NHK2017 octopus robot

Dependencies:   2017NHKpin_config mbed FEP ikarashiMDC PID jy901 omni HMC6352 omni_wheel

Fork of KANI2017v2 by NagaokaRoboticsClub_mbedTeam

Committer:
UCHITAKE
Date:
Thu Aug 24 08:16:21 2017 +0000
Revision:
6:590c9622ecf1
Child:
19:41f7dd1a5ed1
Just worked !!!!!!!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
UCHITAKE 6:590c9622ecf1 1 #include "PID_controller.h"
UCHITAKE 6:590c9622ecf1 2
UCHITAKE 6:590c9622ecf1 3 void PIDC::updateOutput()
UCHITAKE 6:590c9622ecf1 4 {
UCHITAKE 6:590c9622ecf1 5 confirm();
UCHITAKE 6:590c9622ecf1 6 }
UCHITAKE 6:590c9622ecf1 7
UCHITAKE 6:590c9622ecf1 8 PIDC::PIDC() : PID(KC, TI, TD, INTERVAL), HMC6352(HMCsda, HMCscl)
UCHITAKE 6:590c9622ecf1 9 {
UCHITAKE 6:590c9622ecf1 10 setInputLimits(-180, 180);
UCHITAKE 6:590c9622ecf1 11 setOutputLimits(-1.0, 1.0);
UCHITAKE 6:590c9622ecf1 12 setBias(0.0);
UCHITAKE 6:590c9622ecf1 13 setMode(AUTO_MODE);
UCHITAKE 6:590c9622ecf1 14 setSetPoint(0.0);
UCHITAKE 6:590c9622ecf1 15
UCHITAKE 6:590c9622ecf1 16 setOpMode(HMC6352_CONTINUOUS, 1, 20);
UCHITAKE 6:590c9622ecf1 17 rawDegree = sample();
UCHITAKE 6:590c9622ecf1 18 beforeDegree = sample();
UCHITAKE 6:590c9622ecf1 19 offSetDegree = sample();
UCHITAKE 6:590c9622ecf1 20 initDegree = 0;
UCHITAKE 6:590c9622ecf1 21 turnOverNumber = 0;
UCHITAKE 6:590c9622ecf1 22 // this -> attach(this, &PIDC::updateOutput, INTERVAL);
UCHITAKE 6:590c9622ecf1 23 }
UCHITAKE 6:590c9622ecf1 24
UCHITAKE 6:590c9622ecf1 25 void PIDC::confirm()
UCHITAKE 6:590c9622ecf1 26 {
UCHITAKE 6:590c9622ecf1 27 rawDegree = sample();
UCHITAKE 6:590c9622ecf1 28 if(rawDegree - beforeDegree < -1800) turnOverNumber++;
UCHITAKE 6:590c9622ecf1 29 if(rawDegree - beforeDegree > 1800) turnOverNumber--;
UCHITAKE 6:590c9622ecf1 30 initDegree = rawDegree - offSetDegree + turnOverNumber * 3600;
UCHITAKE 6:590c9622ecf1 31 beforeDegree = sample();
UCHITAKE 6:590c9622ecf1 32 setProcessValue(initDegree / 10.0);
UCHITAKE 6:590c9622ecf1 33 co = compute();
UCHITAKE 6:590c9622ecf1 34 }
UCHITAKE 6:590c9622ecf1 35
UCHITAKE 6:590c9622ecf1 36 float PIDC::getCo()
UCHITAKE 6:590c9622ecf1 37 {
UCHITAKE 6:590c9622ecf1 38 return co;
UCHITAKE 6:590c9622ecf1 39 }