ROS and APM

3689392696?profile=originalRecently I've been reading about the Robot Operating System (ROS) from Willow Garage and thinking about ways that it could interface with a UAV system to take advantage of many of the robot navigation and task planning routines that have already been developed for other platforms.  After going through some of the ROS tutorials, I started coding a publisher node for APM, it reads telemtry data via serial in the GCS Standard format, and publishes the data as ROS messages that can be subscribed to by any other ROS nodes.  My chosen language is Python:

 

#!/usr/bin/env python
import roslib; roslib.load_manifest('apm_talker')
import rospy
from std_msgs.msg import Int16MultiArray, MultiArrayDimension
import serial
import struct

def parsemessage(mtype, mdata):
ddict = dict()
if mtype=='\x01':
ddict['SystemStatus'] = list()
ddict['SystemStatus'].append(int(mdata[2].encode('hex'), 16))
ddict['SystemStatus'].append(struct.unpack_from("h", mdata[5:7])[0])
if mtype=='\x02':
ddict['Attitude'] = list()
ddict['Attitude'].append(struct.unpack_from("h", mdata[2:4])[0])
ddict['Attitude'].append(struct.unpack_from("h", mdata[4:6])[0])
ddict['Attitude'].append(struct.unpack_from("h", mdata[6:8])[0])

if mtype=='\x04':
ddict['PressureAlt'] = list()
ddict['PressureAlt'].append(struct.unpack_from("I", mdata[2:6]))
#if mtype=='\x05':
# ddict['StatusText'] = list()
# ddict['StatusText'].append(str(mdata[2:len(mdata)-2]))
return ddict

def talker():
pub = rospy.Publisher('apm_data', Int16MultiArray)
rospy.init_node('talker')
ser = serial.Serial("/dev/ttyUSB0", 57600)
while not rospy.is_shutdown():
f = ser.read(size=1)
if f=='\x34':
f = ser.read(size=1)
if f=='\x44':
f = ser.read(size=1)
data = ser.read(size=int(f.encode('hex'), 16)+4)
datadict = parsemessage(data[0], data)
for signal in datadict:
msg = Int16MultiArray()
msg.layout.dim = [MultiArrayDimension(signal, 1, 1)]
msg.data = datadict[signal]
pub.publish(msg)
#rospy.loginfo(msg)

if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException: pass

 

This is fairly basic, and it doesn't cover the entire APM message set.  There is still work to do to decide how the APM messages should be translated into ROS topics and messages to allow for the most flexibility when using it with other packages - for example, ROS seems to use quaternions when representing robot attitude, so it will be necessary to convert from the APM Euler angles.

 

More details on my projects blog including code for a subscriber node, and some details on how the whole thing is run.

E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones

Comments

  • even though its old thread....

    Check this out...for easy application development in ROS.

    http://diydrones.com/profiles/blogs/start-building-high-level-drone...

  • Andrew, I think you did a great job interfacing this quickly and posting about it. Your contribution is really appreciated and I didn't want to minimize this. I just wanted to make clear that several approaches exist and that it might be worth trying to stay compatible with each other's work.

     

    One thing that many people would benefit from is if you would e.g. use pyMAVLink to write a human-readable logger/output ROS node. I think pyMAVLink implements part of this already. I would ba also glad to include your contributions in the official mavlink-ros-pkg.

     

    We have implemented digital image streaming for MAVLink with OpenCV on the MAVCONN middleware. It's not yet in the public tree though. For ROS you could use the same message set, the benefit would be the suitability for radio modems and the QGroundControl widget displaying the video data.

     

    Of course an analog link has much more bandwidth, so you won't get smooth video over a radio modem, but the benefit would be to have ultra-long range transmissions over miles (but really slow image transmission then).

     

    Looking forward for your next steps, keep it up!

  • Rhett, I agree, this was half an exercise to learn more about ROS, and I hadn't had a chance to get a version of APM 2.0 compiled and working on my board with MAVLink yet. Next I will probably take a look at the mavlink-ros-pkg and try to get that working with APM 2.0.

    Sending video back to ROS for doing things like bearing-only SLAM would be really interesting - for the video, I would image you would need a dedicated link as with fpv, unless it is possible to include images in the MAVLink stream - I need to read more about this.

     

  • 3D Robotics
    Ivan, any PC on the ground can run a full ROS install and control multiple ROS nodes.
  • Which ground-based ROS controllers exists?
  • We're not using ROS internally (using MAVCONN, its more lightweight:  https://github.com/pixhawk/mavconn), but what you're talking about is our research core, here are some interesting demo videos showing autonomous flight (no human control) using computer vision and also pattern recognition.

     

    Of course you can do the very same thing with ROS as base as well and since MAVLink has been used in the control loop already, all the required messages already exist and are well-tested.

     

    http://pixhawk.ethz.ch/videos/

    pixhawk/mavconn
    Lightweight robotics middleware for Linux/Unix systems - pixhawk/mavconn
  • I wonder if you could implement full ROS via telemetry and some kind of fpv setup for computer vision. You could even use the MAVLink protocol for in flight two way communication. Having CV on a mobile platform like a UAV would make for an awesome addition.
  • I forgot: For those interested in using APM Beta 2.0 + ROS + Python: There is a convenient Python MAVLink decoder: http://www.qgroundcontrol.org/mavlink/pymavlink

     

    I understand the point in writing a simple decoding app in python, I think however that if you really want to use ROS for robotics, you don't want to have to write a decoder for every single GCS format packet. This ends up in just reimplementing functionality that is already available in the field.

    I think the APM community would really appreciate if you help in getting more interoperability between autopilots, GCS and robots (a.k.a. ROS) using the standard protocols of APM 2.0.

  • Hi Andrew,

     

    Since APM is moving from the GCS format to MAVLink, you might want to have a look at this already fully implemented ROS<->MAVLink bridge. It forwards all MAVLink messages to ROS for further processing. I think it doesn't make sense to go with the outdated GCS protocol. It would be nice if you would join the efforts and extend the MAVLink bridge to also send out further ROS packets:

     

    https://github.com/pixhawk/mavlink-ros-pkg

    pixhawk/mavlink-ros-pkg
    MAVLink / MAVCONN to ROS adapter package. Contribute to pixhawk/mavlink-ros-pkg development by creating an account on GitHub.
  • 3D Robotics
    Rhett: just to be clear, this would make APM a ROS node, not run full ROS on APM. This would allow a ground-based ROS controller run multiple APM-powered UAVs as part of a flocking/swarming mode.
This reply was deleted.