yup yup... we're slamming forward with this project!!! i've gotten quite a bit more information:
is the final diagram of the motor controller. i plan on incorporating LEDs in line with each motor lead however to show current, that way, if hte motor isn't turning, and the light is on, i know there's a problem, or that there's at least power there, even if i don't know why its not working
there'll be two of these on this bot. 1 for the legs, 1 for the pan and look up/down servos for the range finder.
Speaking of which, how do i know where the 'home' position is on a servo? is that what the third wire is?
i've started hacking out some code for it, its far from complete:
#include <Servo.h>
//open analog pins - 3 , 5. open digital pins - 8 10 11 12
//declare servos
Servo panhorizontal;
Servo panverticle;
int panhorizontalpos = 0;
int panverticlepos = 0;
//declare 'scan look positions'
int lookleft = 0;
int lookright = 0;
int lookforward = 0;
int lookdown = 1;
//set pins
//analog
int rangesensor = 0;
int motorspeed = 1;
int legpotleftextend = 2;
int legpotrightextend = 4;
//digital
int led1 = 13;
int led2 = 0;
int driveleft1 =1;
int driveleft2 =2;
int driveright1 =4;
int driveright2 =7;
//pwm
int driveleftenable = 3;
int driverightenable = 5;
void setup()
{
Serial.begin(9600); //???
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(driveleft1, OUTPUT);
pinMode(driveleft2, OUTPUT);
pinMode(driveright1, OUTPUT);
pinMode(driveright2, OUTPUT);
//PWM pins
pinMode(driveleftenable, OUTPUT);
pinMode(driverightenable, OUTPUT);
panhorizontal.attach(6);
panverticle.attach(9);
//motortest? via motortest();
}
void loop()
{
scansidetoside();
scandown();
if (lookdown == 1)
{
//turn 180
}
if (lookforward == 1 && lookright == 1 and lookleft == 1)
{
//turn 180
}
if (lookforward == 1 && lookright == 0 && lookleft == 0)
{
//turn right
}
if (lookforward == 1 && lookright == 1 && lookleft == 0)
{
//turn left
}
if (lookforward == 1 && lookleft == 1 && lookright == 0)
{
//turn right
}
//step once on each side
//monitor step pots to ensure no motor jams
}
void takestep(int side, int dir)
{
}
void scansidetoside()
{
for(panhorizontalpos = 0; panhorizontalpos < 90; panhorizontalpos += 1)
{
panhorizontal.write(panhorizontalpos);
delay(15);
}
lookright = scan();
for(panhorizontalpos = 90; panhorizontalpos > -90; panhorizontalpos-=1)
{
panhorizontal.write(panhorizontalpos);
delay(15);
}
lookleft = scan();
for(panhorizontalpos = -90; panhorizontalpos <= 0; panhorizontalpos+=1)
{
panhorizontal.write(panhorizontalpos);
delay(15);
}
lookforward = scan();
}
void scandown()
{
for(panverticlepos = 0; panverticlepos < 45; panhorizontalpos += 1)
{
panverticle.write(panhorizontalpos);
delay(15);
}
lookdown = scan();
for(panverticlepos = 45; panverticlepos > 0; panhorizontalpos -= 1)
{
panverticle.write(panhorizontalpos);
delay(15);
}
}
int scan()
{
//returns a value in cm = closest obstacle
int x = 1;
return x;
}
void turn180(){}
void turnright(){}
void turnleft(){}
void takestep(){}
void motortest(){}
Serial.begin(9600); //??? speaking of which, what is this??? it was in the example that i used to start building on, and i'm not sure what th heck it is.
i'm going ot start programming each of those functions here shortly. prolly have something working in theory by sunday, even though my arduino and prototype shield, motor controllers, and servos won't be here before monday at the soonest.
EDIT - i just found out 1 pwm is all you need for each servo. that just opened up abunch of pins. derp.
Second EDIT - took down my old code and put up the new. yay.