This is the one where I went back and un-did the cube.cpp file

Dependencies:   BNO055_fusion_tom FastPWM mbed

Fork of NucleoCube1 by Tom Rasmussen

Committer:
tomras12
Date:
Tue Apr 18 21:13:06 2017 +0000
Revision:
29:37dc63b57d6e
Parent:
28:b813a8f685c3
Added button debounce and equilibrium angle setpoint on press

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tomras12 23:abe76b7c377a 1 /*
tomras12 23:abe76b7c377a 2 * cube.h
tomras12 23:abe76b7c377a 3 * April 11, 2017
tomras12 23:abe76b7c377a 4 *
tomras12 23:abe76b7c377a 5 * Control software for balancing cube senior design project
tomras12 23:abe76b7c377a 6 *
tomras12 23:abe76b7c377a 7 * Will Church
tomras12 23:abe76b7c377a 8 * Tom Rasmussen
tomras12 23:abe76b7c377a 9 */
tomras12 23:abe76b7c377a 10
tomras12 23:abe76b7c377a 11 #ifndef CUBE_H
tomras12 23:abe76b7c377a 12 #define CUBE_H
tomras12 23:abe76b7c377a 13
tomras12 23:abe76b7c377a 14 /* -- INCLUDES -- */
tomras12 23:abe76b7c377a 15 #include "mbed.h"
tomras12 23:abe76b7c377a 16 #include "BNO055.h"
tomras12 23:abe76b7c377a 17
tomras12 23:abe76b7c377a 18 /* -- STRUCT -- */
tomras12 23:abe76b7c377a 19 struct config {
tomras12 23:abe76b7c377a 20 double Kbt; // Body angle gain
tomras12 23:abe76b7c377a 21 double Kbv; // Body velocity gain
tomras12 23:abe76b7c377a 22 double Kwv; // Wheel velocity gain
tomras12 23:abe76b7c377a 23 double eqAngle; // Equilibrium angle
tomras12 23:abe76b7c377a 24 double *angle; // Points to angle in IMU Euler_angle struct
tomras12 23:abe76b7c377a 25 double *vel; // Points to vel in IMU VEL struct
tomras12 24:c7b3bac429c5 26 PwmOut *pwm; // PWM out for motor control
tomras12 24:c7b3bac429c5 27 AnalogIn *hall; // Analog in for wheel velocity
tomras12 24:c7b3bac429c5 28 char *descr; // Description of config
tomras12 23:abe76b7c377a 29 };
tomras12 23:abe76b7c377a 30
tomras12 29:37dc63b57d6e 31 /* -- GLOBALS -- */
tomras12 29:37dc63b57d6e 32 Ticker pwmint; // Button interrupt
tomras12 29:37dc63b57d6e 33 BNO055_EULER_TypeDef euler_angles;
tomras12 29:37dc63b57d6e 34 BNO055_VEL_TypeDef velocity;
tomras12 29:37dc63b57d6e 35 config *currentConfig; // Stores current config
tomras12 29:37dc63b57d6e 36 bool isActive; // Control loop bool
tomras12 29:37dc63b57d6e 37
tomras12 23:abe76b7c377a 38 /* -- CONSTANTS -- */
tomras12 29:37dc63b57d6e 39 const double pi = 3.14159265;
tomras12 29:37dc63b57d6e 40 const float TM = .25; //threshold for main axis
tomras12 29:37dc63b57d6e 41 const float TA = .2; //threshold for aux axis
tomras12 23:abe76b7c377a 42
tomras12 29:37dc63b57d6e 43 /* -- CONFIGS -- */
tomras12 29:37dc63b57d6e 44 /* Define our parameters here for each balancing configuration */
tomras12 29:37dc63b57d6e 45 struct config balX = {-89.9276, //Kbt
tomras12 29:37dc63b57d6e 46 -14.9398, //Kbv
tomras12 29:37dc63b57d6e 47 -0.001, //Kwv
tomras12 29:37dc63b57d6e 48 pi/4.0, //eqAngle
tomras12 29:37dc63b57d6e 49 &(euler_angles.r), //angle
tomras12 29:37dc63b57d6e 50 &(velocity.x), //vel
tomras12 29:37dc63b57d6e 51 new PwmOut(PE_9), //pwm
tomras12 29:37dc63b57d6e 52 new AnalogIn(A0), //hall
tomras12 29:37dc63b57d6e 53 "Balancing on X edge"}; //descr
tomras12 29:37dc63b57d6e 54
tomras12 29:37dc63b57d6e 55 struct config balY = {0, //Kbt
tomras12 29:37dc63b57d6e 56 0, //Kbv
tomras12 29:37dc63b57d6e 57 0, //Kwv
tomras12 29:37dc63b57d6e 58 -pi/4.0, //eqAngle
tomras12 29:37dc63b57d6e 59 &(euler_angles.p), //angle
tomras12 29:37dc63b57d6e 60 &(velocity.y), //vel
tomras12 29:37dc63b57d6e 61 new PwmOut(PE_9), //pwm
tomras12 29:37dc63b57d6e 62 new AnalogIn(A0), //hall
tomras12 29:37dc63b57d6e 63 "Balancing on Y edge"}; //descr
tomras12 23:abe76b7c377a 64
tomras12 29:37dc63b57d6e 65 struct config balZ = {-72.4921, //Kbt
tomras12 29:37dc63b57d6e 66 -9.9672, //Kbv
tomras12 29:37dc63b57d6e 67 -0.00025, //Kwv
tomras12 29:37dc63b57d6e 68 -.7000, //eqAngle
tomras12 29:37dc63b57d6e 69 &(euler_angles.p), //angle
tomras12 29:37dc63b57d6e 70 &(velocity.z), //vel
tomras12 29:37dc63b57d6e 71 new PwmOut(PE_9), //pwm
tomras12 29:37dc63b57d6e 72 new AnalogIn(A0), //hall
tomras12 29:37dc63b57d6e 73 "Balancing on Z edge"}; //descr
tomras12 23:abe76b7c377a 74
tomras12 29:37dc63b57d6e 75 struct config fall = {0, //Kbt
tomras12 29:37dc63b57d6e 76 0, //Kbv
tomras12 29:37dc63b57d6e 77 0, //Kwv
tomras12 29:37dc63b57d6e 78 0, //eqAngle
tomras12 29:37dc63b57d6e 79 &(euler_angles.p), //angle
tomras12 29:37dc63b57d6e 80 &(velocity.z), //vel
tomras12 29:37dc63b57d6e 81 NULL, //pwm
tomras12 29:37dc63b57d6e 82 NULL, //hall
tomras12 29:37dc63b57d6e 83 "Fallen"}; //descr
tomras12 23:abe76b7c377a 84
tomras12 23:abe76b7c377a 85 // Other constants
tomras12 29:37dc63b57d6e 86
tomras12 23:abe76b7c377a 87
tomras12 23:abe76b7c377a 88 /* -- NOTES -- */
tomras12 23:abe76b7c377a 89 //------------------------------------
tomras12 23:abe76b7c377a 90 // Hyperterminal configuration
tomras12 23:abe76b7c377a 91 // 9600 bauds, 8-bit data, no parity
tomras12 23:abe76b7c377a 92 //------------------------------------
tomras12 23:abe76b7c377a 93
tomras12 23:abe76b7c377a 94 /* -- PROTOTYPES -- */
tomras12 23:abe76b7c377a 95
tomras12 23:abe76b7c377a 96 /*
tomras12 24:c7b3bac429c5 97 * Checks and prints calibration until sys calib is at 3 / 3
tomras12 24:c7b3bac429c5 98 */
tomras12 28:b813a8f685c3 99 //void checkCalib(BNO055 *imu, Serial *pc);
tomras12 24:c7b3bac429c5 100
tomras12 24:c7b3bac429c5 101 /*
tomras12 23:abe76b7c377a 102 * TODO: Documentation here
tomras12 23:abe76b7c377a 103 * Note: should this function be inline?
tomras12 23:abe76b7c377a 104 */
tomras12 23:abe76b7c377a 105 double calcPWM(config *c);
tomras12 23:abe76b7c377a 106 void updatePWM(config *c);
tomras12 23:abe76b7c377a 107 #endif