Neither are terribly difficult, but you shouldn't do both in the same sketch. In order to implement a PID loop you have to either implement the functions of an existing PID library or write your own. I am wondering though, have you done any testing to see if your servo is strong enough to steer a bicycle at all - even without a PID loop? Can it turn the front wheel under full load standing still (bike stationary)? Because there isn't a "one to one" relationship between servo angle and roll angle (what you are measuring with the IMU), this is actually a non-linear system and you will need a PID controller. It is an autonomous bicycle project so basically I want the servo motor to turn the steer of the bicycle when bicycle leans in any direction. Void SetOutputLimits(double Min, double Max) SampleTime = (unsigned long)NewSampleTime *Compute all the working error variables*/ĭouble ratio = (double)NewSampleTime/(double)SampleTime * I make the mean of 200 values, that should be enough*/ *Here we calculate the acc data error before we start the loop Time = millis() //Start counting time in milliseconds Serial.begin(9600) //Remember to set this same baud rate to the serial monitor Wire.write(0x10) //Set the register bits as 00010000 (+/- 8g full scale range) Wire.write(0x1C) //We want to write to the ACCEL_CONFIG register Wire.beginTransmission(0圆8) //Start communication with the address found during search. Wire.endTransmission(true) //End the transmission with the gyro Wire.write(0x10) //Set the register bits as 00010000 (1000dps full scale) Wire.write(0x1B) //We want to write to the GYRO_CONFIG register (1B hex) Wire.endTransmission(true) //end the transmission Wire.write(0圆B) //make the reset (place a 0 into the 6B register) Wire.beginTransmission(0圆8) //begin, Send the slave adress (in this case 68) Wire.begin() //begin the wire comunication put your setup code here, to run once: Float Gyro_raw_error_x, Gyro_raw_error_y įloat Acc_angle_error_x, Acc_angle_error_y
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |