Files
clover/docs/en/ros.md
Alexey Rogachevskiy 4a23a9274a Move to Raspbian Buster (#193)
* builder: Build against Buster

* builder: Use correct repository specifications

* builder: Move ld.so.preload to have less errors

* builder: Use coex repo to install Monkey

* builder: Search for buster ROS packages

* aruco_pose: Vendor in aruco library from OpenCV 3.4.6

* builder: Move to ROS Melodic

* builder: Update kernel version

* aruco_pose, clever: Remove opencv3 ROS dependency

* builder: Update rosdep

* travis: Disable eclint for vendored aruco library

* tests: Don't try to locate opencv in ros

* roscore: Use melodic distribution

* Revert "aruco_pose: Vendor in aruco library from OpenCV 3.4.6"

This reverts commit 9c14a8c002bb3396f9a7d9b2ba39969207f066ba.

* aruco_pose: Vendor opencv_contrib/aruco again

* builder: Add led packages

* builder: Remove unused builder code

* travis: Add native tests

* builder: Set permissions for standalone-install

* builder: Use -y for package installation

* builder: Add repo for standalone build

* builder: Use correct file types for standalone install

* aruco_pose: Accept rgb8 map images

* builder: Disable mjpg_streamer test

* aruco_pose: Allow rgb8 map images (again)

* builder: Re-add mjpgstreamer

* builder: Install tornado==4.2.1 for rosbridge_suite

* builder: Use more recent base image

* builder: Use default kernel

* builder: Move ld.so.preload back after tests

* builder: Disable catkin tests

These tests fail on a remote machine but seem to pass just fine on real hardware. Something must have changed between Kinetic and Melodic, and we must investigate more, but for now we just need a working image.

* aruco_pose: Remove unused vendored code

* selfcheck: Update systemd-analyze regex

* builder: Add opencv repository

* rosdep: Update package definitions for Melodic

* rosdep: Use proper yaml formatting

* travis: Remove unnecessary space

* docs: Reference Melodic wherever possible
2019-12-06 21:25:19 +03:00

3.7 KiB

ROS

Main article: http://wiki.ros.org

ROS is a widely used framework for developing complex and distributed robotic systems.

Installation

Main article: http://wiki.ros.org/melodic/Installation/Ubuntu

ROS is already installed on the RPi image.

To use ROS on a PC, we recommend using Ubuntu Linux (or a virtual machine such as Parallels Desktop Lite](https://itunes.apple.com/ru/app/parallels-desktop-lite/id1085114709?mt=12) or VirtualBox).

Note

For ROS Melodic distribution, we recommend using Ubuntu 18.04.

Concepts

Nodes

Main article: http://wiki.ros.org/Nodes

ROS node is a special program (usually written in Python or C++) that communicates with other nodes via ROS topics and ROS services. Dividing complex robotic systems into isolated nodes provides certain advantages: reduced coupling of the code, increases re-usability and reliability.

Many robotic libraries and the drivers are executed in the form of ROS-nodes.

In order to turn an ordinary program into a ROS node, include a rospy or roscpp library, and insert the initialization code.

An example of a ROS node in Python:

import rospy

rospy.init_node('my_ros_node')  # the name of the ROS node

rospy.spin() # entering an endless cycle...

Topics

Main article: http://wiki.ros.org/Topics

A topic is a named data bus used by the nodes for exchanging messages. Any node can post a message in a random topic, and subscribe to an arbitrary topic.

An example of std_msgs/String (line) message type posting in topic /foo in Python:

from std_msgs.msg import String

# ...

foo_pub = rospy.Publisher('/foo', String, queue_size=1)  # creating a Publisher

# ...

foo_pub.publish(data='Hello, world!')  # posting the message

An example of subscription to topic /foo:

def foo_callback(msg):
    print msg.data

# Subscribing. When a message is received in topic /foo, function foo_callback will be invoked.
rospy.Subscriber('/foo', String, foo_callback)

There is also an opportunity to work with the topics using the rostopic utility. For example, using the following command, one can view messages published in topic /variety of the Aegean sea/state:

rostopic echo /mavros/state

Services

Main article: http://wiki.ros.org/Services

A service can be assimilated to the a function that can be called from one node, and processed in another one. The service has a name that is similar to the name of the topic, and 2 message types: request type and response type.

An example ROS service invoking from Python:

from clever.srv import GetTelemetry

# ...

# Creating a wrapper for the get_telemetry service of the clever package with the GetTelemetry type:
get_telemetry = rospy.ServiceProxy('get_telemetry', srv.GetTelemetry)

# Invoking the service, and receiving the quadcopter telemetry:
telemetry = get_telemetry()

You can also work with the services using the rosservice utility. For instance, you can call service /get_telemetry from the command line:

rosservice call /get_telemetry "{frame_id: ''}"

More examples of using the services for Clever quadcopter autonomous flights are available in the documentation for node simple_offboard.

Working on several PCs

Main article: http://wiki.ros.org/ROS/Tutorials/MultipleMachines.

The advantage of using ROS is the possibility of distributing the nodes across several PCs in the network. For example, a node that recognizes an image may be run on a more powerful PC; the node that controls the copter may be run directly on a Raspberry Pi connected to the flight controller, etc.