lecture4
lecture4
Introduction to ROS
Course 4
Exercise 1 Exercise 5
Exercise 2 Exercise 3 Exercise 4
§ ROS services
§ ROS actions (actionlib)
§ ROS time
§ ROS bags
nav_msgs/GetPlan.srv
std_srvs/Trigger.srv
geometry_msgs/PoseStamped start
--- Request geometry_msgs/PoseStamped goal
bool success float32 tolerance
string message Response ---
nav_msgs/Path plan
In console nr. 1:
Start a roscore with
> roscore
In console nr. 2:
Run a service demo node with
> rosrun roscpp_tutorials add_two_ints_server
§ Fill in the response to the response int main(int argc, char **argv)
argument {
ros::init(argc, argv, "add_two_ints_server");
§ Return to function with true to indicate that it ros::NodeHandle nh;
ros::ServiceServer service =
has been executed properly nh.advertiseService("add_two_ints", add);
ros::spin();
More info return 0;
http://wiki.ros.org/roscpp/Overview/Services }
Action
§ Similar to service calls, but provide possibility to Goal
§ Cancel the task (preempt) Cancel
§ Receive feedback on the progress Node 1 Status Node 2
Action Client Result Action Server
§ Best way to implement interfaces to time-
Feedback
extended, goal-oriented behaviors
§ Similar in structure to services, action are
*.action Action definition
defined in *.action files
Goal
§ Internally, actions are implemented with a set of ---
Result
topics ---
Feedback
More info
http://wiki.ros.org/actionlib
http://wiki.ros.org/actionlib/DetailedDescription
Averaging.action
int32 samples FollowPath.action
--- Goal navigation_msgs/Path path
float32 mean
---
float32 std_dev Result bool success
---
int32 sample Feedback ---
float32 data float32 remaining_distance
float32 mean float32 initial_distance
float32 std_dev
Description Global constant Local, changeable Continuous data Blocking call for Non-blocking,
parameters parameters streams processing a request preemptable goal
oriented tasks
Application Constant settings Tuning parameters One-way continuous Short triggers or Task executions and
data flow calculations robot actions
Examples Topic names, camera Controller parameters Sensor data, robot Trigger change, Navigation, grasping,
settings, calibration state request state, motion execution
data, robot setup compute quantity
§ Normally, ROS uses the PC’s system clock § To take advantage of the simulated time, you
as time source (wall time) should always use the ROS Time APIs:
§ For simulations or playback of logged data, it § ros::Time
is convenient to work with a simulated time ros::Time begin = ros::Time::now();
(pause, slow-down etc.) double secs = begin.toSec();
§ A bag is a format for storing message data Show information about a bag
§ Binary format with file extension *.bag > rosbag info bag_name.bag
§ Suited for logging and recording datasets for Read a bag and publish its contents
later visualization and analysis > rosbag play bag_name.bag
Record all topics in a bag
Playback options can be defined e.g.
> rosbag record --all
> rosbag play --rate=0.5 bag_name.bag
Record given topics
--rate=factor Publish rate factor
> rosbag record topic_1 topic_2 topic_3 --clock Publish the clock time (set
param use_sim_time to true)
Stop recording with Ctrl + C --loop Loop playback
Bags are saved with start date and time as file etc.
name in the current folder (e.g. 2017-02-07- More info
01-27-13.bag) http://wiki.ros.org/rosbag/Commandline