Hi this is my first project,
I started with and ebay found transit damaged 1/24 rc tank and due to no glue on the joints had dissasembled in transit. And for the electronics i dicied upon a DFRobot MEGA, motor shield, and io expantion shield.
That got me so far as this was my first time using the arduino and in fact any microcontroller, with many nights spent trawling through code
adding bump sensors, leds and an arm fasioned from foamex i hit a wall so i headed over to ebay and bought myself 2 ultrasonic sensors and a 16x2 lcd, I finally got to a stage that i was happy with then **** broken track, so i made a quick bodge (staples and superglue) it worked but it took adjusting the motor speed to counteract the drift, then i encountered "cellbots" and the "robots anywhere" system, time for a change whch i will be documenting, more on it at the end of the post.
Anyway enough with the chat heres the code from it:
//
//
// Tank bot work in progress 30/12/10 version 0.4:
// by Overclock
#include "Ultrasonic.h"
#include <Servo.h>
//turret and servo(s)
Ultrasonic ultrasonic (11,12);
Servo scanservo;
long LDistance = 0;
long RDistance = 0;
//motor pins and reverse
const int RTMPin = 5 ;
const int RTRPin = 4 ;
const int LTMPin = 6 ;
const int LTRPin = 7 ;
int val = 0;
// timers
long scantimer = 1000;
unsigned long currentmillis = 0;
unsigned long previousmillis = 0;
/////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
pinMode (RTMPin, OUTPUT);
pinMode (RTRPin, OUTPUT);
pinMode (LTMPin, OUTPUT);
pinMode (LTRPin, OUTPUT);
scanservo.attach(9);
}
//////////////////////////////////////////////////////////////
void loop()
{
val = map (ultrasonic.Ranging(CM),0 ,60, 0, 255); //map 0-60 cm to 0-255 in order to enable more control and to bring the bot to a controlled stop
if (ultrasonic.Ranging(CM)<10) { // switch condition reads ranging ditance
// checks if Us reads lower than 10cm
analogWrite (RTMPin, 0); //stop
analogWrite (LTMPin, 0);
digitalWrite (RTRPin, LOW);
digitalWrite (LTRPin, LOW);
scanservo.write(0); // scan servo left
delay(150);
LDistance = ultrasonic.Ranging(CM); // read out dist into "LDistance"
delay(1000);
scanservo.write(180); // scan servo right
delay(150);
RDistance = ultrasonic.Ranging(CM); // read out dist into RDistance
delay(1000);
scanservo.write(90); // center servo
if (LDistance<RDistance){ // decides if left distance is larger than right distance
analogWrite (RTMPin, 100); // then reverses and makes a turn
analogWrite (LTMPin, 100); // 70% sucess rate
digitalWrite (RTRPin, HIGH);
digitalWrite (LTRPin, HIGH);
delay(750);
analogWrite (RTMPin, 100);
analogWrite (LTMPin, 100);
digitalWrite (RTRPin, HIGH);
digitalWrite (LTRPin, LOW);
delay(1000);
}
else{
analogWrite (RTMPin, 100);
analogWrite (LTMPin, 100);
digitalWrite (RTRPin, HIGH);
digitalWrite (LTRPin, HIGH);
delay(750);
analogWrite (RTMPin, 100);
analogWrite (LTMPin, 100);
digitalWrite (RTRPin, LOW);
digitalWrite (LTRPin, HIGH);
delay(1000);
}
}
else { // normal conditions
scanservo.write(90);
analogWrite (RTMPin, constrain (val, 50, 255)); //
analogWrite (LTMPin, constrain (val, 50, 255));
digitalWrite (RTRPin, LOW);
digitalWrite (LTRPin, LOW);
}
Serial.print("sensor = " );
Serial.print(ultrasonic.Ranging(CM));
Serial.print("\t output = ");
Serial.println(val);
}
Next time, 1/12 scale, bb firing 2 foot monster.
What we want to see:
motor encoders (turret and tracks)
various sensors
2nd arduino to read sensor values and to offlload calculations
android phone for the remote video and control link!! dell streak ;D
laser targeting, with rangefinding and auto aim (distance compensation)
deployable arms
ability to recharge remote
remote PC (brain) with dedicated software (mapping, vision, ect.)
some huge destruction when it decides humans are its enemy
Lets get some more bots built its easier than you think!!