81
Vehicles - Helicopters / Re: Convert racing controller PIDs to CC3D
« Last post by TheOtherCliff on July 17, 2022, 01:41:40 pm »Hmm...
By the time the sensor data gets into a UAV where you can see it, it is already converted into standard units and floating point. For instance GyroSensor is in degrees per second. The PID comes later than that.
The raw gyro sensor data is scaled to be float degrees per second in flight/modules/Sensors/sensors.c and put in GyroSensor with GyroSensorSet(). It goes into GyroState from there and every time that changes, innerloop.c gets the values and puts them into gyro_filtered and that is what the PID acts on.
There seems to be a hold over from the days of integers though. The PID code multiplies the inputs by 1000 at the beginning and divides by 1000 at the end. This kind of looks like scaling to avoid integer overflow / underflow and tastes like the old days of direct hardware access, but it might be some reasonable required scaling. Maybe just to match the values used in the integer days. I cringe when I think about it, but it is only 500 x 2 x ?6? = 6000 FLOPS so it isn't really worth a special version to take it out.
By the time the sensor data gets into a UAV where you can see it, it is already converted into standard units and floating point. For instance GyroSensor is in degrees per second. The PID comes later than that.
The raw gyro sensor data is scaled to be float degrees per second in flight/modules/Sensors/sensors.c and put in GyroSensor with GyroSensorSet(). It goes into GyroState from there and every time that changes, innerloop.c gets the values and puts them into gyro_filtered and that is what the PID acts on.
There seems to be a hold over from the days of integers though. The PID code multiplies the inputs by 1000 at the beginning and divides by 1000 at the end. This kind of looks like scaling to avoid integer overflow / underflow and tastes like the old days of direct hardware access, but it might be some reasonable required scaling. Maybe just to match the values used in the integer days. I cringe when I think about it, but it is only 500 x 2 x ?6? = 6000 FLOPS so it isn't really worth a special version to take it out.