RC Tank

This is an Rc tank controlled by a Ps2 controller.

Engineer

Jake C

Area of Interest

Explosives Engineering/ Mechanical Engineering/ Electrical Engineering/  Finance

School

S.A.R. High School

Grade

Incoming Junior

Second Milestone

For my second milestone, I had to finish the main project, this meant I had to get the 3 main electronic components of the tank done. They where: the ps2 receiver, the motor driver, and the Arduino.  The ps2 receiver is what allows me to use the ps2 controller to connect the Arduino and thus the motor driver. The ps2 controller has 9 total pins but only 6 are needed, the pins are in no particular order, clock, data, command, power, ground, and attention. Clock and data send information from the master device to the slave, in this case, the master device is the ps2 controller and the slave is the ps2 receiver and by extension the Arduino. Command is what the ps2 receiver uses to communicate with the master device. Power and ground are connected in the usual manner. Finally, attention is what the master uses to tell the slave that it is active.  The motor driver is, in essence, an H bridge. an H bridge allows current to be sent in the opposite direction or flip the polarity. This allows you to reverse the direction of a DC motor, this allows me to turn the tank.  The Arduino is the “brains” of the tank its purpose is to take the ps2 receivers outputs and turn them into inputs for the H bridge this then send current to the motors, thus allowing the tank to move.

click to show code
the red section of the code is the aspect that interacts with the motors and ps2 receiver
#include <L298N.h>
#define ENa 10
#define IN1 9
#define IN2 8
#define ENB 5
#define IN3 7
#define IN4 6
L298N motor1(ENa, IN1, IN2);
L298N motor2(ENB, IN3, IN4);
#include <PS2X_lib.h>  //for v1.6
PS2X ps2x; // create PS2 Controller Class
//right now, the library does NOT support hot pluggable controllers, meaning
//you must always either restart your Arduino after you conect the controller,
//or call config_gamepad(pins) again after connecting the controller.
int error = 0;
byte type = 0;
byte vibrate = 0;
void setup() {
Serial.begin(57600);
motor1.setSpeed(255); // an integer between 0 and 255
motor2.setSpeed(255); // an integer between 0 and 25
//CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************
  error = ps2x.config_gamepad(13, 11, 4, 12, true, true); //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
  if (error == 0) {
Serial.println(“Found Controller, configured successful”);
Serial.println(“Try out all the buttons, X will vibrate the controller, faster as you press harder;”);
Serial.println(“holding L1 or R1 will print out the analog stick values.”);
Serial.println(“Go to www.billporter.info for updates and to report bugs.”);
}
  else if (error == 1)
Serial.println(“No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips”);
  else if (error == 2)
Serial.println(“Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips”);
  else if (error == 3)
Serial.println(“Controller refusing to enter Pressures mode, may not support it. “);
  //Serial.print(ps2x.Analog(1), HEX);
  type = ps2x.readType();
switch (type) {
case 0:
Serial.println(“Unknown Controller type”);
break;
case 1:
Serial.println(“DualShock Controller Found”);
break;
case 2:
Serial.println(“GuitarHero Controller Found”);
break;
}
}
void loop() {
  /* You must Read Gamepad to get new values
Read GamePad and set vibration values
ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255)
if you don’t enable the rumble, use ps2x.read_gamepad(); with no values
    you should call this at least once a second
*/
  if (error == 1) //skip loop if no controller found
return;
  if (type == 2) { //Guitar Hero Controller
    ps2x.read_gamepad();          //read controller
    //  if (ps2x.ButtonPressed(GREEN_FRET))
Serial.println(“Green Fret Pressed”);
if (ps2x.ButtonPressed(RED_FRET))
Serial.println(“Red Fret Pressed”);
if (ps2x.ButtonPressed(YELLOW_FRET))
Serial.println(“Yellow Fret Pressed”);
if (ps2x.ButtonPressed(BLUE_FRET))
Serial.println(“Blue Fret Pressed”);
if (ps2x.ButtonPressed(ORANGE_FRET))
Serial.println(“Orange Fret Pressed”);
if (ps2x.ButtonPressed(STAR_POWER))
Serial.println(“Star Power Command”);
    if (ps2x.Button(UP_STRUM))         //will be TRUE as long as button is pressed
Serial.println(“Up Strum”);
if (ps2x.Button(DOWN_STRUM))
Serial.println(“DOWN Strum”);
if (ps2x.Button(PSB_START))                  //will be TRUE as long as button is pressed
Serial.println(“Start is being held”);
if (ps2x.Button(PSB_SELECT))
Serial.println(“Select is being held”);
if (ps2x.Button(ORANGE_FRET)) // print stick value IF TRUE
{
Serial.print(“Wammy Bar Position:”);
Serial.println(ps2x.Analog(WHAMMY_BAR), DEC);
}
}
  else { //DualShock Controller
    ps2x.read_gamepad(false, vibrate);          //read controller and set large motor to spin at ‘vibrate’ speed
    if (ps2x.Button(PSB_START))                  //will be TRUE as long as button is pressed
Serial.println(“Start is being held”);
if (ps2x.Button(PSB_SELECT))
Serial.println(“Select is being held”);
if (ps2x.Button(PSB_PAD_UP)) {        //will be TRUE as long as button is pressed
Serial.print(“Up held this hard: “);
Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);
}
if (ps2x.Button(PSB_PAD_RIGHT)) {
Serial.println(“Right held this hard: “);
Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);
}
if (ps2x.Button(PSB_PAD_LEFT)) {
Serial.println(“LEFT held this hard: “);
Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);
}
if (ps2x.Button(PSB_PAD_DOWN)) {
Serial.print(“DOWN held this hard: “);
Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);
}
vibrate = ps2x.Analog(PSAB_BLUE);        //this will set the large motor vibrate speed based on
//how hard you press the blue (X) button
    if (ps2x.NewButtonState())               //will be TRUE if any button changes state (on to off, or off to on)
{
      if (ps2x.ButtonPressed(PSB_L2)) {
Serial.println(“L2 pressed”);
motor2.forward();
Serial.println(“motor go”);
}
if (ps2x.ButtonPressed(PSB_R2 )) {
Serial.println(“R2 pressed”);
motor1.forward();
Serial.println(“motor go”);
}
if (ps2x.ButtonReleased(PSB_R2 )) {
motor1.stop();
Serial.println(“motor stop”);
}
if (ps2x.ButtonReleased(PSB_L2 )) {
motor2.stop();
Serial.println(“motor stop”);
}
if (ps2x.ButtonPressed(PSB_L1)) {
motor2.backward();
Serial.println(“motor go”);
}
if (ps2x.ButtonPressed(PSB_R1)) {
motor1.backward();
Serial.println(“motor go”);
}
if (ps2x.ButtonReleased(PSB_L1)) {
motor2.stop();
Serial.println(“motor stop”);
}
if (ps2x.ButtonReleased(PSB_R1)) {
motor1.stop();
Serial.println(“motor stop”);
}
delay(50);
}

First Milestone

My first milestone was to be able to power the motors by the battery.  To do this I had to make 3 main subassemblies, the gearbox, the chassis, and the wheels.  The most complex part was the gearbox this was due to many different ways to build it. The variant I chose to build was variant C this gave me rpm  114.7 which gives me 115 rpm and 809-gram force cm.  This is fairly in the middle in terms of both torque and rpm this will allow me to add more attachments later as I could still have enough torque to move the tank. The other parts where simple to assemble. Below are images of the tank

rc tank

Hover Box Element

this is the main subassemblies of the tank are the chassis, wheels and the gearbox. the wheels are the orange wheels the chassis is the tan plate that everything is attached to. finally, the gearbox is the grey box with blue and yellow gears inside.

Starter Project

my starter project is the useless machine, a machine that turns itself off when you turn it on.  It is composed of 3 main subassemblies: the outer box, the motor and arm, and the PCB. The box is made out of black acrylic and has a flap for the motor am to go out of.

I faced a few challenges while building the starter project, the biggest one I faced was that I soldered the main switch on an angle that would not allow the arm to interface with the switch. To rectify the mistake I had to desolder and then resolder the switch into the correct position.

Below is a schematic of the circuit for the Useless machine.

link to the instructions: http://www.spikenzielabs.com/Downloadables/uselessmachine/Useless-Machine-Soldering-Edition.pdf

The images below are of the internals of the useless machine. they are composed of, the motor and the PCB. the motor is the main moving part of the machine. the PCB is what controls the motor. The PCB is composed of 2 switches 2resistors a 3 pin led and screw terminals. The main switch on the top is what activates the device. when the switch is flipped the motor is activated as well as the led. this causes the arm to turn and the led to turn green when the arm flips the switch on the top of the machine 2 things happen. First, the polarity on the motor is reversed this causes the arm to spin backward.  Secondly, Power is routed from the green anode to the red anode on the led. finally, to stop the motor for going back too far there is a second switch to kill the whole circuit and for the cycle to start anew.

STEM Classes For Kids in New York
STEM Classes For Kids in New York

Start typing and press Enter to search