![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
NHK2017 octopus robot
Dependencies: 2017NHKpin_config mbed FEP ikarashiMDC PID jy901 omni HMC6352 omni_wheel
Fork of KANI2017v2 by
Diff: bot/PIDcontroller/PID_controller.cpp
- Revision:
- 2:ea151e05033a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bot/PIDcontroller/PID_controller.cpp Tue Aug 22 11:56:47 2017 +0000 @@ -0,0 +1,31 @@ +#include "PID_controller.h" + +void PIDC::updateOutput() +{ + rawDegree = sample(); + if(rawDegree - beforeDegree < -1800) turnOverNumber++; + if(rawDegree - beforeDegree > 1800) turnOverNumber--; + initDegree = rawDegree - offSetDegree + turnOverNumber * 3600; + beforeDegree = sample(); + + setProcessValue(initDegree / 10.0); + co = compute(); +} + +PIDC::PIDC() : PID(KC, TI, TD, INTERVAL), HMC6352(Sensor3pin5a, Sensor3pin5a) +{ + setInputLimits(-M_PI, M_PI); + setOutputLimits(-1.0, 1.0); + setBias(0.0); + setMode(AUTO_MODE); + setSetPoint(0.0); + + setOpMode(HMC6352_CONTINUOUS, 1, 20); + rawDegree = sample(); + beforeDegree = sample(); + offSetDegree = sample(); + initDegree = 0; + turnOverNumber = 0; + + this -> attach(this, &PIDC::updateOutput, 0.05); +} \ No newline at end of file