I am creating a hamster robot who runs around in a hamster ball and builds a cognitive map of its area. My arduino code must accept an int from an android phone on top of the bot, inside the hamster ball (via Wi-Shield) and control the motor based on that int. I am trying to get the DC motor to accelerate, as it is on for longer (i.e. longer distance), just like a real hamster accelerates by finding a longer path in order to get over obstacles and generally gain speed. This is my current acceleration code:
//action=wifi.getNum; //pseudocode to get int from wishield
if(action==0){
pwmSpeed=0;
while(pwmSpeed<250){
pwmSpeed+=5;
analogWrite(motorpwm, pwmSpeed);
analogWrite(motorpwm2, pwmSpeed);
digitalWrite(motor1, HIGH);
digitalWrite(motor1b, LOW); //turns the motors on - forwards
digitalWrite(motor2, HIGH);
digitalWrite(motor2b, LOW);
delay(500);
}
}
I know that the numbers are wayyy off, but is this the right general concept?
Also-- if anyone is familiar with sending small pieces of data (1 int) from the wi-shield, l would appreciate some help. I tried getting help over at the wi-shield forum, but don't really know how to do what theyre telling me to do.
Thanks,
HamBot
Is this a very difficult issue? I somehow thought the solution would be fairly simple. could someone knowledgeable about arduino at least tell me that I'm on my own? That would be helpful :-/
please help. Is anyone out there?
It looks like you have got the idea about acceleration. A steady linear increase in speed. Has you have it only increasing the speed every half second it will feel a bit jerky. Try cutting down the delay and reducing the increment.
I have only ever applied acceleration to stepping motors but that essentially is the same thing. However I feel that the acceleration is going to be the easy part of your project.
Best of luck with it.
Hey Mike, thanks a lot. The accel will definitely require a lot of testing, as it needs to be fairly precise to get over bumps (problems the bot faces in the map), but yeah, probably one of the easier parts of this epic project I've taken on. The other thing I was wondering is when I get to to top speed, I want it to coast at top speed until it get's a stop input, Is this code correct for that?
Thanks Again,
David
I want it to coast at top speed until it get's a stop input,
then do nothing, once the motor is going at that speed it will keep on going. However if you accelerate up to a speed you will probably have to decelerate down when you want to stop.
Thanks again, Mike. I'll start testing this and post any further problems I have. One other question-- you said that you've done this kind of code with stepper motors. Do you think those are better suited for this kind of project? Are they easier to determine distance travelled than DC?
David
Are they easier to determine distance travelled than DC?
Yes I think they are easier but it is still a difficult thing to do with any sort of motor because of wheel slippage.
My project was making an XY plotter in the late 70s using a 6800 processor all programmed in hand assembled hex over 2K of code (and that's a lot of hand assembled hex) so all I had to worry about was the missing pulses if you went too fast.
always more problems thanks for the help. I have a lot to test and tweak.