Tutorials/Arduino Projects/RC car Hacking Project/Controlling the motors
(→Testing) |
|||
| (4 intermediate revisions by one user not shown) | |||
| Line 9: | Line 9: | ||
{| align="center" | {| align="center" | ||
|- | |- | ||
| − | [[image:Interceptor_Arduino_Power_Diagram.png|thumb|c|center|400px|Treat the AAA battery holder as a stand-in for the vehicle's battery pack.]]|| | + | | [[image:Interceptor_Arduino_Power_Diagram.png|thumb|c|center|400px|Treat the AAA battery holder as a stand-in for the vehicle's battery pack.]]|| |
[[image:Gymkhana_Arduino_Power_Diagram.png|thumb|c|center|400px|Treat the 9V battery holder as a stand-in for the vehicle's batteries.]] | [[image:Gymkhana_Arduino_Power_Diagram.png|thumb|c|center|400px|Treat the 9V battery holder as a stand-in for the vehicle's batteries.]] | ||
|} | |} | ||
| Line 36: | Line 36: | ||
{| align="center" | {| align="center" | ||
|- | |- | ||
| − | [[image:Interceptor_Motor_Wiring_Schematic.png|thumb|c|center|400px|Wiring schematic.]] || | + | | [[image:Interceptor_Motor_Wiring_Schematic.png|thumb|c|center|400px|Interceptor Wiring schematic.]] || |
| − | [[image:Gymkhana_Motor_Wiring_Schematic.png|thumb|c|center|400px|Wiring schematic.]] | + | [[image:Gymkhana_Motor_Wiring_Schematic.png|thumb|c|center|400px|Gymkhana Wiring schematic.]] |
|} | |} | ||
{| align="center" | {| align="center" | ||
|- | |- | ||
| − | [[image:Interceptor_Motor_Wiring_Virtual_Breadboard.png|thumb|c|center|400px|Virtual breadboard diagram.]] || | + | | [[image:Interceptor_Motor_Wiring_Virtual_Breadboard.png|thumb|c|center|400px|Interceptor Virtual breadboard diagram.]] || |
| − | [[image:Gymkhana_Motor_Wiring_Virtual_Breadboard.png|thumb|c|center|400px|Virtual breadboard diagram.]] | + | [[image:Gymkhana_Motor_Wiring_Virtual_Breadboard.png|thumb|c|center|400px|Gymkhana Virtual breadboard diagram.]] |
|} | |} | ||
| − | |||
==Testing== | ==Testing== | ||
| Line 60: | Line 59: | ||
#pragma config(CircuitBoardType, typeCktBoardUNO) | #pragma config(CircuitBoardType, typeCktBoardUNO) | ||
#pragma config(UART_Usage, UART0, uartSystemCommPort, baudRate200000, IOPins, dgtl1, dgtl0) | #pragma config(UART_Usage, UART0, uartSystemCommPort, baudRate200000, IOPins, dgtl1, dgtl0) | ||
| − | #pragma config(Motor, | + | #pragma config(Motor, servo_9, driveMotor, tmotorServoContinuousRotation, openLoop, IOPins, dgtl9, None) |
| − | #pragma config(Motor, | + | #pragma config(Motor, servo_10, steerMotor, tmotorServoContinuousRotation, openLoop, IOPins, dgtl10, None) |
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// | ||
| Line 71: | Line 70: | ||
motor[driveMotor] = 100; | motor[driveMotor] = 100; | ||
wait1Msec(2000); | wait1Msec(2000); | ||
| + | motor[steerMotor] = 0; | ||
| + | motor[driveMotor] = 0; | ||
| + | wait1Msec(500); | ||
motor[steerMotor] = -127; | motor[steerMotor] = -127; | ||
motor[driveMotor] = -100; | motor[driveMotor] = -100; | ||
wait1Msec(2000); | wait1Msec(2000); | ||
| + | motor[steerMotor] = 0; | ||
| + | motor[driveMotor] = 0; | ||
| + | wait1Msec(500); | ||
} | } | ||
} | } | ||
Latest revision as of 14:02, 11 July 2012
Contents |
Interfacing the Arduino
The first thing we need to do before we can connect the motors is power the Arduino. To power the Arduino from the RC car power supply using the wires we soldered earlier, we will use the Arduino's 'Vin' pin which allows it to be powered from an external source without using the power plug.
Set the circuit up like the diagram below. We use the breadboard as we will need the raw battery power supply later to power the motors.
Turn the car on and you should see the Arduino power up.
Connecting the motors
Motor controllers
DC motors cannot be directly controlled by the Arduino - we will need an external motor controller to allow speed regulation as well as forwards/backwards control. These controllers all use the same fundamental concept - the H-bridge. This will use the PWM signal and convert it into useful DC motor commands.
Thankfully, VEX robotics has recently released the Motor Controller 29 - a nifty, compact motor controller to use with their new line of 2-wire motors. Fortunately for us, this is a controller that will work perfectly with our DC motors.
Another option for a motor controller is an Arduino Shield such as the Ardumoto from Sparkfun. This acts as a shield for the Arduino which lets you control up to 2 DC motors - perfect for our purposes.
Wiring
The wiring is pretty simple, nothing fancy. The signal cables should go to digital ports 9 and 10. Port 9 should be the Drive motor and port 10 should be the Steering motor. Keep in mind, we are powering the motor controllers straight from the battery and not from the Arduino 5V - the motors draw too much current otherwise.
Testing
NOTE: If you are using the Gymkhana or a similar vehicle with turn regulation, skip this next section.
To test the motors, we are going to write a simple program for the Arduino. First, configure the motors as Continuous Rotation Servos driveMotor (motor_5) and steerMotor(motor_6). While the motors are not actually servos, the Arduino needs to think they are for the motor controllers to work properly.
Let's make the car move forward turning one direction, then backward turning the other. This means the vehicle will end up amusing us by essentially trying to do an infinite-point turn.
#pragma config(CircuitBoardType, typeCktBoardUNO) #pragma config(UART_Usage, UART0, uartSystemCommPort, baudRate200000, IOPins, dgtl1, dgtl0) #pragma config(Motor, servo_9, driveMotor, tmotorServoContinuousRotation, openLoop, IOPins, dgtl9, None) #pragma config(Motor, servo_10, steerMotor, tmotorServoContinuousRotation, openLoop, IOPins, dgtl10, None) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*// task main() { while(true) { motor[steerMotor] = 127; motor[driveMotor] = 100; wait1Msec(2000); motor[steerMotor] = 0; motor[driveMotor] = 0; wait1Msec(500); motor[steerMotor] = -127; motor[driveMotor] = -100; wait1Msec(2000); motor[steerMotor] = 0; motor[driveMotor] = 0; wait1Msec(500); } } |
Run this out in an open area and watch the car control itself.