Skip to content

Instantly share code, notes, and snippets.

@cdiener1
Created April 20, 2019 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdiener1/aace0bf151facfc76cc0a4cd452a3c68 to your computer and use it in GitHub Desktop.
Save cdiener1/aace0bf151facfc76cc0a4cd452a3c68 to your computer and use it in GitHub Desktop.
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