Introduction: In this project, we used referenced the tutorial created by Joop Brokking. The HW5: Joysticks/Stepper Motor
was a brief introduction into how the stepper motor operates and the
basic circuit needed to drive the stepper motor. It allowed us to learn
how to drive the motor using the L298N H-Bridge Driver and use the
A4988 stepper motor driver as they are crucial components in the
Two-Wheel Balancing Car. To make the car frames, we had to measure
materials to be able to create a two-level structure and had to 3D
print certain parts to hold some of the components. Once we completed
it,
it was time to test the MPU6050 accelerometer/gyroscope sensor to
understand acceleration and angular velocity. We also got to learn
about the importance of a loop time. With that done, we had to debug
the code to interface with our robot so that it would be able to
balance. Throughout this project we had to use a lot of what we learned
throughout the semester to help in making the robot balance. Everything done in this project can be found here.
Materials:
Materials
Quantity
Breadboard
1
Open-Smart Transceiver
1
Arduino Uno
1
A4988 Motor Driver
2
NEMA17 Stepper Motor
2
100 uF Capacitor
1
Lipo Battery
3
MPU6050
1
Lipo Battery Catridge
1
Jumper Cables
Infinity
Acrylic Plastic Platforms
2
Wheels
2
Part 1, Task 5: Test the MPU6050 Accelerometer/Gyroscope Sensor In
Task 1, we looked at the pinout and schematic of the MPU6050 module.
Looking at the schematic of the MPU6050 was important as we had to
implement that design on our PCB as we were expected to attach the
MPU6050 surface mount directly to the PCB. We learned that the MPU6050
operated at a VDD of 2.375V-3.46V and only supported I2C as the serial
interface. Once we had knowledge of the MPU6050, we made simple
hardware connections to test the acceleration and gyroscope readings,
ensuring that when different gestures were performed that the data
represented the gesture correctly. Once completed, we had to place the
MPU module into the breadboard vertically so that the x-axis was
parallel with gravity. If done correctly we should recieve a value that
is somewhere close to 8192 for accel_x from the module but due to
errors it will be off, as seen in Figure 1.
Figure 1. Displaying accel_x when the MPU module is oriented vertically so that the x-axis is parallel to gravity.
Part 1, Task 6: Remove the Offset of the Gyro's Readings In
Task 2, since we noticed that the gyro's readings were not perfectly 0
we needed to add a calibration section in the code to be able to
average out the first 500 readings to calibrate the gyro's readings.
Once implemented, we were able to get an average of the readings that
we could use for calibration, as seen in Figure 2.
Figure 2. Reporting the averaged 'gyro_pitch_calibration_value' to the serial monitor.
Part 1, Task 7: The loop_timer variable In
Task 3, we learned about the importance of the loop_timer variable. To
be able to unify the 'delta_t' of the PID controller of every loop of
the loop(), we needed to add 'loop_timer = micros() +4000 in the setup
function. In the loop function we needed to add a while loop,
'while(micros() < loop_timer)' and inside the while loop function we
needed to add 'loop_timer += 4000'. To be able to understand the
technique of using a loop_timer variable, we needed to put it in use by
using the technique to blink a LED at a frequency of 1Hz, as seen in
Figure 3.
Figure 3. Using the loop_timer technique to blink a LED at 1Hz.
Part 1, Task 8: Angle Calculation In
Task 4, we want to use the MPU to measure the angles by combining
information from the accelerometer and the gyroscope. We was this
functionality so that when the robot leans forward, it should sense the
movement and the robot should react to prevent from tipping and same
goes for it the robot leans backwards. Since the vertical acceleration
is always 1 g, we can use the equation Theta = asin(Accel_Z/1 g) x
57.296 to get a value in degrees. Figure 4 shows the demonstration of the angle calculation through the serial monitor.
Figure 4. Angula calculations shown in the serial monitor.
Part 2, Task 1: Building Prototype In
Task 1, we had to build the frame of the balancing robot. The robot was
build using two acrylic plastic platforms, two motors, a
breadboard, 2 motordrivers, and an Arduino Uno. Figure 5 shows the
completed balancing robot structure. In order to be able to hold many
components on the robot, we had to 3D print some special parts. The
special parts were mounts for the motors, adapters to connect the tires to the motors, and a battery mount.
The top platform housed the Arduino Uno, the breadboard and component
connections, and the 3 cell lipo batter cartridge. The wiring of the
breadboard is shown in Figure 6. The bottom platform housed the two
motors. The platforms were held together using 4 metal rods. The code
was an adaptation of Joop Brookings work, which the previous Robotics
II class had worked on. The code is found here,
The code works on the principal of using an ISR interrupt to allow for
two tasks to be executed at the same time, which is recieving the data
from the MPU6050 and managing the PID controller. Most of the code
doesn't need to be changed except for the 'acc_calibration_value',
which the user must determine, using a program similar to thiswill
help will finding that value. The PID values might need to be
tweaked with depending on the robot. Once all was done the robot was
tested to determine if it could balance. Working with Sophie Turner, we
were able to get our balancing robot to balance, as shown in Figure 7.
Figure 5. Structure of the robot.
Figure 6. Wiring of the breadboard.
Figure 7. Demonstration showing the balancing robot.
Part 2, Task 4: PCB Design, Fabrication, Soldering, and Testing. In
Task 2, we had to design a PCB for the robot that would implement the
circuit built on the breadboard and one for the remote to control the
robot. The PCB was designed using EAGLE, the schematic and BRD files.Instead
of mounting the MPU module directly on the PCB, we were given the
schematic to implement. Figure 8 shows the schematic while Figure 9
shows the BRD file. The final PCB can be seen in Figure 10,
unfortunately we did not have time to implement that on our robot. My
partner for this project Sophie Turner created the schematic for the
controller and the bare PCB can be seen in Figure 11.
Figure 8. Schematic of robot PCB.
Figure 9. BRD of robot PCB.
Figure 10. Finished PCB with all parts soldered on.
Figure 11. Bare controller PCB.
Discussion: By
completing this project, we were able to learn a lot from the
programming portion to the hardware portion. Using a lot of the same
components that we had previously seen before definitely made it a
little easier. Reading through the code provided helped in
understanding what was going on and why certain bits of code were
implemented. Being able to build the robot from scratch was a nice
experience as we got to see the entire process. There were some
frustrating things that happened along the way but it made it all worth
it seeing the robot balance. Overall, this project was good as it
enforced a lot of the topic we had learned throught the course.