JFDuval said:Hello!
The link is working, it's the video that can't be seen (by some people at least). The directory jfduv/ exist. Don't forget the slash at the end.
MrMikey83 said:Seems to stay pretty still which doesn't make for a very exciting video. Good job though!
~Mike
while(1)
{
//delay_ms(45);
//Look for user input
check_for_button();
//Find tilt magnitude
//===================================================================
tilt_value = read_tilt();
tilt_angle = tilt_center - tilt_value;
//===================================================================
//Find gyro magnitude
//===================================================================
gyro_value = read_gyro();
gyro_amount = gyro_center - gyro_value;
//===================================================================
tilt_correction = tilt_angle * tilt_fudge;
gyro_correction = gyro_amount * gyro_fudge;
new_correction = tilt_correction + gyro_correction;
new_correction = new_correction * new_fudge;
//motor_correction = motor_correction + new_correction; //Integrate over time
motor_correction = new_correction; //
//if (abs(tilt_angle) <= 1) {putc('!'); motor_correction = 0;}
/*
printfloat("T=%f ", tilt_correction);
printfloat("G=%f ", gyro_correction);
printfloat("C=%f ", motor_correction);
*/
set_motors(motor_correction);
}
You NEVER want to use floating point values in time critical code of an 8 bit system. Floating point computations are really, really slow on an 8 bit system. A single floating point multiply will take several THOUSAND instructions compared to tens for a 16 bit integer multiply. I have a feeling your control loop is running a lot slower than you think. If you need fractional values use Fixed point numbers which can be implemented using standard integer math.I've run the P and D values from 0-8 in 0.01 steps.
It's the derivative term that is the damping term - make sure you have the sign right so it's damping (it should be in the opposite direction of the P term). The integral term is only to cancel out constant forces in steady state. The rest of the time it make a controller worse.I feel like I need a dampening variable - that's why I was trying to integrate the correction value over time.
This means your P term is too big. If you can't make P low enough and still use integer values just add a constant divisor to the control output (this effectivly make your values like a truncated fixed point). You can also add something called "dead band" this is where you ignore differences lower than a couple ticks.A 1 'tick' change in the ADC reading, and the system reacts so quickly, it starts to oscillate.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?