Date: 3/7/23

In this lab we swap the RC car’s motor drivers with our own.

Setup

Here is schematic showing how the connections look from the Artemis to the motor driver, motor, and battery:

image

To connect a motor driver it is important to use analog PWM pins to send power that is not just high or low. I used the schematic in order to figure out which pins were PWM. I decided to use pins A2,A3,A4,and A5 as my motor driver pins. Additionally in order to provide more current to each motor we parallel couple the input and output of the motor driver as seen in the wiring diagram because it is capable of controlling two separate motors.

The motors and the Artemis are powered by separate batteries to avoid EMI issues. By having separate power sourcses we can minimize the noise from the motors and motor drivers to our IMU and ToF sensors.

Lab Tasks

I first initially tested the system by hooking up a power supply set to 3.7 V (the same voltage as the battery) to the VIN and GND pins on each motor controller. I then also connected the output of the motor controller to an oscilloscope to read the signal output. I did this to test if my initial wiring of the motor controllers was accurate on the input side. Here is a snippet of the code I ran to generate the oscilloscope signal

  analogWrite(2, 0);
  analogWrite(3, 75);
  analogWrite(4, 75);
  analogWrite(5, 0);

image image

I then soldered the motor leads onto each motor controller. My next test was to see if I could get the robot to spin on its side. Still using the power supply I tested rotating each side of the wheels using the same code as before. I also tested going clockwise and counterclockwise with the motors. To accomplish that in the program I just changed which pin I was writing to. So I executed the previous code or this code to test.

  analogWrite(2, 75);
  analogWrite(3, 0);
  analogWrite(4, 0);
  analogWrite(5, 75);

My next step was soldering the battery onto the power connections for the motor controller to run both of the motors at once without the power supply. I executed both of the previous code snippets to get the following result. The right set of wheels were spinning slower but that was not an actual issue with the motors that was just due to a low PWM value.

With all the connections confirmed working I now focused on securing all the components adequately to the car. The following diagram shows how I secured the components and where I placed all the different sensors/controllers.

image

Next I experimentally tested to find the dead band in PWM for my motors. Through incrementing through different values I found the dead band for my motor.

  analogWrite(2, 0); // LEFT
  analogWrite(3, 39);
  analogWrite(4, 28);//RIGHT
  analogWrite(5, 0);

The motor driving the left wheels had a higher minimum PWM at 39 compared to the right motor at 28. Here is a video showing the motor stalling.

I found that the minimum power to drive forward was 43 PWM to each motor.

The minimum PWM to rotate was 190 PWM

Next I placed the motor on the ground to see if any motor calibration was needed. I initially believed due to the different dead bands for each motor I would require some calibration factor however after testing I discovered it was not needed. In the below video you can see the car veers off slightly towards the end. The reason for that is not a motor miscalibration but instead a flooring issue. The tile it drove over is slightly raised and not level with the previous tiles causing the car to veer slightly. You can see in the video the car is still over the center line.

Next I put a series of commands together to demonstrate the robot was capable of making multiple moves. Here are the commands:

 // MOVE FORWARD
  analogWrite(2, 0);
  analogWrite(3, 75);
  analogWrite(4, 75);
  analogWrite(5, 0);
  delay(2000);
  // TURN
  analogWrite(2, 0);
  analogWrite(3, 190);
  analogWrite(4, 0);
  analogWrite(5, 190);
  delay(1500);
  // MOVE BACKWARD
  analogWrite(2, 75);
  analogWrite(3, 0);
  analogWrite(4, 0);
  analogWrite(5, 75);
  delay(1000);
  //TURN
  analogWrite(2, 0);
  analogWrite(3, 190);
  analogWrite(4, 0);
  analogWrite(5, 190);
  delay(1500);
  //MOVE FORWARD
  analogWrite(2, 0);
  analogWrite(3, 75);
  analogWrite(4, 75);
  analogWrite(5, 0);
  delay(1000);
  //STOP
  analogWrite(2, 0);
  analogWrite(3, 0);
  analogWrite(4, 0);
  analogWrite(5, 0);

The following video shows the results of these commands