Robot Update – #1

So my new 24V-12V converter arrived, allowing me to make some upgrades to my robot.

 

New power supply for Wifi router and Nerf gun

The new power supply is a 24v-12v converter I got off eBay for a few dollars, which has enough capacity to power both the Wifi converter and Nerf Stampede without any problems. I may have discussed it previously, but I have a 24v -5v converter to power the arduino and peripherals.

You can see in this photo, I actually cut short lengths off a Wall Plug (the type that you’d use for putting screws into masonry), and used it as spacers to keep the converter off the metal housing. The 5V converter came with nice brass spacers, but I thought this was a suitable fix for the 12V converter.

20131031_124815

 

LCD panel displaying robot vital statistics

Nifty little LCD display panel that displays the IP address and Port of my robot (in case I forget what settings I put in the arduino code), as well as displaying any error messages (such as when it is unable to connect, or the kill switch is depressed). You can see in the photos below that I have put a potentiometer in to control contrast on the screen, but this could’ve been taken care of using a fixed voltage divider, if I’d wanted to.

20131031_150548 20131031_150558

MAP function

Used to turn signals from game controller app into signals to wheelchair controller (instead of previous step increment code). See code below. I originally hadn’t done this because of some weird drift in the PWM set points, but I took some measurements to confirm that it would work, and it gives much better fine control over the robot’s movements.

Laser sight added for nerf gun

For awesomeness. see http://www.thingiverse.com/thing:172903

20131025_114239 20131031_212242

Nerf gun temporarily mounted on robot

I will print a better mount (possibly actuated for the hell of it), but for now I’ve cable tied it to some existing structure. see below.

20131031_212024

Robot fore-aft axis inverted

To allow for nerf gun configuration. Because the ammo drum sticks out on the left side of the gun, and the structure that I was tying the gun to is on the right side of the wheelchair, it had to be mounted in reverse configuration (as those familiar with power chairs can see from the following photos). Because of this I inverted the Forwards and Backwards signals, so that it runs normally. This is noted in the code below.

20131031_211958 20131031_212254

While I was doing all of this, I tidied up the wiring and gave everything a good clean. In testing, everything worked flawlessly. Unfortunately we were out for dinner, so I couldn’t chase the neighbour kids with it when they were going around trick-or-treating. Next year, neighbour kids…

I’ll upload some videos of it operating tomorrow. It moves me deeply, seeing it operate… the starus lights come on one at a time, the calming blue glow of the LCD balanced by that little angry red dot that alights everything that’s about to get shot…

Some people look at me funny when I describe a piece of machinery, code or maths as “sexy”. I don’t mean sexy like THAT, but it’s a feeling that I think only an enthusiastic technically minded person can understand…

 

 

Maybe I’ll modify the nerf darts for greater power and range, too. How much power do I need? my answer, as always: just a little bit more.

 

 

 

 

LATEST CODE:

//!!!!! DEFINE NETWORK STUFF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008
#include <LiquidCrystal.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress ip(10, 1, 1, 177);
unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

//!!!!! END DEFINE NETWORK STUFF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//!!!!! DEFINE ROBOT STUFF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//define variables here
int ledPin = 13;
int val = -1;
int vX;
int vY;
int vF;

int Fore_PWM = 4;
int Aft_PWM = 5;
int Left_PWM = 7;
int Right_PWM = 6;

int kill_switch = 24; //pin for kill switch, normally high to robot to run.
int Fire_OUT = 22; //+5v to transistor on low side of nerf trigger bypass relay. BC337 used. pins, left to right when looking from flat face, are Collector (low side of relay), Base (5V signal), Emitter (ground)

int Fire_IN = 23;
int Fore_IN = A1;
int Left_IN = A2;

int fore_range = A3; //rangefinders. yet to be installed and coded.
int aft_range=A4;
int left_range=A5;
int right_range = A6;

//int Manual_IN=28; //switch for manual control. closed circuit for manual

int LCD_d4 = 30;
int LCD_d5 = 32;
int LCD_d6 = 34;
int LCD_d7 = 36;
int LCD_RS = 31;
int LCD_E = 33;

LiquidCrystal lcd(LCD_RS, LCD_E, LCD_d4, LCD_d5, LCD_d6, LCD_d7);

int AnalogLower = 0;
int AnalogUpper = 1023;
int PWMLower = 0;
int PWMUpper = 255;
int VoltsLower = 0;
int VoltsUpper = 500;

int JazzyUpper3   = 202;
int JazzyUpper2   = 177;
int JazzyUpper1   = 151;
int JazzyNeutral = 127;
int JazzyLower1   = 101;
int JazzyLower2   = 77;
int JazzyLower3   = 51;

//int JazzyUpper3   = 212;
//int JazzyUpper2   = 186;
//int JazzyUpper1   = 160;
//int JazzyNeutral = 135;
//int JazzyLower1   = 108;
//int JazzyLower2   = 82;
//int JazzyLower3   = 57;

unsigned long lastTick=millis();
String Temp = “”;

//!!!!! END DEFINE ROBOT STUFF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//!!!!! DEFINE IPGAMEPAD STUFF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const int PACKET_SIZE = 4; //Size of the joystick data packet
byte joystick_data[PACKET_SIZE]; //Byte array for incoming data – [0] = leftUP, [1] = leftRIGHT, [2] = rightUP, [3] = rightRIGHT

int gamepadUpper3   = 219;
int gamepadUpper2   = 182;
int gamepadUpper1   = 145;
int gamepadLower1   = 111;
int gamepadLower2   = 74;
int gamepadLower3   = 37;

//!!!!! END DEFINE IPGAMEPAD STUFF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

void setup() {

lcd.begin(20,4);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Robot Initialised”);

//!!!!! SETUP NETWORK STUFF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Ethernet.begin(mac,ip);

Serial.begin(9600);

Serial.println(Ethernet.localIP());
Serial.println(localPort);
Serial.println(“Robot control system initialized.”);

while (Ethernet.localIP() != ip){
lcd.setCursor(0, 1);
lcd.print(“Connecting “);
lcd.print(millis()/1000);
lcd.setCursor(0, 2);
lcd.print(“IP: “);
lcd.print(Ethernet.localIP());

delay(1000);

Ethernet.begin(mac,ip);
}

Udp.begin(localPort);

lcd.setCursor(0, 1);
lcd.print(“IP: “);
lcd.print(Ethernet.localIP());

lcd.setCursor(0, 2);
lcd.print(“Port: “);
lcd.print(localPort);

lcd.setCursor(0, 3);
lcd.print(“F:”);
lcd.print(0);

lcd.setCursor(7, 3);
lcd.print(“,R:”);
lcd.print(0);

lcd.setCursor(14, 3);
lcd.print(“,F:”);
lcd.print(“N”);

String inData = “”;
//!!!!! END SETUP NETWORK STUFF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//!!!!! SETUP ROBOT STUFF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
pinMode(ledPin,OUTPUT);

pinMode(Fire_OUT, OUTPUT);
digitalWrite(Fire_OUT,LOW);

pinMode(Fire_IN,INPUT);
pinMode(Fore_IN,INPUT);
pinMode(Left_IN,INPUT);
pinMode(kill_switch,INPUT);
//pinMode(Manual_IN,INPUT);

pinMode(Fore_PWM, OUTPUT); // sets the pin as output
analogWrite(Fore_PWM, JazzyNeutral); //sets reference voltage level= 125

pinMode(Aft_PWM, OUTPUT); // sets the pin as output
analogWrite(Aft_PWM, JazzyNeutral); //sets reference voltage level = 125

pinMode(Left_PWM, OUTPUT); // sets the pin as output
analogWrite(Left_PWM, JazzyNeutral); //sets reference voltage level= 125

pinMode(Right_PWM, OUTPUT); // sets the pin as output
analogWrite(Right_PWM, JazzyNeutral); //sets reference voltage level= 125

lastTick = millis();
//!!!!! END SETUP ROBOT STUFF !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

}

void loop() {

//    if (digitalRead(Manual_IN)==HIGH)
//  {
//    analogWrite(Fore_PWM, map(analogRead(Fore_IN), AnalogLower, AnalogUpper, PWMLower, PWMUpper));
//    analogWrite(Aft_PWM, map((256-analogRead(Fore_IN)), AnalogLower, AnalogUpper, PWMLower, PWMUpper));
//    analogWrite(Left_PWM, map(analogRead(Left_IN), AnalogLower, AnalogUpper, PWMLower, PWMUpper));
//    analogWrite(Right_PWM, map((256-analogRead(Left_IN)), AnalogLower, AnalogUpper, PWMLower, PWMUpper));
//
//  }

if (millis()-lastTick>100){
timeout();
}

// if there’s data available, read a packet

int packetSize = Udp.parsePacket();
if(packetSize)
{
Udp.read(joystick_data, PACKET_SIZE); //read data into joystick_data array
//     Serial.println(“Contents:”);
//     Serial.println(“jostick_data[]: “);
//     Serial.println(joystick_data[0]);
//     Serial.println(joystick_data[1]);
//     Serial.println(joystick_data[2]);
//     Serial.println(joystick_data[3]);

lastTick = millis();

vY=(long)joystick_data[0];
vX=(long)joystick_data[1];
vF=(long)joystick_data[2];

// !!!!!  DATA USE HERE   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

if (digitalRead(kill_switch)==HIGH)//check for kill switch not hit (normally closed circuit, i.e. high), if not, deactivate robot
{

//CODE FOR COMMAND HERE!!!!!

analogWrite(Right_PWM,map(vX,0,255,51,202));
analogWrite(Left_PWM,map(vX,0,255,202,51));

analogWrite(Aft_PWM,map(vY,0,255,51,202)); //NOTE: this has beed reversed for current revision, as robot nerf gun is facing backwards, so the robot now runs backwards
analogWrite(Fore_PWM,map(vY,0,255,202,51)); //NOTE: this has beed reversed for current revision, as robot nerf gun is facing backwards, so the robot now runs backwards

lcd.setCursor(0, 3);
lcd.print(“F:    “);
lcd.setCursor(2, 3);
lcd.print(128-vY); //NOTE: this has beed reversed for current revision, as robot nerf gun is facing backwards, so the robot now runs backwards

lcd.setCursor(7, 3);
lcd.print(“,R:    “);
lcd.setCursor(10, 3);
lcd.print(vX-128);

lcd.setCursor(14, 3);
lcd.print(“,F: “);

if (vF>gamepadUpper3)
{
//code here
digitalWrite(Fire_OUT,HIGH);
lcd.setCursor(17, 3);
lcd.print(“Y”);
}
else
{
//code here
digitalWrite(Fire_OUT,LOW);
lcd.setCursor(17, 3);
lcd.print(“N”);
}

}
else
{
kill();
}

// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

}
delay(10);
}

void kill(){
lcd.setCursor(0, 3);
lcd.print(”                    “);
lcd.setCursor(0, 3);
lcd.print(“kill switch hit”);
Serial.println(“kill switch hit”);
digitalWrite(Fire_OUT,LOW);
analogWrite(Fore_PWM, JazzyNeutral); //sets reference voltage level= 125
analogWrite(Aft_PWM, JazzyNeutral); //sets reference voltage level = 125
analogWrite(Left_PWM, JazzyNeutral); //sets reference voltage level= 125
analogWrite(Right_PWM, JazzyNeutral); //sets reference voltage level= 125
}

void timeout(){
digitalWrite(Fire_OUT,LOW);
analogWrite(Fore_PWM, JazzyNeutral); //sets reference voltage level= 125
analogWrite(Aft_PWM, JazzyNeutral); //sets reference voltage level = 125
analogWrite(Left_PWM, JazzyNeutral); //sets reference voltage level= 125
analogWrite(Right_PWM, JazzyNeutral); //sets reference voltage level= 125

lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Robot Initialised”);

lcd.setCursor(0, 1);
lcd.print(“IP: “);
lcd.print(Ethernet.localIP());

lcd.setCursor(0, 2);
lcd.print(“Port: “);
lcd.print(localPort);

lcd.setCursor(0, 3);
lcd.print(“F:”);
lcd.print(0);

lcd.setCursor(7, 3);
lcd.print(“,R:”);
lcd.print(0);

lcd.setCursor(14, 3);
lcd.print(“,F:”);
lcd.print(“N”);

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s