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 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:
Now let’s take a look at the interface guide for the Arduino expansion board:
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:
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“.
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 part” should 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)
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)
Additionally, you need to power the driver . 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:
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;
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
-
“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.
04
Summary, Outlook, Easter Egg
Summary:
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.
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.
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:
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!
———
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
Leave a Comment
Your email address will not be published. Required fields are marked *