Teaching Assistant: Roi Yehoshua

Slides:



Advertisements
Similar presentations
CPSC 441 TUTORIAL – JANUARY 16, 2012 TA: MARYAM ELAHI INTRODUCTION TO C.
Advertisements

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
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Lab2 TA Notes. Set up for Visual C++ New Workspace Win32 Console Application – This runs from a command line Chose Blank Project Add your.C file Build.
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
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
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
1 INF160 IS Development Environments AUBG, COS dept Lecture 06 Title: Dev Env: Code::Blocks (Extract from Syllabus) Reference:
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Introduction to Webots Outlines Introduction Introduction World Description World Description Controller Programming Controller Programming.
Teaching Assistant: Roi Yehoshua
Ling Chen ( From Shanghai University 1.
Teaching Assistant: Roi Yehoshua
An Introduction to Front-end Web Development Tom Perkins.
Implementation of the Hangman Game in C++
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Teaching Assistant: Roi Yehoshua
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
Teaching Assistant: Roi Yehoshua
Exceptions in C++. Exceptions  Exceptions provide a way to handle the errors generated by our programs by transferring control to functions called handlers.
Teaching Assistant: Roi Yehoshua
Teaching Assistant: Roi Yehoshua
Lecturer: Roi Yehoshua
Lecturer: Roi Yehoshua
Lecturer: Roi Yehoshua
Jacob White and Andrew Keller
Lecturer: Roi Yehoshua
Lecturer: Roi Yehoshua
Lecturer: Roi Yehoshua
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
The Finch Robot and the While Loop
Multi-Robot Systems with ROS Lesson 2
C Stuff CS 2308.
- The Robot Operating System
Lab 1 Introduction to C++.
Quick Introduction to ROS
Robotic Perception and Action
Robotic Perception and Action
Robotic Perception and Action
Robotic Perception and Action
Robot Operating System (ROS): An Introduction
SPL – PS1 Introduction to C++.
Presentation transcript:

Teaching Assistant: Roi Yehoshua

Gazebo 3D Simulator Spanning multiple robots in Gazebo Controlling multiple robots in Gazebo (C)2014 Roi Yehoshua

Gazebo is a 3D multi-robot simulator Gazebo ROS Hydro comes with Gazebo V1.9.1 Composed of two processes: – Server: Runs the physics loop and generates sensor data – Client: Provides user interaction and visualization of a simulation (C)2014 Roi Yehoshua

To launch gazebo (both client and server components) run: (C)2013 Roi Yehoshua $ gazebo

You can use roslaunch to load world models For example, to open willowgarage_world type: There are other 5 world files examples in the /launch subdirectory of gazebo_ros package (C)2014 Roi Yehoshua $ roslaunch gazebo_ros willowgarage_world.launch

To add a model to the world: – Move to the Insert tab – left-click on the desired model in the Insert Tab – move the cursor to the desired location in World View – left-click again to release – Use the Translate and Rotate modes to orient the model more precisely (C)2013 Roi Yehoshua

For example, we will add two Pioneer robots to our world (C)2013 Roi Yehoshua

Typically, each robot comes with a robot description package that contains its URDF and mesh files for simulation and visualization We will use r2d2_description package that we have built in the Introduction course This package contains r2d2 URDF file and the mesh file for the Hokuyo laser You can download this package from the link: – 685/demos/lesson11/r2d2_packages.zip 685/demos/lesson11/r2d2_packages.zip (C)2014 Roi Yehoshua

Make sure that the laser topic used in the URDF file does is without the /, otherwise it will be shared base_scan hokuyo_link base_scan hokuyo_link

Let’s create a new package called gazebo_multi Create a launch subdirectory within the package and add the following launch file called one_robot.launch (C)2014 Roi Yehoshua $ cd ~/catkin_ws/src $ catkin_create_pkg gazebo_multi std_msgs rospy roscpp $ cd ~/catkin_ws/src $ catkin_create_pkg gazebo_multi std_msgs rospy roscpp

To work with the robot model in ROS, we need to publish its joint states and TF tree For that purpose we need to start two nodes: – a joint_state_publisher node that reads the robot’s model from its URDF file and publishes /joint_states messages – a robot_state_publisher node that listens to /joint_states messages and publishes the transforms to /tf (C)2014 Roi Yehoshua

<node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" output="screen"/> <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" output="screen"/> There are two arguments to pass for robot initialization: name and position Notice that -param /robot_description is with the slash i.e. fully-qualified, as it will be shared

(C)2014 Roi Yehoshua <!-- No namespace here as we will share this description. Access with slash at the beginning --> <!-- No namespace here as we will share this description. Access with slash at the beginning -->

gazebo_multi.launch (C)2014 Roi Yehoshua

To launch the simulation run: This will open an empty world with the two r2d2 robots (C)2014 Roi Yehoshua $ roslaunch gazebo_multi gazebo_multi.launch

(C)2014 Roi Yehoshua

You can see that both robots publish the base_scan and cmd_vel topics in the correct namespace (C)2014 Roi Yehoshua

Now we are going to move one of the robots using the teleop_twist_keyboard node Run the following command: You should see console output that gives you the key-to-control mapping (C)2014 Roi Yehoshua $ rosrun teleop_twist_keyboard teleop_twist_keyboard.py cmd_vel:=/robot2/cmd_vel

(C)2014 Roi Yehoshua

We will now add a node that will make one of the robots start random walking in the environment The code of the node is the same as the one we used to control the robot in Stage simulator – Since the robots are using the same topics Add random_walk.cpp to your package

(C)2014 Roi Yehoshua #include using namespace std; #define MIN_SCAN_ANGLE_RAD -45.0/180*M_PI #define MAX_SCAN_ANGLE_RAD +45.0/180*M_PI bool obstacleFound = false; void readSensorCallback(const sensor_msgs::LaserScan::ConstPtr &sensor_msg); #include using namespace std; #define MIN_SCAN_ANGLE_RAD -45.0/180*M_PI #define MAX_SCAN_ANGLE_RAD +45.0/180*M_PI bool obstacleFound = false; void readSensorCallback(const sensor_msgs::LaserScan::ConstPtr &sensor_msg);

(C)2014 Roi Yehoshua int main(int argc, char **argv) { if (argc < 2) { ROS_ERROR("You must specify robot id."); return -1; } char *robot_name = argv[1]; ROS_INFO("Moving robot %s", robot_name); ros::init(argc, argv, "random_walk"); ros::NodeHandle nh; string cmd_vel_topic_name = robot_name; cmd_vel_topic_name += "/cmd_vel"; ros::Publisher cmd_vel_pub = nh.advertise (cmd_vel_topic_name, 10); string laser_topic_name = robot_name; laser_topic_name += "/base_scan"; ros::Subscriber base_scan_sub = nh.subscribe (laser_topic_name, 1, &readSensorCallback); int main(int argc, char **argv) { if (argc < 2) { ROS_ERROR("You must specify robot id."); return -1; } char *robot_name = argv[1]; ROS_INFO("Moving robot %s", robot_name); ros::init(argc, argv, "random_walk"); ros::NodeHandle nh; string cmd_vel_topic_name = robot_name; cmd_vel_topic_name += "/cmd_vel"; ros::Publisher cmd_vel_pub = nh.advertise (cmd_vel_topic_name, 10); string laser_topic_name = robot_name; laser_topic_name += "/base_scan"; ros::Subscriber base_scan_sub = nh.subscribe (laser_topic_name, 1, &readSensorCallback);

(C)2014 Roi Yehoshua geometry_msgs::Twist moveForwardCommand; moveForwardCommand.linear.x = 1.0; geometry_msgs::Twist turnCommand; turnCommand.angular.z = 1.0; ros::Rate loop_rate(10); while (ros::ok()) { if (obstacleFound) { ROS_INFO("Turning around"); cmd_vel_pub.publish(turnCommand); } else { ROS_INFO("Moving forward"); cmd_vel_pub.publish(moveForwardCommand); } ros::spinOnce(); // let ROS process incoming messages loop_rate.sleep(); } return 0; } geometry_msgs::Twist moveForwardCommand; moveForwardCommand.linear.x = 1.0; geometry_msgs::Twist turnCommand; turnCommand.angular.z = 1.0; ros::Rate loop_rate(10); while (ros::ok()) { if (obstacleFound) { ROS_INFO("Turning around"); cmd_vel_pub.publish(turnCommand); } else { ROS_INFO("Moving forward"); cmd_vel_pub.publish(moveForwardCommand); } ros::spinOnce(); // let ROS process incoming messages loop_rate.sleep(); } return 0; }

(C)2014 Roi Yehoshua void readSensorCallback(const sensor_msgs::LaserScan::ConstPtr &scan) { bool isObstacle = false; int minIndex = ceil((MIN_SCAN_ANGLE_RAD - scan->angle_min) / scan- >angle_increment); int maxIndex = floor((MAX_SCAN_ANGLE_RAD - scan->angle_min) / scan- >angle_increment); for (int i = minIndex; i <= maxIndex; i++) { if (scan->ranges[i] < 0.5) { isObstacle = true; } if (isObstacle) { ROS_INFO("Obstacle in front of you!"); obstacleFound = true; } else { obstacleFound = false; } void readSensorCallback(const sensor_msgs::LaserScan::ConstPtr &scan) { bool isObstacle = false; int minIndex = ceil((MIN_SCAN_ANGLE_RAD - scan->angle_min) / scan- >angle_increment); int maxIndex = floor((MAX_SCAN_ANGLE_RAD - scan->angle_min) / scan- >angle_increment); for (int i = minIndex; i <= maxIndex; i++) { if (scan->ranges[i] < 0.5) { isObstacle = true; } if (isObstacle) { ROS_INFO("Obstacle in front of you!"); obstacleFound = true; } else { obstacleFound = false; }

(C)2014 Roi Yehoshua To launch the random walk node type: $ rosrun gazebo_multi random_walk [robot name]

(C)2014 Roi Yehoshua To make all robots random walk, you can add the random_walk node to one_robot.launch file <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" output="screen"/> <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" output="screen"/>

Pioneer 3-AT (P3AT) is one of the world's most popular robot for research and teaching university robotics Download Pioneer’s URDF file from herehere Spawn 3 Pioneer robots in Gazebo and move them around with the keyboard (C)2014 Roi Yehoshua