How to write a callback subscriber for sensor_state (turtlebot3_msgs/SensorState)

asked 2021-09-13 08:58:29 -0600

Mordred gravatar image

updated 2021-09-13 13:41:20 -0600

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
edit retag flag offensive close merge delete

Comments

Could you pls show code snippets, the errors you are getting and ROS version you are working please.

osilva gravatar image osilva  ( 2021-09-13 13:33:36 -0600 )edit

I have updated the question

Mordred gravatar image Mordred  ( 2021-09-13 13:42:08 -0600 )edit

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.

osilva gravatar image osilva  ( 2021-09-13 13:56:15 -0600 )edit

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...

osilva gravatar image osilva  ( 2021-09-13 15:59:04 -0600 )edit

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

osilva gravatar image osilva  ( 2021-09-13 16:16:30 -0600 )edit

I tried to replicate in simulation, but this is only available with turtlebot3 hardware.

osilva gravatar image osilva  ( 2021-09-13 17:43:17 -0600 )edit