This shows you the differences between two versions of the page.
tutorials:advanced:ros_tutorial [2016/07/09 05:01] Guvalif |
tutorials:advanced:ros_tutorial [2021/04/01 13:52] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ROS Tutorial | ||
- | =============================================================================== | ||
- | ## Build Environment | ||
- | - Ubuntu | ||
- | - ROS indigo | ||
- | - python 2.7 | ||
- | |||
- | |||
- | ## Install ROS | ||
- | Please check [this page](http:// | ||
- | |||
- | ### Create a Workspace | ||
- | Please create a working directory to develop with ROS. | ||
- | After that, initialize the working directory environment as follows: | ||
- | |||
- | ```bash | ||
- | $ mkdir -p ~/ | ||
- | $ cd ~/ | ||
- | $ catkin_init_workspace | ||
- | $ cd ~/catkin_ws | ||
- | $ catkin_make | ||
- | ``` | ||
- | |||
- | There is a setup script to initialize the environment. | ||
- | Please enter command below. | ||
- | |||
- | ```bash | ||
- | $ source ~/ | ||
- | ``` | ||
- | |||
- | This process needs at first time whenever use ROS. Thus, I recommend to add script to **.bashrc** file. | ||
- | |||
- | ```bash | ||
- | #source / | ||
- | source ~/ | ||
- | ``` | ||
- | |||
- | ### Create a Package | ||
- | Please change directory and create a package. | ||
- | |||
- | ```bash | ||
- | $ cd ~/ | ||
- | ``` | ||
- | |||
- | ```bash | ||
- | $ catkin_create_pkg < | ||
- | ``` | ||
- | |||
- | And then, run `catkin_make` again. | ||
- | |||
- | ```bash | ||
- | $ cd ~/catkin_ws | ||
- | $ catkin_make | ||
- | $ source ~/ | ||
- | ``` | ||
- | |||
- | Now, your package can be available. | ||
- | Please check it with following command: | ||
- | |||
- | ```bash | ||
- | catkin_ws$ roscd < | ||
- | catkin_ws/ | ||
- | ``` | ||
- | |||
- | If you can do it, creating a package is succeeded. | ||
- | |||
- | |||
- | ## Connect to PLEN2 | ||
- | Since time of the shipment, PLEN2 has been access point mode (You could connect PLEN2 as WiFi). | ||
- | Also PLEN2 has been set different SSID and common password. | ||
- | |||
- | ``` | ||
- | SSID: PLEN2dev< | ||
- | Password: plenproject | ||
- | ``` | ||
- | |||
- | |||
- | ## Setting Up ROS Environment | ||
- | After connect your PC to PLEN2, please check IP address of your PC with `ifconfig` command. | ||
- | Then, change ROS environment parameters as follows: | ||
- | |||
- | ```bash | ||
- | export ROS_IP=< | ||
- | export ROS_HOSTNAME=< | ||
- | export ROS_MASTER_URI=192.168.42.1: | ||
- | ``` | ||
- | |||
- | Now, your PC can communicate other ROS setuped devices. | ||
- | |||
- | |||
- | ## Blink LED of PLEN2' | ||
- | Let you blink LED of PLEN2' | ||
- | Please create following sample program. | ||
- | |||
- | ```python | ||
- | # | ||
- | # -*- coding: utf-8 -*- | ||
- | |||
- | import rospy | ||
- | from std_msgs.msg import String | ||
- | |||
- | |||
- | def talker(): | ||
- | rospy.init_node(' | ||
- | |||
- | p = rospy.Publisher(' | ||
- | r = rospy.Rate(1) | ||
- | |||
- | led_command = String() | ||
- | led_command.data = ' | ||
- | |||
- | while ( not rospy.is_shutdown() ): | ||
- | if ( ' | ||
- | led_command.data = ' | ||
- | |||
- | elif ( ' | ||
- | led_command.data = ' | ||
- | |||
- | rospy.loginfo(' | ||
- | |||
- | p.publish(led_command) | ||
- | r.sleep() | ||
- | |||
- | |||
- | if __name__ == ' | ||
- | try: | ||
- | talker() | ||
- | |||
- | except rospy.ROSInterruptException: | ||
- | pass | ||
- | ``` | ||
- | |||
- | This script blink PLEN2' | ||
- | PLEN2 subscribe topic which name is **PcToControl**. | ||
- | |||
- | You need to run following command to be availabel the python script: | ||
- | |||
- | ```bash | ||
- | $ chmod 755 < | ||
- | $ python < | ||
- | ``` | ||
- | |||
- | In addition, You could control PLEN2 with command below. [See also...](http:// | ||
- | |||
- | ``` | ||
- | serial, | ||
- | ``` | ||
- | |||
- | For example, if you would like to play the motion that is placed slot 4, send command below: | ||
- | |||
- | ``` | ||
- | serial, | ||
- | ``` |