Meet R2-D2's cousin, Robert!
This project is maintained by ece3140-sp22
In our final project, we programmed the FRDM-KL46Z board to send commands to an Arduino Mega board to control the locomotion of a dual-motor robot. The Arduino receives commands to move forwards and backwards, and turn left and right through UART serial communication. Depending on the received commands, the Arduino outputs PWM values to drive the motors on the robot. In order for the motors to move in real-time, we implemented real-time processing to schedule multiple motor commands. We also coded the FRDM board to flash a green LED concurrently while sending a command to signal a successful communication. Through this project, we were able to put the concepts we learned in class to use, including serial communication and real-time scheduling. We learned how to use these embedded systems skills to bring a robot to life through a real-time locomotion system.
The FRDM board sends tuples of motor power to an Arduino Mega through UART in the form of (_0.LL,_0.RR); it starts with a plus or minus sign that indicates the spin direction, followed by a float number which indicates the fraction of the maximum motor power. The first number in the tuple represents the left motor’s setup, and the second represents the right motor’s. The Arduino receives the message and decodes it. The message is then sent to a driver from the Arduino, which prompts the motor to spin in the specified direction.
Our system is divided into three main parts: the FRDM board, the Arduino, and the motor and the driver.
First, in the FRDM board code, we initialize UART and set up the required modules and pins for serial communication. We used the uart_puts() function that was provided in the example serial code. To implement process scheduling, we created a process for each command sent to the Arduino, and we created time structs to hold the start time and deadline of each process. We also made a process to flash the green LED to signal that a command was communicated. We made use of the real-time scheduler that we created in lab 5.
Next, we created an Arduino code file that checks if there is anything coming from the serial line connected to the FRDM board. If it detects a command, the incoming message is stored in a buffer and printed to the serial monitor. Since the buffer is in ASCII, we convert it to readable characters before printing it out. Then, we convert the received command into analog and digital outputs that the driver can understand. Since the incoming command takes the form “(+0.00,-0.00)”, we divide it into two floats containing the left and right numbers. We do this by creating an array of characters and then using the atof() method. Using these floats, we can calculate the percentage of maximum motor power we want the motor to spin at as well as whether each motor should spin clockwise or counterclockwise. After executing this logic, we write the outputs to their respective pins, which were initialized in the setup() method of the code along with the serial ports. Lastly, to send the command from the Arduino to the motor, we connect the outputs of the Arduino with their respective inputs on the driver.
To establish a serial communication between the FRDM board and the Arduino, we connected the Tx pin on the FRDM board to the RX pin on the Arduino, and we also connected their grounds. The testing of this connection is described in the testing section.
Although the initial expectation was to make the entire robot move, we had some mechanical issues in the robot’s wheels and had to take off the motors from the robot’s body. However, our plan was to move the motors using the FRDM and Arduino boards, so the main goal of the project remained unchanged, and we successfully implemented the locomotion system.
We tested our project in stages. First, we wanted to make sure that the Arduino could receive serial input from the FRDM board. We did this by continuously passing in values from the FRDM board to the Arduino and checking to see if the values were received in the Arduino serial monitor. We then passed in the tuples of motor power to the Arduino and checked to see that it was receiving the correct messages. At first, we forgot to switch the buffer size, so we thought that the code was not working, but after we made the buffer size 13, it was working properly.
Next, we wired the Arduino to the driver and the driver to the motor so that the Arduino messages would actually be able to move the motor. This was done by connecting the PWM pins on the Arduino to their corresponding wires on the driver. We tested this connection by manually writing PWM and clockwise/counterclockwise values to the Arduino’s output ports and checking that the motor was spinning as intended.
The final stage of testing was ensuring that real-time scheduling was functional. We made use of our code from lab 5 to do this. We created a total of 8 processes with different start times and deadlines and ensured that they ran in the expected order by observing the terminal on the debugger and the green LED flashes. At the end of execution, there were no processes that had missed their deadline, meaning our code worked as expected.
We used the Serial Code example provided by Professor Napp to set up UART. We also used our code from lab 5 (real-time scheduling) to set up the process scheduler. We soldered pins onto the FRDM board to ensure the connection of the TX and RX ports and the ground to the Arduino board.
Everyone in the group worked together on the project. We reached out to each other whenever we felt unsure about our decision or faced a problem and posted questions on Ed Discussion to receive help. We always tried to exchange opinions and thoughts to seek the most efficient way to implement our system. The website was completed by dividing work equally among group members.