Post by jaros on Oct 29, 2016 20:25:41 GMT -8
This project is the first programming I've ever done, and I'm doing it all as part of a class. We've built the bot to where it can use the motors, but haven't yet mounted the ultrasonic sensors. Our current assignment is to make a 10inx10in square inside of a 24x24 square, and modify the MotorTest sample code (given on the site) to send the bot around in between the circles. Basically, we're just adjusting the speeds and delay times to put the bot on the right track.
My problem is that, with the same consistent code, the pi-bot will go at different speeds every time it runs, and typically slows down while it's running. My hunch is that this is a mechanical, not coding, problem. I've put extra grease in the gears, changed the batteries several times, and checked and rechecked the wires and parts. The only thing I could find was that a piece in the gearbox had come loose, but even after fixing that, the problem persists. The only thing that seems to work is when I pull out the wires and put them back in - so that's probably where the problem lies, I just don't know what it is. It can't be the surface the bot is on, which is concrete.
I've spent the last 8 hours changing speed values and delay times, checking the setup, replacing batteries, and pulling out wires and putting them back in. No dice.
Any suggestions? Please help
Here's the Arduino code I'm currently working with. Note that I'm constantly changing the speed and delay values to try to get it to work. Also note that the comments aren't all mine, and I've modified the code without actually changing all the comments, so they're not all accurate.
My problem is that, with the same consistent code, the pi-bot will go at different speeds every time it runs, and typically slows down while it's running. My hunch is that this is a mechanical, not coding, problem. I've put extra grease in the gears, changed the batteries several times, and checked and rechecked the wires and parts. The only thing I could find was that a piece in the gearbox had come loose, but even after fixing that, the problem persists. The only thing that seems to work is when I pull out the wires and put them back in - so that's probably where the problem lies, I just don't know what it is. It can't be the surface the bot is on, which is concrete.
I've spent the last 8 hours changing speed values and delay times, checking the setup, replacing batteries, and pulling out wires and putting them back in. No dice.
Any suggestions? Please help
Here's the Arduino code I'm currently working with. Note that I'm constantly changing the speed and delay values to try to get it to work. Also note that the comments aren't all mine, and I've modified the code without actually changing all the comments, so they're not all accurate.
const int In1 = 3;
const int In2 = 5;
const int In3 = 6;
const int In4 = 11;
void setup()
{
// initialize the pins as output:
pinMode(In1, OUTPUT);
// left, forward
pinMode(In2, OUTPUT);
// left, backward
pinMode(In3, OUTPUT);
// right, forward
pinMode(In4, OUTPUT);
// right, backward
}
void loop()
{
int speed1;
int speed2;
int speed3;
int speed4;
// speed1 and speed2 are two variables
// You can change these values from 0 to 255
// We will use 150 for now
// use for left wheel linear
speed1 = 255;
//use for right wheel linear
speed2 = 255;
// use for left wheel turn
speed3 = 220;
// use for right wheel turn
speed4 = 220;
while(1==1)
{
//STOP
analogWrite(In4, 0);
analogWrite(In3, 0);
analogWrite(In2, 0);
analogWrite(In1, 0);
delay(1000);
//Go Forward
analogWrite(In4, 0);
analogWrite(In3, speed2);
analogWrite(In2, 0);
analogWrite(In1, speed1);
delay(1300);
//STOP
analogWrite(In4, 0);
analogWrite(In3, 0);
analogWrite(In2, 0);
analogWrite(In1, 0);
delay(1000);
//TURN
analogWrite(In4, speed3);
analogWrite(In3, 0);
analogWrite(In2, 0);
analogWrite(In1, speed4);
delay(650);
}
}