Skip to content

Driving DC Motors for Tracks

botamochi6277 edited this page Aug 28, 2020 · 4 revisions

CAMROBO has 130-type DC-motor to drive the tracks. Raspberry Pi can control these motors with H-bridge motor drivers and PWM signals from the pi's gpio. In this section, you learn about two motor drivers.

Following wirings are examples. You can change wirings of GPIO and yaml files.

Wiring Example using Cytron Maker Drive

Cytron Maker Drive is a good choice for beginners. You can drive the motors without microcontrollers with pushing buttons to check wiring. Indicators in this drive show status of output signals for the DC-motors.

raspi_motor_maker-drive_bb

Driver Other Device
M1A (IN) Raspi-17
M1B (IN) Raspi-18
M2A (IN) Raspi-27
M2B (IN) Raspi-22
M1A (OUT) RMotor-YELLOW
M2A (OUT) RMotor-BLUE
M1B (OUT) LMotor-BLUE
M2B (OUT) LMotor-YELLOW
VM Alkaline-V+
5V0 Raspi-5V
GND Raspi-GND, Alkaline-V-

Wiring Example using TB6612

Sparkfun TB6612 module is smaller module to drive DC-motors. You can put this module on breadboards and proto-boards

raspi_motor_tb6612_bb

TB6612 Other Device
A_IN1 Raspi-22
A_IN2 Raspi-27
A_PWM Raspi-17
B_IN1 Raspi-13
B_IN2 Raspi-19
B_PWM Raspi-26
A01 RMotor-YELLOW
A02 RMotor-BLUE
B01 LMotor-BLUE
B02 LMotor-YELLOW
VM Alkaline-V+
VCC Raspi-3V3
STBY Raspi-3V3
GND Raspi-GND, Alkaline-V-

Run

Establish Motor Listener

tamiya_cam_robot/wheels_listener is a ROS node controlling DC motors for wheels (tracks) with H-bridge drivers. This node is L298N mode, having no PWMA and PWMB parameter. On the other hand, the node is TB6612 mode when it reserves PWMA and PWMB parameters.

  • Maker Drive (L298N)
rosrun tamiya_cam_robot wheels_listener

When you add no parameters, wheels_listener sets default values ( _AIN1:=17 _AIN2:=18 _BIN1:=27 _BIN2:=22).

When you changed a wiring, you need to remap the pin assignment.

rosrun tamiya_cam_robot wheels_listener _AIN1:=17 _AIN2:=18 _BIN1:=27 _BIN2:=21
  • TB6612

Inputing PWMA and PWMB set tamiya_cam_robot/wheels_listener on TB6612 mode.

rosrun tamiya_cam_robot wheels_listener _AIN1:=22 _AIN2:=27 _PWMA:=17 _BIN1:=13 _BIN2:=19 _PWMB:=26

Publish Command

tamiya_cam_robot/wheels_listener subscribes /tamiya1/cmd_vel (geometry_msgs/Twist) which is rostopic representing wheels efforts (-1.0 -- 1.0). You can drive the motors with publishing topics to the listener.

  • Forward
rostopic pub -1 /tamiya1/cmd_vel geometry_msgs/Twist  '{linear:  {x: 0.5, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'
  • Backward
rostopic pub -1 /tamiya1/cmd_vel geometry_msgs/Twist  '{linear:  {x: -0.5, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'
  • Turn Right (Clockwise)
rostopic pub -1 /tamiya1/cmd_vel geometry_msgs/Twist  '{linear:  {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: -0.5}}'
  • Turn Left (Counterclockwise)
rostopic pub -1 /tamiya1/cmd_vel geometry_msgs/Twist  '{linear:  {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.5}}'
  • Stop
rostopic pub -1 /tamiya1/cmd_vel geometry_msgs/Twist  '{linear:  {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'