PeterH:
thomas3120:
I tried another way using the do-while loop and had better results (sort of hehe).
I got a nice smooth increase in acceleration but it went to full throttle instead of leveling out at my max. throttle threshold.
I'll see if I can dig the code out from my overun desktopand post back.
This is not a problem that really calls for while loops and so on.
I think the key concept is that you have a target speed and an actual speed. The target speed can be changed arbitrarily by outside forces at any time. The actual speed is controlled by the Arduino. At regular intervals the Arduino compares the actual and target speeds and moves the actual speed towards the target speed. The 'blink without delay' example sketch shows you how to carry out processing at regular intervals - here, instead of blinking an LED, you would update the speed. The acceleration characteristics would be defined by how frequently you updated the speed, and how much you updated it by.
Thanks Peter,
I tried incorporating blink without delay into my accelThrottle sketch.
I'm still unsure what to do about this part in Blink without delay:
if(ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
Here is what I have so far:
#include <Servo.h>
Servo myservoThrottle; // Initialize servos
Servo myservoSteering;
unsigned long actualSpeed =micros();
unsigned long targetSpeed =micros();
long interval =micros();
int neutralThrottle = 1500;
int maxThrotThresh = 1700;
void setup()
{
myservoThrottle.attach(53, 1000, 2000); // Attach servos throttle and steering
myservoSteering.attach(52, 1000, 2000);
}
void loop()
{
moveForward();
//...
//...
}
void moveForward()
{
interval =50;
targetSpeed =1700;
if(targetSpeed = actualSpeed += interval)
{
myservoThrottle.write(actualSpeed); /* ..or should I use myservoThrottle.write(targetSpeed);
since targetSpeed = actualSpeed += interval*/
}
}
Or something along these lines...
void moveForward()
{
interval =50;
targetSpeed =1700;
if(targetSpeed - actualSpeed > interval)
{
actualSpeed = targetSpeed;
myservoThrottle.write(targetSpeed);
}
}