0
$\begingroup$

I have a motor driver for a BLDC wheel. I have successfully made the motor driver and ROS connections and when I send motor_command as in the "user manual" of the motor drivers, my wheels are working.

I found a package to make Differential Drive. Differential Driver Package link

I can use the "twist_to_motors.py" file to be able to drive in this package. But how can I provide a bridge between my motor driver and this file?

my motor command : rostopic pub -r 10 /bldc_driver_node/Command chip_bldc_driver/Command "motor_command: 100"

if i run this command my wheel is spin. But cmd_vel and i want use teleop, how to bridge?

this my motor driver package link : motor-driver-package

$\endgroup$

1 Answer 1

1
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.