Based on the twist_to_motors.py documentation, it sounds like you have to map the following two published topics to your motor command subscribers:
lwheel_vtarget - (std_msgs/Float32)
The target velocity for the left wheel (in M/s)
rwheel_vtarget - (std_msgs/Float32)
The target velocity for the right wheel (in M/s)
One way I can think of to do this is to implement a bridge node. The bridge node would subscribe to the lwheel_vtarget
and rwheel_vtarget
topics, and in the callback functions you would add the logic to convert from m/s to your motor command and publish the motor command.
Here's a sketch implementation in Python (I haven't tested it):
import rospy
from chip_bldc_driver.msg import Command
from std_msgs.msg import Float64
def main():
rospy.init_node('bridge_motor_command')
left_pub = rospy.Publisher('left/motor_command', Command, queue_size=10)
right_pub = rospy.Publisher('right/motor_command', Command, queue_size=10)
def convert(msg):
command = Command()
# TODO: change this line to properly convert from m/s to motor command
command.motor_command = msg.data * 1000
def left_callback(msg):
nonlocal left_pub
left_pub.publish(convert(msg))
def right_callback(msg):
nonlocal right_pub
right_pub.publish(convert(msg))
left_sub = rospy.Subscriber("lwheel_vtarget", Float64, left_callback)
right_sub = rospy.Subscriber("rwheel_vtarget", Float64, right_callback)
rospy.spin()
The publisher topic names and queue sizes can be changed to fit your needs. Similar code could be implemented in C++, if that is your preferred language to use.