How to write a callback subscriber for sensor_state (turtlebot3_msgs/SensorState)
I was trying to make a python script. In the subscriber callback, I am stuck on how do I create and get the values of the wheel encoders. I ask for help about this subject and someone said that the encoders are Uint32 which doesn't give much help. btw it's python
Version: Ubuntu (64-bit)
`#!/usr/bin/env python
import rospy
from turtlebot3_msgs.msg import SensorState
def callback(msg):
print ("left encoder = " + {left_encoder.msg})
print ("right encoder = " + {right_encoder.msg})
def talker():
rospy.init_node('sensor')
rospy.Subscriber("/sensor_state", SensorState, callback)
rospy.spin()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass
Could you pls show code snippets, the errors you are getting and ROS version you are working please.
I have updated the question
Thank you for sharing the code. Could you pls share your outputs.
From https://github.com/ROBOTIS-GIT/turtle...
Header header
uint8 bumper
float32 cliff
float32 sonar
float32 illumination
uint8 led
uint8 button
bool torque
int32 left_encoder # (-2,147,483,648 ~ 2,147,483,647)
int32 right_encoder # (-2,147,483,648 ~ 2,147,483,647)
float32 battery
I understand why the suggestion for int32 as the format of the msg for left_encoder and right_encoder are in this type.
I was investigating a little and it seems it may have to do with OpenCR firmware not updated and not necessarily your code. Check this thread on no battery similar issue. I’ll keep digging.
https://github.com/ROBOTIS-GIT/turtle...
Yes I believe this is to opencr setup.
https://emanual.robotis.com/docs/en/p...
Hope this helps to check if it’s a hardware issue. Let me know and I’ll turn this into an answer
I tried to replicate in simulation, but this is only available with turtlebot3 hardware.