Robotics StackExchange | Archived questions

rostopic publish/subscribe over serial port

Hi, I'm trying to receive IMU data from simulink on a STM32 Nucleo board over port "ttyACM0" to a topic "/rawimu" and also publish navigation plan coordinates from rostopic "/localplan".

I'm confused about the general method of doing this. Do I make a script to run on the host computer or the STM board? I've tried the tutorials on the the wiki and this is the best I can come up with but I'm not sure where to put it. This part is only for the board publisher. (I know it's very not right but any tips would be super helpful)

#!/usr/bin/env python import roslib

import rospy from nav_msgs.msg

import Path

import serial

ros::NodeHandle nh;

ser = serial.Serial('/dev/ttyACM0', 9600)

def talker():

while not rospy.is_shutdown():

data= ser.read(2)

rospy.loginfo(IMU)

pub.publish(String(IMU))

rospy.sleep(1.0)

if name == 'main':

try: pub = rospy.Publisher('IMU', String)

rospy.init_node('talker')

talker()

except rospy.ROSInterruptException:

pass

Asked by jamesislost on 2019-06-03 13:13:01 UTC

Comments

Answers

This depends on the IMU board your using, what protocol it uses and if you can update its firmware or not. For example the Razor IMU ROS package uses a custom firmware on the board and a ROS node on the host computer together to publish the IMU data to ROS. Another option would be to use ROSSerial on the board so it publishes the IMU messages directly.

It looks like you're using an arduino derivative so the ROSSerial option would probably be the simplest method to use. There are somegood tutorials(http://wiki.ros.org/rosserial/Tutorials) you can use to get started. Is the IMU data you're receiving already calibrated or will the node need to do that as well?

Hope this gives you some pointers.

Asked by PeteBlackerThe3rd on 2019-06-03 15:06:01 UTC

Comments