Robotic Perception and Action

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Robot Operating System Tutorial ROS Basic
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Multi-Robot Systems with ROS Lesson 1
What is ROS? Robot Operating System
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
CSC172 Intro Pepper. Goals Reminder of what a class is How to create and use classes How to design classes How to think in terms of objects How to comment.
Teaching Assistant: Roi Yehoshua
ACM/JETT Workshop - August 4-5, Guidelines For Using BlueJ.
Teaching Assistant: Roi Yehoshua
CS 590 Programming Environments with UNIX. Computer Lab Account Course Homepage
CD2012 Principles of Interactive Graphics Lecture 01 Introduction Abir Hussain (Rome: 6.33,Tel , Web:
Teaching Assistant: Roi Yehoshua
An Introduction to Front-end Web Development Tom Perkins.
Teaching Assistant: Roi Yehoshua
Python module distribution. Modules in Python Modules are everywhere.
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
Teaching Assistant: Roi Yehoshua
Lecturer: Roi Yehoshua
Lecturer: Roi Yehoshua
CST 1101 Problem Solving Using Computers
Lecturer: Roi Yehoshua
Lecturer: Roi Yehoshua
Lecturer: Roi Yehoshua
Navigating the Filing System
5.13 Recursion Recursive functions Functions that call themselves
Lecturer: Roi Yehoshua
ROSLab: a High Level Programming Language for Robotic Applications
What is ROS? ROS is an open-source robot operating system
Multi-Robot Systems with ROS Lesson 10
Multi-Robot Systems with ROS Lesson 2
Processes in Unix, Linux, and Windows
Microsoft Windows 2000 Professional
Some Tips for Using Eclipse
- The Robot Operating System
Processes in Unix, Linux, and Windows
Robotic Perception and Action
Robotics and Perception
Programming Assignment # 2 – Supplementary Discussion
Quick Introduction to ROS
Robotics and Perception
Robotic Perception and Action
Processes in Unix, Linux, and Windows
Scripts In Matlab.
Robotic Perception and Action
Robotic Perception and Action
Working with Libraries
Review Lab assignments Homework #3
Robot Operating System (ROS): An Introduction
Presentation transcript:

Robotic Perception and Action Turtlesim: Publisher/Subscriber Examples

Writing a Publisher node What is Turtlesim? Writing a Publisher node ROS Publisher Program Catkin Executing Publisher Program Publisher Result Writing a Subscriber node ROS Subscriber Program Executing Subscriber Program Subscriber Result References Index

Turtlesim is a tool made for teaching ROS and ROS packages In order to become more familiar with the ROS concepts about Publisher/Subscriber nodes, we use the simple simulator Turtlesim Turtlesim is a tool made for teaching ROS and ROS packages To open the turtlesim: Open a 1st terminal and activate ROS by digiting: > roscore Open a 2° terminal and run the command: > rosrun turtlesim turtlesim_node The simulator window is opened with the turtle simulated in the center position. What is Turtlesim?

The turtlesim package has a single node called turtlesim_node that presents the following topics: Published Topics turtleX/cmd_vel (geometry_msgs/Twist) It is the linear and angular command velocity for turtleX. The turtle will execute a velocity command for 1 second then time out. Subscribed Topics turtleX/pose (turtlesim/Pose) The x, y, theta, linear velocity, and angular velocity of turtleX. In red there are the topic names and in blue the topic data types What is Turtlesim?

Let’s investigate the data types by finding them on Google or directly on the http://docs.ros.org/api/ website geometry_msgs/Twist What is Turtlesim?

What is Turtlesim? turtlesim/Pose Remark Pose = Position + Orientation In this case we have a 2D pose: Position: x, y directions Orientation: theta angle What is Turtlesim?

Move the turtle: send command velocity -> Publisher Ok. Now we know how it is composed the turtlesim package, node and related topics. It’s time to create program files in order to use these information to: Move the turtle: send command velocity -> Publisher Acquire pose data (odometry) from turtle -> Subscriber So, open a terminal and go to the workspace directory and let’s create a new package called turtle_pkg in where we will create the publisher/subscriber nodes by following the commands: > cd ~/catkin_ws > source /opt/ros/indigo/setup.bash > source devel/setup.bash > cd ~/catkin_ws/src > catkin_create_pkg --rosdistro indigo turtle_pkg roscpp ROS Publisher/Subscriber

Now it’s time to understand the concepts about Publisher program code: Move the turtle: send command velocity -> Publisher Once the package is created with success, go inside the turtle_pkg directory and in the directory src open with gedit a file called pubvel.cpp. > cd ~/catkin_ws/src/turtle_pkg/src > gedit pubvel.cpp In it copy the following code: ROS Publisher Program

// This program publishes randomly − generated velocity messages for turtlesim. #include <ros/ros.h> #include <geometry_msgs/Twist.h> // For geometry_msgs ::Twist #include <stdlib.h> // For rand () and RAND_MAX int main (int argc, char **argv) { // Initialize the ROS system and become a node. ros::init(argc, argv, "publish_velocity") ; ros::NodeHandle nh; // Create a publisher object. ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("turtle1/cmd_vel", 1000); // Seed the random number generator. srand(time(0)); ROS Publisher Program

ROS Publisher Program // Loop at 2Hz until the node is shut down. ros::Rate rate(2); while (ros::ok()){ // Create and fill in the message. The other four // fields, which are ignored by turtlesim , default to 0. geometry_msgs:: Twist msg; msg.linear.x = double(rand())/double(RAND_MAX); msg.angular.z = 2*double(rand())/double(RAND_MAX)-1; // Publish the message. pub.publish(msg); // Send a message to rosout with the details. ROS_INFO_STREAM("Sending random velocity command: " <<"linear="<<msg.linear.x <<"angular="<<msg.angular.z); // Wait until it's time for another iteration. rate.sleep(); } ROS Publisher Program

After that, open with gedit the CMakeLists After that, open with gedit the CMakeLists.txt file in the previous folder and copy before the end of file: In this way we have created the Node file pubvel related to the .cpp file pubvel.cpp. add_executable(pubvel src/pubvel.cpp) target_link_libraries(pubvel ${catkin_LIBRARIES}) ROS Publisher Program

To build your package we have to return to the root directory of our workspace: > cd /home/student/catkin_ws or > cd ~/catkin_ws Build and create executable for all packages: > catkin_make If all is ok, it will create other 2 directories called build and devel: Now you update your environment: > source devel/setup.bash NB: catkin is the ROS build system to generate exec, libraries, and interfaces. Catkin

Executing Publisher Program When all of those build steps are complete, your new ROS program is ready to execute using rosrun just like any other ROS program. Open a terminal and launch the roscore command > roscore Open a second terminal and launch the turtlesim simulator > rosrun turtlesim turtlesim_node Open a third terminal and launch our example, the command is: > rosrun turtle_pkg pubvel NB: If the package is not visible, try to restart the shell or run the command: > rospack find turtle_pkg or rospack profile find turtle_pkg If all is ok, it will produce as result: Executing Publisher Program

Publisher Result

ROS Subscriber Program Now it’s time to understand the concepts about Subscriber program code: Acquire pose data (odometry) from turtle -> Subscriber As the publisher, go inside the turtle_pkg directory and in the directory src open with gedit a file called subpose.cpp. > cd ~/catkin_ws/src/turtle_pkg/src > gedit subpose.cpp In it copy the following code: ROS Subscriber Program

ROS Subscriber Program // This program subscribes to turtle1/pose and shows its messages on the screen. #include <ros/ros.h> #include <turtlesim/Pose.h> #include <iomanip> // for std::setprecision and std::fixed /* A callback function. Executed each time a new pose message arrives. void function_name(const package_name::type_name &msg) { ... } The package_name and type_name are the same as for publishing: They refer to the message class for the topic to which we plan to subscribe. */ void poseMessageReceived(const turtlesim::Pose& msg){ // POSE = POSITION + ANGULAR DIRECTION ROS_INFO_STREAM(std::setprecision(2)<<std::fixed <<"position =("<<msg.x<<", "<<msg.y<<")" // position <<"direction="<<msg.theta); // direction ROS Subscriber Program

ROS Subscriber Program int main (int argc, char **argv){ // Initialize the ROS system and become a node . ros::init(argc, argv, "subscribe_to_pose"); ros::NodeHandle nh; // Create a subscriber object.1000 is the queue size ros::Subscriber sub = nh.subscribe("turtle1/pose", 1000, &poseMessageReceived); // Let ROS take over. ros::spin(); } ROS Subscriber Program

After that, open with gedit the CMakeLists After that, open with gedit the CMakeLists.txt file in the previous folder and copy before the end of file: In this way we have created the Node file subpose related to the .cpp file subpose.cpp. add_executable(subpose src/subpose.cpp) target_link_libraries(subpose ${catkin_LIBRARIES}) ROS Subscriber Program

To build your package we have to return to the root directory of our workspace: > cd /home/student/catkin_ws or > cd ~/catkin_ws Build and create executable for all packages: > catkin_make If all is ok, it will create other 2 directories called build and devel: Now you update your environment: > source devel/setup.bash NB: catkin is the ROS build system to generate exec, libraries, and interfaces. Catkin

Executing Subpose Program When all of those build steps are complete, your new ROS program is ready to execute using rosrun just like any other ROS program. Open a terminal and launch the roscore command > roscore Open a second terminal and launch the turtlesim simulator > rosrun turtlesim turtlesim_node Open a third terminal and launch our example, the command is: > rosrun turtle_pkg subpose Open a fourth terminal and launch the turtle_teleop in order to move with the keyboard our turtle. The command is: > rosrun turtlesim turtle_teleop_key NB: If the package is not visible, try to restart the shell or run the command: > rospack find turtle_pkg or rospack profile find turtle_pkg If all is ok, it will produce as result: Executing Subpose Program

Subscriber Result

turtle_pkg tree

A Gentle Introduction to ROS (Jason M. O’Kane) Wiki ROS Tutorials Turtlesim Tutorial http://wiki.ros.org/turtlesim A Gentle Introduction to ROS (Jason M. O’Kane) https://www.cse.sc.edu/~jokane/agitr/ Wiki ROS Tutorials  http://wiki.ros.org/ROS/Tutorials Slides course (Roi Yehoshua) https://u.cs.biu.ac.il/~yehoshr1/89-685/ References