From 7a38990f9edfccdc4448dc89fc378a0028fbc8a7 Mon Sep 17 00:00:00 2001 From: Mugen Date: Sun, 21 Jun 2015 18:26:44 +0900 Subject: [PATCH] add my awesome work --- 20150422/launch/mydetectnode.launch | 16 ++++ 20150422/read.md | 142 ++++++++++++++++++++++++++++ 20150422/scripts/mynode.py | 41 ++++++++ 3 files changed, 199 insertions(+) create mode 100644 20150422/launch/mydetectnode.launch create mode 100644 20150422/read.md create mode 100644 20150422/scripts/mynode.py diff --git a/20150422/launch/mydetectnode.launch b/20150422/launch/mydetectnode.launch new file mode 100644 index 0000000..7688fce --- /dev/null +++ b/20150422/launch/mydetectnode.launch @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + diff --git a/20150422/read.md b/20150422/read.md new file mode 100644 index 0000000..dfa6be0 --- /dev/null +++ b/20150422/read.md @@ -0,0 +1,142 @@ +# homework20150422 + +1. execute `talker/listener` sample + + **Goal:** Comprehend node, topic, publish/subscriber and command line tools for ROS + + - Open new terminal and execute command below: + ```bash +# Terminal 1 +roscore +``` + - Open new terminal and execute command below + ```bash + # Terminal 2 +rosrun homework20150422 talker.l +``` + - Open new terminal and execute command below: + ```bash + # Terminal 3 +rosrun homework20150422 listener.l +``` + + - Open new terminal and execute commands below: + ```bash + # Terminal 4 +rostopic list # you can find all topics advertised +rostopic info /chatter # you can see detail information of /chatter topic +rostopic echo /chatter # you can also see the message published as /chatter topic +``` + +2. execute `turtlesim` sample + + **Goal:** Comprehend ros distributed system with multiple launguages, and its launching system called `roslaunch` + + - Open new terminal and execute commands below: + ```bash + # Terminal 1 +roslaunch homework20150422 turtlesim.launch +``` + + - Focus the terminal and push `up` `down` `right` `left` keys. + + - See what nodes are launching by `rosnode list`: + ```bash + # Terminal 2 +rosnode list # you can see what nodes are on ROS +``` + + - Now let's take a look at `turtlesim.launch` + ```xml + + + + + + +``` + + - You can see 2 `` tags in launch file. This means these 2 nodes are launched.: + ```xml + +``` + - `name` attribute: name of the node + + **NOTE** (each node name is already named in each nodes, but once you set name different from that written at original node, it will be overwriten (we call it `remapped`)) + - `pkg` attribute: package of the node + - `type` attribute: program name of the node (we can use each independent node by `rosrun `) + + - Now let's look at next node example: + ```xml + + + +``` + - `args` attribute (optional): arguments passed when launching node + - `output` attribute (optional): when this has value `screen`, we can see output log of this node. (This is important when launching nodes on another machine, and need to transmit log output to your terminal) + - ``: remapping topic name + Detail: `turtlesim-teleop.l` has publisher of `cmd_vel`, so if you launch this node with `rosrun`, this node publishes `/cmd_vel` topic. But, if remapped `cmd_vel` to `/turtle1/cmd_vel` as described above, this node changes the topic name from `/cmd_vel` to `/turtle1/cmd_vel`. + You can change subscribe/publish topic of the node without changing any code. + + +3. execute `face_detector` sample: + + **GOAL** Comprehend nested `launch`, topic remapping + + - Open new terminal and execute command below: + ```bash +roslaunch homework20150422 camera.launch +``` + + - You can see the image captured from the camera of your PC + + - Press `Ctrl-C` to stop this launch + + - Open new terminal and execute command below: + ```bash +roslaunch homework20150422 face_detect.launch +``` + + - You can see 2 image_view (one shows raw image view, and another shows the image drawn rectangle over the detected face using OpenCV) + + ```xml + + ... + + ... +``` + + - You can use arguments in launch file + - You can also set arguments when launches launch file + e.g.: `roslaunch homework20150422 face_detect.launch show_debug_image:=false` + + ```xml + +``` + - You can include another `launch` files. + +4. Make your own image processing node + + - previous `face_detector` example has node doing 3 things: + - Subscribe `sensor_msgs/Image` message + - Processs image subscribed (detecting face, and draw rectangle on each image) + - Publish processed image + - Let's make your own node to process image, and visualize processed image + - Please send pull request below: + - your source codes of image processing that: + - Subscribe `sensor_msgs/Image` message + - Processs image subscribed (any processing is ok) + - Publish processed image + - make `launch` file to show following: + - original camera image + - processed image + - add `README` which describes your node + + +--------------------------------------------------- +My homework20150422 diff --git a/20150422/scripts/mynode.py b/20150422/scripts/mynode.py new file mode 100644 index 0000000..c0fb7aa --- /dev/null +++ b/20150422/scripts/mynode.py @@ -0,0 +1,41 @@ + +import rospy + +from sensor_msgs.msg import Image +from geometry_msgs.msg import Twist + +from cv_bridge import CvBridge + +import cv2 + +class mydetect_node(object): + + + def __init__(self): + + try: + self.bridge = CvBridge() + self.cascade = cv2.CascadeClassifier(cascade_path) + except Exception as e: + rospy.logerr("Error: %s" % e) + self.image_subscriber = rospy.Subscriber("image", Image, self.image_callback) + + self.face_pose_publisher = rospy.Publisher("twist", Twist) + self.debug_image_publisher = rospy.Publisher("debug_image", Image) + + def image_callback(self, msg): + img_size = (msg.width, msg.height) + + img_mat = self.bridge.imgmsg_to_cv2(msg) + + img_grey = cv2.cvtColor(img_mat, cv2.cv.CV_BGR2GRAY) + img_edge = cv2.Canny(img_grey,100,100) + + pub_debug_img_msg = self.bridge.cv2_to_imgmsg(img_edge, encoding="bgr8") + self.debug_image_publisher.publish(pub_debug_img_msg) + +if __name__ == '__main__': + rospy.init_node("mydetectnode") + mydetectnode = mydetect_node() + + rospy.spin()