I need to write a ROS publisher node (and then subscriber node) using IMU data which is published from the IMU using OSC. I have a python script which will print the data to screen but I need to be able to publish this via ROS.
I have seen rososc but this seems linked to using smart devices which I'm not using and I just don't know enough to be able to convert it to what i need.
I've written some code using examples I've found as a basis but at the moment it just publishes 'none' instead of the data stream.
How do i get the OSC published in a ROS node and not just to screen?
Here is my code - it's basically the same as the original script but with some ROS commands mixed in.
# I've added this function
def handlerfunction(s, x, y, z, w):
# Will receive message data unpacked in s, x, y
pass
def generate_imu():
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="0.0.0.0", help="The ip to listen on")
parser.add_argument("--port",
type=int, default=8084, help="The port to listen on")
args = parser.parse_args()
dispatcherObj = dispatcher.Dispatcher()
# dispatcherObj.map("/quaternion", print) #- original command to print data to screen
pub=rospy.Publisher('imu_pub',Float32,queue_size=10)
rospy.init_node('generate_imu')
while not rospy.is_shutdown():
#/quaternion is imu data followed by numerical data. I replaced 'print' with handlerfunction
ngimu_out = dispatcherObj.map("/quaternion",handlerfunction)
rospy.loginfo("imu: %s", ngimu_out)
pub.publish(ngimu_out)
server = osc_server.ThreadingOSCUDPServer((args.ip, args.port), dispatcherObj)
print("Serving on {}".format(server.server_address))
server.serve_forever()
The commented line is I get: [INFO] [1556016429.254443]: imu: None
I want to get: [INFO] [1556016429.254443]: imu: 0.02763 3.282368 9.367127 0.32357235 0.775263
If anyone can help or even point me in the right direction I'd be so thankful.
tia
# I've added this function
def handlerfunction(s, x, y, z, w):
# Will receive message data unpacked in s, x, y
pass
This part doesn't do anything.
How about trying this?
class imu_data:
def __init__(self):
self.s = 0
self.x = 0
self.y = 0
self.z = 0
self.w = 0
# I've added this function
def handlerfunction(s, x, y, z, w):
# Will receive message data unpacked in s, x, y
newData = imu_data() //creating new object
newData.s = s;
newData.x = x;
newData.y = y;
newData.z = z;
newData.w = w;
return newData
And:
rospy.init_node('generate_imu')
ngimu_out = new imu_data()
while not rospy.is_shutdown():
Could you check if it works please? If it doesn't try to print it separately.
print("s: " + ngimu_out.s)
Like this for example
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.