This is for our FYDP project. 2 MPU6050s are used

Dependencies:   Servo mbed

Committer:
majik
Date:
Sun Mar 22 06:34:30 2015 +0000
Revision:
4:05484073a641
Parent:
0:21019d94ad33
BOTH IMUs WORK NOW. Put them in separate threads. Servo is included.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
majik 0:21019d94ad33 1 #ifndef ACS712_H
majik 0:21019d94ad33 2 #define ACS712_H
majik 0:21019d94ad33 3
majik 0:21019d94ad33 4 /****
majik 0:21019d94ad33 5 This class calculates the current drawn by the robot. It requires that EVERYTHING else is turned off when
majik 0:21019d94ad33 6 calibration is in progress.
majik 0:21019d94ad33 7 Requirement: Turn off mouse sensors somehow.
majik 0:21019d94ad33 8 */
majik 0:21019d94ad33 9
majik 0:21019d94ad33 10 #include "mbed.h"
majik 0:21019d94ad33 11 //#include "robot.h"
majik 0:21019d94ad33 12
majik 0:21019d94ad33 13 #define HIGH_CURRENT 130 //increase of current when switch is turned on [mA]
majik 0:21019d94ad33 14 #define LOW_CURRENT 36 //current draw when everything is turned off [mA]
majik 0:21019d94ad33 15 #define SWITCH_PIN PTB18//HIGH_CURRENT_SWITCH
majik 0:21019d94ad33 16 #define SENSOR_PIN PTC2//CURRENTSENSOR_PIN
majik 0:21019d94ad33 17
majik 0:21019d94ad33 18 #define CALIBRATION_SAMPLES 50 //the number of samples taken for the calibration
majik 0:21019d94ad33 19
majik 0:21019d94ad33 20 class ACS712
majik 0:21019d94ad33 21 {
majik 0:21019d94ad33 22 private:
majik 0:21019d94ad33 23
majik 0:21019d94ad33 24 AnalogIn sensor; //reads the value from current sensor
majik 0:21019d94ad33 25 DigitalOut currentSwitch; //turn this on to send current through a resistor
majik 0:21019d94ad33 26
majik 0:21019d94ad33 27 float b; //offset
majik 0:21019d94ad33 28 float m; //slope
majik 0:21019d94ad33 29 float current; //[mA]
majik 0:21019d94ad33 30 float sensor_val; //[% of 3.3V]
majik 0:21019d94ad33 31
majik 0:21019d94ad33 32 public:
majik 0:21019d94ad33 33
majik 0:21019d94ad33 34 ACS712();
majik 0:21019d94ad33 35 void calibrate(); //calculates m and b
majik 0:21019d94ad33 36 float get_current(); //returns the current [mA]
majik 0:21019d94ad33 37 float read_sensor(); //reads sensor [% of 3.3V]
majik 0:21019d94ad33 38 float read_sensor(int n, int t); //reads sensor <n> times and returns the average
majik 0:21019d94ad33 39 };
majik 0:21019d94ad33 40
majik 0:21019d94ad33 41
majik 0:21019d94ad33 42
majik 0:21019d94ad33 43 #endif