Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

01

Introduction

In the previous articles, we mainly recorded how to drive TT motors with Hall encoders and low-power DC gear motors using our Arduino Mega 2560 expansion board (with TB6612).

  • “Open Source! A Step-by-Step Guide to Driving Motors with Arduino+ROS Car”

  • “Open Source! A Step-by-Step Guide on How to Adjust Encoder Motor Speed PID”

With the above two documents, you can complete the driving and control part of a ROS car chassis like the one shown below.

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

  • “Open Source! A Step-by-Step Guide to Building Arduino+Nvidia Jetson ROS Car (Part 2)”

This article records how to achieve data interaction through the ROS package (ros_arduino_bridge) and Arduino, implementing the communication method of ROS Topic to control the motor to perform specified actions.

Later, some friends asked if it is possible to control and drive high-power DC motors with Arduino? The answer is definitely yes. Next, I will introduce the expansion board interface and how to run the code along with some precautions.

02

Arduino Mega 2560 High-Power Motor Expansion Board

We have stripped the motor driver module (TB6612) from the original Arduino expansion board and left the corresponding interfaces. This way, you can adapt to different power drivers based on the motor power. As shown in the combination below:

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

Now let’s take a look at the interface guide for the Arduino expansion board:

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

This time, we take the Chihai motor + high-power dual-channel DC driver as an example:

  • Motor rated voltage: 12v;

  • Motor planetary gear reducer ratio: 27;

  • Motor AB phase Hall encoder: 13ppr;

  • Driver motor voltage range: 5.6~33v;

  • Driver continuous output current: 12.8A;

  • Driver channel output power: 380 watts;

  • Driver control logic: similar to L298 (PWM pin speed control, GPIO pin direction control);

As shown in the figure below:

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

03

Test the connection correctness through code

Compared to the previous expansion board, this expansion board adds twovariables, which are:

  • Wiring of the driver control pins;

  • Wiring between the driver motor output and the expansion board or the positive and negative terminals of the motor;

To help everyone connect the wires correctly, this section will explain: “Connecting the Wires” and “How to Check if the Wires are Connected Correctly Through Code“.

1. Verify the Direction of the Horn Connector

The horn connector wire should be plugged into the Arduino expansion board horn socket on one end and into the motor driver control pin interface on the other end. When inserting into the driver, please pay attention to the following points:

  • The horn connector “protruding partshould face the direction of the driver motor output interface (yellow);

  • Or the red side of the horn wire should be close to the “V3.0” text next to the driver; (Make sure to pay attention)

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

The control interface PCB guide of the Arduino expansion board is as shown in the figure below:

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

5V PWMA (4) IN1 (22) IN2 (24) GND
5V PWMB (5) IN3 (28) IN4 (26) GND

Table 1-1

2. Verify the Connection Correspondence of the Motor Power Wires

It is important to note that the driver motor power interface needs to be connected to the Arduino expansion board’s power interface. The connection correspondence is as follows:

  • Driver motor 1 <——-> Expansion board right power interface (or right motor positive and negative terminals)

  • Driver motor 2 <——-> Expansion board left power interface (or left motor positive and negative terminals)

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

Additionally, you need to power the driver Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROSOpen Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS. The driver power interface is the part between motor1 and motor2, and the driver has marked positive and negative terminals on the back, with a voltage range of [5.6, 33] volts. Of course, you also need to connect the motor wire interface according to the left-right order of the above motor power interface, and the motor wire interface can be connected to either a 2.54mm pitch 4pin or 6pin.

3. Test the Wire Connections Through Code

The control interface of the driver used in this article is shown in the figure below:

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

Its control logic is consistent with the L298N control logic. Therefore, combined with the Table 1-1 of the Arduino expansion board’s interface definition, the test code is as follows:

// Control the left motorint enA = 4;   // PWM speed control pinint in1 = 22;  // Motor direction control pin 1int in2 = 24;  // Motor direction control pin 2// Control the right motorint enB = 5;   // PWM speed control pinint in3 = 26;  // Motor direction control pin 1int in4 = 28;  // Motor direction control pin 2// This program segment will only execute once, generally used to initialize pins and variables, etc.void setup() {  // Set all control pins to output state.  // PWM output pins  pinMode(enA, OUTPUT);  pinMode(enB, OUTPUT);  // Motor direction control pins  pinMode(in1, OUTPUT);  pinMode(in2, OUTPUT);  pinMode(in3, OUTPUT);  pinMode(in4, OUTPUT);  // Default initialize the motor driver to stop state.  digitalWrite(in1, LOW);  digitalWrite(in2, LOW);  digitalWrite(in3, LOW);  digitalWrite(in4, LOW);}// This function will run continuously, similar to the while() function;void loop() {  directionControl();  delay(1000);}// This function lets you control the spinning direction of motorsvoid directionControl() {  // The motor should spin forward, test reverse later by commenting out  analogWrite(enA, 30);    // PWM value should be in the range [0,255].  digitalWrite(in1, HIGH);  digitalWrite(in2, LOW);  analogWrite(enB, 30);    digitalWrite(in3, HIGH);  digitalWrite(in4, LOW);  // Reverse, comment out the code below to test reverse later  //  analogWrite(enA, 30); //  digitalWrite(in1, LOW); //  digitalWrite(in2, HIGH); //  analogWrite(enB, 30);  //  digitalWrite(in3, LOW); //  digitalWrite(in4, HIGH);  delay(2000);  digitalWrite(in1, LOW);  digitalWrite(in2, LOW);  digitalWrite(in3, LOW);  digitalWrite(in4, LOW);}

By observing the program and the motor’s rotation phenomenon, determine whether the wiring sequence between the motor driver’s two output terminals and the motor’s positive and negative terminals is correct. The testing steps are as follows:

  • After compiling and uploading the program, the motor will: spin forward –> pause –> spin forward … If it does not spin forward, then you need to switch the order of the two wires at the driver output;

  • Comment out the reverse code at the bottom of the program and uncomment the forward code, then recompile and upload the code. The expected phenomenon should be that the motor will reverse;

The testing phenomenon is shown in the animated image below:

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

After the testing is completed, it means that the wiring between your driver and the motor, as well as the wiring between the driver and the Arduino expansion board, are all correct. Next, you need to upload our other piece of code, which is the corresponding code for the subsequent ROS car.

The corresponding tutorial and the previous explanation of the process with the TB6612 driver are consistent, but the code used is slightly different. The code address for this article is as follows:

# See the corresponding Arduino folder in the repository for detailshttps://github.com/COONEO/Arduino_Jetson_nano_ROS_Carhttps://github.com/COONEO/Arduino_Raspberry_ROS_Car
Then, follow the two articles shown in the figure below to complete the driving part of the ROS car with Arduino.
  • “Open Source! A Step-by-Step Guide to Driving Motors with Arduino+ROS Car”

  • “Open Source! A Step-by-Step Guide on How to Adjust Encoder Motor Speed PID”

After that, follow the steps shown in the figure to configure the corresponding ROS package.

  • “Open Source! A Step-by-Step Guide to Building Arduino+Nvidia Jetson ROS Car (Part 2)”

The code and configuration methods of the ros_arduino_bridge are universal; as long as it is an Ubuntu + ROS environment, it can be used, regardless of the specific hardware processor.

Motor Driver ModuleOpen Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROSCOONEO Flagship Store126

04

Summary, Outlook, Easter Egg

Summary:

This article mainly introduces the usage of the new version of the Arduino expansion board. The author records the wiring precautions from the PCB interface description of the expansion board to the actual wiring of high-power motors and motor drivers; from the control logic of the motor driver to the actual code operation to assist in detecting whether the connections between the driver, motor, and expansion board are correct, and finally adapting to the previous articles written. I hope the detailed debugging process recorded in this article can assist you in joyfully building the physical car.

Outlook:

Looking back at the rendering of the previous Arduino expansion board, we can find that our board also has two servo interfaces, which can drive two servos like the MG996. The total output current of these two outputs is 3A, which can provide stable power for high-power servos.

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

Therefore, our Arduino expansion board can not only drive two-wheel differential cars with different motor powers but can also drive an Ackermann car (rear-wheel drive, front-wheel steering) by adding one servo.

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

Or drive a 2-degree-of-freedom gimbal, and further combine with OpenCV to achieve object tracking? Or like the infantry robot in RoboMaster, automatically aim and shoot?

So stay tuned for more updates!

Easter Egg:

Welcome to join ourdiscussion group for friends who love robot development, to facilitate everyone to learn, share, and exchange intelligent robot creation together, and meet more like-minded friends. There are also exclusive community welfare from time to time! Follow our public account to get the way to join the group. Let robot/unmanned vehicle development be more efficient!

Creating content is not easy, if you like this article, please share it with your friends to enjoy and exchange the joy of creation together, and also motivate us to create more robot development strategies for everyone. Let’s learn by doing together!

———

Recommended Reading:
The robot has tapped you, how about a simulation test?
Robot Target Detection | Recognizing you only takes a moment
The Flat World in the Robot’s Brain
Three Minutes to Understand PID Algorithm
Gesture Recognition and Control | “Contactless” Mode During the Epidemic
ROS Takes You Through Simulation and Reality
Depth Camera | The Smart Eye of the Robotic Arm
Odometry | The Distance Between You and Autonomous Mobile Robots
Mysterious Unboxing | NEOR mini User Feedback

Building a ROS Open Source Mini Unmanned Vehicle from Scratch

Standing on the Shoulders of PX4-Autopilot: Outdoor Unmanned Driving Path Planning

NEOR mini Running Wild on the Track

Building an Open Source Crop Patrol Robot from Scratch

Open Source! A Step-by-Step Guide to Building Arduino+Raspberry Pi ROS Car (Part 1)

Open Source! A Step-by-Step Guide to Building Arduino+Raspberry Pi ROS Car (Part 2)

Building ROS Robots – Ubuntu Binding Serial Devices

Open Source! Visual Line Following ROS Car Based on OpenCV

Open Source! Webots + ABB Robotic Arm Inverse Kinematics Solving Building ROS Robots – Copying Raspberry Pi System Image and Mounting Free Memory
Step-by-Step Guide to Velodyne Lidar Simulation + 3D Mapping
Open Source! Step-by-Step Guide to Multi-Channel Ultrasonic Sensor Obstacle Avoidance Simulation
Camera Calibration and Distortion Correction – Taking Raspberry Pi Wide Angle as an Example
Raspberry Pi Wide Angle Camera Target Detection and Monocular Distance Measurement
Building ROS Robots – Ackermann Chassis Odometry Calculation Node
Building ROS Robots – Using Programs to Publish Navigation Target Points
Building ROS Robots – Step-by-Step Guide to Using Gmapping for 2D Mapping
Building ROS Robots – Overview of Laser Radar 2D Mapping Methods
Practical Test! ROS Robot 400 Square Meter Circular Floor Different Methods Mapping Analysis
Open Source! Step-by-Step Guide to Building Arduino+Nvidia Jetson ROS Car (Part 1)
Open Source! Step-by-Step Guide to Driving Motors with Arduino+ROS Car
2021 Annual Free Open Resource Sharing – Ackermann and Differential Chassis Series Simulation
2021 Annual Free Open Resource Sharing – Building ROS Car Series NEOR mini Self-collected Data Set LeGO-LOAM Mapping Open Source! Step-by-Step Guide to Building Arduino+Nvidia Jetson ROS Car (Part 2) VMware Virtual Machine Network Configuration
Open Source! Step-by-Step Guide on How to Adjust Encoder Motor Speed PID

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

Open Source! A Step-by-Step Guide to Driving High-Power DC Hall Encoder Motors with Arduino and ROS

Leave a Comment

Your email address will not be published. Required fields are marked *