ND - 2. ROS essentials - core

2. ROS essential - core

Fundamental

perception -> decision making -> action

  1. Master = manager; registry of all nodes

  2. Parameter Server = params + configs

  3. Node -> publish -> Topic -> subscribe -> node (named Bus pipeline)

  4. Service = Node1 -> request -> Node2 -> response -> Node1 (1:1)

Q: Is ROS installed & sourced?

A: $ ros with double tab should list lots of commands.

source vs ./

sourceexecute the script in the current session.

./start a new session, with a copy of the current env. When exit the script, all env variables will be lost.

$ source /opt/ros/kinetic/setup.bash

Gazebo = physics simulator,

RViz = can visualize sensor data being published over a ROS topic like camera images, point clouds, Lidar data, etc.

TurtleSim

1. Starting the Master process

  • Naming and registration services to running nodes

  • Facilitating connections between nodes

  • Tracking all publishers and subscriber.

  • Aggregating log messages

$ roscore

2. Node

$ rosrun package_name node_name

$ rosnode list

$ rostopic list
$ rostopic info topic_name
$ rostopic echo topic_name // see realtime msg from a topic

$ rosmsg info class_name/msg_name // rosmsg info geometry_msgs/Twist

$ rosed geometry_msgs Twist.msg

/rosout Launched by roscore, and subscribes to the /rosout topic, all nodes send log messages to it.

Catkin

1. Create workspace

$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace // generate CMakeLists.txt

$ cd ~/catkin_ws
$ catkin_make

2. Add a package

From existing code

$ cd ~/catkin_ws/src
$ git clone https://github.com/udacity/simple_arm_01.git simple_arm

From scratch

$ cd ~/catkin_ws/src/

// catkin_create_pkg <your_package_name> [dependency1 dependency2 …]
$ catkin_create_pkg udacity_bot

$ cd udacity_bot
$ mkdir launch
$ mkdir worlds
...
...

scripts (python executables)

src (C++ source files)

msg (for custom message definitions)

srv (for service message definitions)

include -> headers/libraries that are needed as dependencies

config -> configuration files

launch -> provide a more automated way of starting nodes

Other folders may include

= = =

urdf (Universal Robot Description Files)

meshes (CAD files in .dae (Collada) or .stl (STereoLithography) format)

worlds (XML like files that are used for Gazebo simulation environments)

3. roslaunch

  • Launch ROS Master and multiple nodes with one simple command

  • Set default parameters on the parameter server

$ cd ~/catkin_ws
$ catkin_make

$ source devel/setup.bash

$ roslaunch simple_arm robot_spawn.launch

4. rosdep

$ rosdep check simple_arm
$ rosdep install -i simple_arm

ROS Publishers

Node -> publisher -> topic

  1. allow a node to send messages to a topic

  2. can be either synchronous or asynchronous.

  3. Synchronous publishing - The 2nd publisher is blocked until the 1st publisher has serialized all messages to a buffer and the buffer has written the messages to each of the topic's subscribers.

  4. Asynchronous publishing - store messages in a queue until the messages can be sent. (the oldest messages are dropped when exceeds the size of the queue.)

pub1 = rospy.Publisher("/topic_name", message_type, queue_size=size)

pub1.publish(message)

command line example to publish a message.

publish messages(geometry_msgs/Twist) to topic(cmd_vel)

$ rostopic pub /cmd_vel geometry_msgs/Twist  "linear:
  x: 0.1
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.1"

see realtime msg from a topic

$ rostopic echo topic_name

ROS Subscribers

A Subscriber = node to read messages from a topic.

data -> streamed -> node.

sub1 = rospy.Subscriber("/topic_name", message_type, callback_function)
# callback_function is not required to return anything.

ROS Service

node <-> request/response <-> node

service = rospy.Service('service_name', serviceClassName, handler)

# using service
service_proxy = rospy.ServiceProxy('service_name', serviceClassName)

msg = serviceClassNameResponse()
#update msg attributes here to have correct data
response = service_proxy(msg)

Last updated

Was this helpful?