stuff n stuff

Dependencies:   AX12 mbed

Committer:
frohst
Date:
Thu Apr 16 06:59:16 2015 +0000
Revision:
0:6044f996df91
initial;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frohst 0:6044f996df91 1 #include "mbed.h"
frohst 0:6044f996df91 2 #include "AX12.h"
frohst 0:6044f996df91 3 #include <cmath>
frohst 0:6044f996df91 4
frohst 0:6044f996df91 5 Timer time;
frohst 0:6044f996df91 6 AX12 dyna(1,2,1); //tx,rx,ID,Baud
frohst 0:6044f996df91 7 Serial comp(3,4); //tx,rx
frohst 0:6044f996df91 8 AnalogIn pot(A0); //pot pin
frohst 0:6044f996df91 9
frohst 0:6044f996df91 10 int main()
frohst 0:6044f996df91 11 {
frohst 0:6044f996df91 12 bool done=false;
frohst 0:6044f996df91 13 float servoCmdTime=-1;
frohst 0:6044f996df91 14 float degPerVolt=330/3.3;
frohst 0:6044f996df91 15 comp.printf("Time(s),ServoPosition(deg),FlywheelError(deg)\n");
frohst 0:6044f996df91 16
frohst 0:6044f996df91 17 dyna.SetMode(0); //0-positional control. 1-velocity control
frohst 0:6044f996df91 18 dyna.SetGoal(150,0);
frohst 0:6044f996df91 19 float flyZero=pot.read()*degPerVolt;
frohst 0:6044f996df91 20
frohst 0:6044f996df91 21 time.start();
frohst 0:6044f996df91 22 while(!done)
frohst 0:6044f996df91 23 {
frohst 0:6044f996df91 24
frohst 0:6044f996df91 25 if(time.read()-servoCmdTime >= 0.001)
frohst 0:6044f996df91 26 {
frohst 0:6044f996df91 27 comp.printf("%.6f,%.2f,%.2f\n", time.read(), dyna.GetPosition(), pot.read()*degPerVolt-flyZero);
frohst 0:6044f996df91 28 int goal=150+60*sin(2*pi()*time.read()*time.read()/10); //freq=time(s)/10
frohst 0:6044f996df91 29 dyna.SetGoal(goal,1);
frohst 0:6044f996df91 30 servoCmdTime=time.read();
frohst 0:6044f996df91 31 if(time.read()/10 > 20)
frohst 0:6044f996df91 32 {
frohst 0:6044f996df91 33 done=true;
frohst 0:6044f996df91 34 }
frohst 0:6044f996df91 35 }
frohst 0:6044f996df91 36 }
frohst 0:6044f996df91 37 }