CLICK ME TO GO TO PREVIOUS PAGE
- starts with "/" are global
- starts with "~"
- define in
ros::NodeHandle nh1("~")orros::NodeHandle nh2("~my_private_ns")- Namespace of nh1: /[node_name] or nh2: /[node_name]/[my_private_ns]
rostopic pub [topic]rostopic echo [topic]rostopic info [topic]
- Structure
catkin_ws/src/[package directory]/msg/[file].msg file
- [field_type] [field_name]
- 4 Field types
- Built-in type
- http://wiki.ros.org/msg#Fields (check out 2.1.1)
- Names of self-defined Message descriptions (Q: message of message?) ?
- Arrays (E.g.: float32[] ranges)
- Header type, which maps to std_msgs/Header
- Built-in type
- Under [msg_package_name] directory
- Under package.xml
- change the depend
<!-- use at build time --> <build_depend>message_generation</build_depend> <!-- use at runtime --> <exec_depend>message_runtime</exec_depend>
- change the depend
- Under CMakeLists.txt
- Under find_package(catkin REQUIRED COMPONENTS
- Add package component:
message_generationfind_package(catkin REQUIRED COMPONENTS roscpp std_msgs message_generation # add this )
- Add package component:
- Under add_message_files(
- Include the .msg file name
add_message_files( FILES Num.msg # add this )
- Include the .msg file name
- Under generate_messages(
- Include the dependencies required by the added messages (and services) above
generate_messages( DEPENDENCIES std_msgs )
- Include the dependencies required by the added messages (and services) above
- Under find_package(catkin REQUIRED COMPONENTS
- Under package.xml
- Under [directory] where the user-defined msg is used
- Under CMakeLists.txt
- Under find_package(catkin REQUIRED COMPONENTS
- Add package component:
[msg_package_name]find_package(catkin REQUIRED COMPONENTS roscpp std_msgs lab_msg // add this ) - Add dependency for the node which uses the message
add_dependencies(talker [msg_package_name]_generate_messages_cpp)
- Add package component:
- Under find_package(catkin REQUIRED COMPONENTS
- Under CMakeLists.txt
- Under the [node_src_file]
#include "[msg_package_name]/[msg_filename].h"- msg header file will be generated under devel/include/[package name], include the header file when we use those messages.
- Declare a msg object and assign values
# Num.msg file int32 val// node file lab_msg::Num num; num.val = 0;
rostopic type [topic]- Will output the message type of that topic
rosmsg show [message_type]- Look up the fields of the msg_type
- Structure
catkin_ws/src/[package directory]/srv/[service_type].srv file
- Fields
- request field (update by client)
- response field (update by server)
- separated by "------"
- The corresponding modifications are very similar to those for
messages.- But in CMakeLists.txt, instead of changing "add_message_files(", modify the "add_service_files(" block.
- rossrv show [service_type]
- E.g.: rossrv show AddTwoInts
- Display the details of the .srv file
- rosservice list
- Display all the currently active services that where launched after you started the ROS master
- Shall be instantiated at the Client (Q: any situation to instantiate at the Server) ?
- 2 members
requestandresponse
- 2 class definitions
RequestandResponse
- Information about request and reponse are logged
- Instances involved as function parameter
- [package_name]::[service_type]::Request &req
- [package_name]::[service_type]::Response &res
- Instances involved as function parameter
ros::ServiceServer service = n.advertiseService("add_two_ints", add)advertiseService()create a service and advertise over ROS- First parameter: service name (E.g.: add_two_ints)
- Second parameter: service function (E.g.: add)
- Return value: ros::ServiceServer object (E.g.: service)
ros::ServiceClient client = n.serviceClient<lab_msg::AddTwoInts>("add_two_ints")serviceClient<>()creates a ros::ServiceClient object- The object will be used to call the service
- Will "subscribe" to the [service_name]: add_two_ints
- Return value: ros::ServiceClient object (E.g.: client)
lab_msg::AddTwoInts srv- Instantiate a autogenerated service class ?
srv.request.a = atoll(argv[1]);- Assign value into the class's request member
if (client.call(srv))calls the serviceclient.call()- Q: Can I change how frequent service is tried to be called? ?
- Node enables us to: publish/subscribe topic, and advertise/subscribe service
- Node: info exchange, Service: under node, acts just like a function
| NodeHandle class (n) | Topic / Service | corr. return type |
|---|---|---|
| Publish | n.advertise<std_msgs::String>("[topic_name]", [msg_queue_size]); | ros::Publisher |
| n.advertiseService("[service_name]", add) | ros::ServiceServer | |
| Subscribe | n.subscribe("[topic_name]", [msg_queue_size], CallbackFunction); | ros::Subscriber |
| n.serviceClient<lab_msg::AddTwoInts>("[service_name]") | ros::ServiceClient |
- Structure
catkin_ws/src/[package directory]/launch/[file].launch xml file
- Tags
- - `pkg=" "` - `type=" "` - Node type, name that matches the executable - `name=" "` - Node name, defined at ros::init() - `ns="my_private_ns"(optional)` - Node name in "my_private_ns" namespace - `output="screen"` to show ROSINFO output
-
<rosparam file="$(find [package_name])/param/[file].yaml" /><remap from="chatter" to="/talker_node/chatter"/>
- Under [bringup_package_name]/CMakeLists.txt
- Modify "find_package(catkin REQUIRED COMPONENTS" according to package needs
roslaunch [package_name] [file].launch- Initializes the robot
- http://wiki.ros.org/roslaunch
- Structure
catkin_ws/src/[package directory]/param/[file].yaml file
- Commands
rosparam list- List all parameter names
rosparam get /- Display contents of the entire Parameter Server
rosparam set my_param "hello world"rosparam load lab/param/val.yaml- Q: how to control which node the parameter loads to? ?
rosparam delete my_param
std::string s;n.getParam("my_param", s);- n: instance of NodeHandle
- Return value: boolean
n.setParam("my_param", "hello world");n.hasParam("my_param")- Return value: boolean
- Check for parameter existence
- Q: Apart from using terminal commands and in .launch file, anyways to load the parameter inside a node? ?
- topic name
- node name