Go Down

Topic: cruise control on motorcycle, need to read timing between wheel RPMs on reed swi (Read 3 times) previous topic - next topic

msumrell

I have built a control box using a mini ATmega 328, servo, potentiometer and 4 button inputs. Currently it works for what i have done. Throttle turns the pot wich moves the servo to pull/push the throttle cables. Two buttons on the handle bars sets the current throttle position and then if pushed, pulls or pushes the servo in 2* incriments. If you pull the front brake or clutch levers it releases the servo control back to the pot. It all works well but now I want to add a reed switch to the front wheel to pick up revolution time of the wheel and feed the change in speed back to the Arduino to move the servo to adjust for change in wheel speed to create a true speed control. I am really condused on this part. i have read a lot on the timers and different posts but dont know how to do this part. What I am thinking is something like if button one is pushed (lockes out the pot and increases 2* servo position) take reading of reed, if rpm slows, increase servo position, if rpm speeds up decrease servo position and do this action every 1/2 second. here is my current code which works for the first part, simple throttle control, button one and two set position and decrease/increase throttle position and button 4 and 5 to release button 1 and 2 back to pot control.

(Button 3 is wired to pin 6 and available on the bike to wire in the reed switch.)


Code: [Select]

#include <Servo.h>
Servo myservo;  // create servo object to control a servo
int potpin = 0; //potentiometer pin location
int val;       //name given for pot input value
int button1 = 10;
int button2 = 8;
int button3 = 6;
int button4 = 4;
int button5 = 2;

void setup() { //assigns inputs and outputs
    pinMode(button1, INPUT); //button 1 input assignment
    pinMode(button2, INPUT); //button 2 input assignment
    pinMode(button3, INPUT); //button 3 input assignment
    pinMode(button4, INPUT); //button 3 input assignment
    pinMode(button5, INPUT); //button 3 input assignment
    myservo.attach(12);
}


void loop(){
  val = analogRead(potpin);  //takes reading from pot current position         
  val = map(val, 0, 1083, 0, 180);   //maps pot inputs to servo output, cut off 0-9 to eliminate gitter 
  myservo.write(val);      //writes current position to servo to move it
  delay(150); //allows time for switch ro reset 
   if (digitalRead(button1) == HIGH)
   SerLoop1(); //sends command to SerLoop1 which is normal throttle control
   if (digitalRead(button2) == HIGH)
   SerLoop1(); //sends command to SerLoop1 which is normal throttle control
   else loop(); //returns to loop to run again
}
void SerLoop1(){
    myservo.attach(12); //attaches servo to pin 10
    int val1 = myservo.read(); //reads current servo location
    if (digitalRead(button1) == HIGH)
    myservo.write(val1 + 2); //SUBTRACT 2 degrees to servo position for increased throttle
    delay(100); //allows time for switch ro reset
    if (digitalRead(button2) == HIGH)
    myservo.write(val1 - 2); //ADDS 2 degrees to servo position for decreased throttle
    delay(100); //allows time for switch ro reset
    if (digitalRead(button5) == HIGH)
    loop(); //returns to normal cruise position
        if (digitalRead(button4) == HIGH)
    loop(); //returns to normal cruise position
    else SerLoop1(); //returns to SerLoop2 to run again

PaulS

Quote
I am really condused on this part.

Then you should stop. You do not have the skills or expertise to be building a cruise control.

Code: [Select]
 delay(150); //allows time for switch ro reset
That is more than enough time to get yourself killed. During that time, you can not do anything about shutting off the cruise control if things go to shit.

Stop right now. This project is well beyond your capabilities.

Code: [Select]
   else loop(); //returns to loop to run again
Never call loop().

Really. Stop!

PeterH

Do you have a scheme which enables the rider to shut the power off regardless of anything the Arduino does to increase power?
I only provide help via the forum - please do not contact me for private consultancy.

msumrell

Perhaps we could avoid the sarcasm.

Yes there are safe guards in place, thank you. I have test rode it and it works without flaw. The only failure it can have is to lose power and throttle down. If anyone can help with adding the reed switch into the programming that would be appreciated.

GoForSmoke

Are you only getting 1 pulse per wheel turn? That can be a lot of lag between change in speed and data capture.

Could you try rolling a thin small roller that rolls on the bike wheel and watch -that- turn? Then you know of change within the circumference of the little wheel of when the change began.

If you can put a bar magnet across a wheel shaft end center and mount a Hall sensor right over that you can use analog read to know the angle of the wheel maybe 5 times a millisecond.

Do you know how many meters or feet 1 turn of your motorcycle wheel covers? Or how much the speed of that wheel can change in that distance?

There are problems you're going to have you don't even know yet. You really used delay(150)?
Take all your "good pictures" now so you can look back on those days later.

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Go Up