Debugging Arduino Code on an Omnidirectional Mobile Chassis

Debugging Arduino Code on an Omnidirectional Mobile Chassis

This tutorial introduces how to debug the Arduino code on a real omnidirectional mobile chassis. Only by debugging the code of the lower computer can we ensure that the upper computer code runs normally. Here, the upper and lower computers communicate through the USB to TTL serial port of the lower computer.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

First, let’s introduce the hardware composition of the omnidirectional mobile chassis. Here is the omnidirectional mobile chassis I made. Everyone can debug their own omnidirectional mobile chassis; the debugging methods are similar, even if the modules on the chassis are different. The left image shows the chassis from above, while the right image shows the chassis from below.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

Next, we introduce the external dimensions of the chassis. The three wheels need to maintain a distance of 120 between each pair, and we also need to measure the distance from the center of the chassis to the wheels and the radius L of the omnidirectional wheels, as these parameters are needed for debugging the upper computer code later. It is important to pay attention to the load capacity of the omnidirectional wheels when selecting them. If the weight the chassis bears exceeds the load capacity, it will cause deformation of the omnidirectional wheels, damaging their structure and leading to instability in the chassis’s movement. Therefore, we need to choose omnidirectional wheels with different load capacities according to the project’s needs.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

Then we introduce an important module in the entire mobile chassis – the DC motor driver board. Since the chassis I made is relatively small, I chose a DC motor driver board that can be plugged together with the Arduino Mega 2560 board, which reduces the occupied area of the chassis and leaves more space for other modules.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

This driver board has fixed connection pins with the Arduino board in its hardware design, so you can use it directly in the code as required. Here, we added the definition of using external interrupts to count the encoder output pins.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

Debugging Arduino Code on an Omnidirectional Mobile Chassis

This section introduces the parameters of the DC reduction motor and provides an in-depth analysis based on the corresponding parameters to facilitate our selection of suitable motor models. First, we introduce the impact of the motor’s output speed on our chassis. Based on the motor’s speed and the diameter of the wheels we installed, we can calculate the maximum linear speed of the mobile chassis in the X and Y directions, as well as the maximum angular speed of rotation in place.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

Here we introduce the conversion between rated torque and different units of torque, which facilitates our selection and comparison between different motors. Of course, the parameters provided by sellers may sometimes have some errors, so we need to test the actual performance in a real environment.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

This section introduces how to connect the encoder output to the interrupt pin of the Arduino board, triggered by level changes. We bind both outputs of the encoder to one interrupt handler function, which can provide four times the output precision of the encoder.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

This section introduces the encoder adapter that matches the motor. Since the encoder output of this motor does not have a pull-up resistor internally, this adapter is required. If the motor encoder you purchased already has an internal pull-up resistor, then this adapter is not necessary.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

To facilitate power control of the chassis motors, I added this MOSFET DC switch module to the chassis, which serves the same function as a relay. This way, we can easily control the power of the chassis motors through commands. In certain situations where an emergency power-off of the chassis movement is required, we do not need to power off the entire robot; we just need to send a command to cut off the power to the chassis motors.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

Here, I added a speaker, so we can know the current running status of the chassis through different sound feedback. The speaker is affordable and can be easily connected to the Arduino board for development.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

After introducing the hardware module composition, we will start the formal debugging process. First, we will debug whether the three motors can work normally by sending the ‘m’ command through the serial port, followed by three parameters representing the rotation pulse counts of motors A, B, and C.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

Next, manually rotate the wheels one full turn to see if the encoder feedback output matches the expectations. By sending the ‘e’ command through the serial port, we can obtain the feedback output of the three encoders. The ‘r’ command can clear the counts of the three encoders and start counting again.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

Next, we will debug whether the speaker can work normally. Since this part of the code was added later, we need to first see how to write the code. Here, I added sound.h and sound.ino files, and also added a new command ‘f’ for speaker operations. By sending ‘f’ through the serial port along with the sound number, we can control the speaker to emit the corresponding sound. I only wrote two types of sounds here: the sound when the chassis is powered on and the sound when it is powered off. More types of sounds can be added in the future as needed so that we can know the current running status of the chassis based on different sound feedback.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

Since the DC switch is also a newly added module, we need to first check how to write the code. Here, the module is connected to digital IO pin 52, and we can control the module’s power on and off by setting the digital IO pin high or low.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

Next, we will debug whether this module can work normally. By sending the ‘w’ command through the serial port, followed by the pin number of the IO port and either 0 or 1 (0 means set low, and 1 means set high), we can operate the digital IO port to turn the module on or off, completing the power on and off operation.

Debugging Arduino Code on an Omnidirectional Mobile Chassis

Finally, let’s summarize the main content of this tutorial. This tutorial demonstrates how to debug the Arduino code of a simple mobile chassis I made, as well as how to debug some simple modules such as the speaker and relay. Of course, in the future, I will gradually add additional obstacle avoidance sensors, but the debugging process will be similar. After adding the corresponding modules, I will explain how to debug the corresponding sensor modules.

Due to my limited ability, if there are any issues in this tutorial, please leave me a message, and I will correct any errors in the tutorial in a timely manner. Similarly, if you want to view the video tutorial for this tutorial, you can search for “ROS Classroom” on Youku to find the corresponding playlist “Making ROS Three-Wheeled Omnidirectional Chassis” to see the video explanation of this tutorial.

Leave a Comment

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