Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
bool once = false;
float w = 1.2; //wheelbase
float v = 6; //speed in meters/sec of bike
float g = 9.8; //constant of gravity in meters/sec
float r = 10000000000; //radius of the turn
float height = 0.75; //height of the center of mass
float h = .5; //half of the length of the handlebar
float t = 0.035; //half of the width of the tire
float l = 0.8381; //length of the body of the actuator + 1.5 of the length of the fully extended actuator
float c = radians(72); //caster angle in degrees
float rate = 0.22987; //rate of motor
float cel = 0.8381; //current extention length of actuator
void loop() {
if (once == false){
c = radians(c);
float angle = (w*cos(atan(sq(v)/g*r)+asin(t*(sin(c)/(height-t)))))/r*cos(c); //needed steer angle of bike for desired turn
Serial.println(angle);
float rawdist = (sqrt(sq(l+h*sin(angle))+(sq(h-h*cos(angle))))); //distance that the actuator must travel
Serial.println(rawdist);
rawdist = float(rawdist, 3);
Serial.println(rawdist);
float dist = rawdist-cel; //total distance from actuator mount to new place to move
Serial.println(dist);
float sec = dist/rate; //number of seconds for the motors to run to make the needed changes to the bike handle bar poss
Serial.print(sec);
once = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.