ROS Tutorial =============================================================================== ## Build Environment - Ubuntu - ROS indigo - python 2.7 ## Install ROS Please check [this page](http://wiki.ros.org/Documentation) and install ROS to your PC that is installed ubuntu. ### Create a Workspace Please create a working directory to develop with ROS. After that, initialize the working directory environment as follows: ```bash $ mkdir -p ~/catkin_ws/src $ cd ~/catkin_ws/src $ catkin_init_workspace $ cd ~/catkin_ws $ catkin_make ``` There is a setup script to initialize the environment. Please enter command below. ```bash $ source ~/catkin_ws/devel/setup.bash ``` This process needs at first time whenever use ROS. Thus, I recommend to add script to **.bashrc** file. ```bash #source /opt/ros/indigo/setup.bash source ~/catkin_ws/devel/setup.bash ``` ### Create a Package Please change directory and create a package. ```bash $ cd ~/catkin_ws/src ``` ```bash $ catkin_create_pkg rospy roscpp std_msgs ``` And then, run `catkin_make` again. ```bash $ cd ~/catkin_ws $ catkin_make $ source ~/catkin_ws/devel/setup.bash ``` Now, your package can be available. Please check it with following command: ```bash catkin_ws$ roscd catkin_ws/src/$ ``` 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=http://192.168.42.1:11311 ``` Now, your PC can communicate other ROS setuped devices. ## Blink LED of PLEN2's Eyes Let you blink LED of PLEN2's eyes. Please create following sample program. ```python #!/usr/bin/env python # -*- coding: utf-8 -*- import rospy from std_msgs.msg import String def talker(): rospy.init_node('PCNode', anonymous=True) p = rospy.Publisher('PcToControl', String, queue_size=10) r = rospy.Rate(1) led_command = String() led_command.data = 'gpio,w,off' while ( not rospy.is_shutdown() ): if ( 'on' in led_command.data ): led_command.data = 'gpio,w,off' elif ( 'off' in led_command.data ): led_command.data = 'gpio,w,on' rospy.loginfo('%s', led_command.data) p.publish(led_command) r.sleep() if __name__ == '__main__': try: talker() except rospy.ROSInterruptException: pass ``` This script blink PLEN2's eye at every seconds. 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://plen.jp/playground/wiki/specifications/protocol) ``` serial,w, ``` For example, if you would like to play the motion that is placed slot 4, send command below: ``` serial,w,$pm04 ```