diff --git a/.gitignore b/.gitignore index 093e781..fb04b32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ *.b#* *.s#* -gerber/ +gerbers/ .DS_Store partslist* *farnell* diff --git a/software/apps/Motion/Motion0/Motion0.ino b/software/apps/Motion/Motion0/Motion0.ino new file mode 100644 index 0000000..8677ff3 --- /dev/null +++ b/software/apps/Motion/Motion0/Motion0.ino @@ -0,0 +1,55 @@ +#include + +/* + +Two motion objects are available from the MMM Motions library +(1) MotionA +(2) MotionB + +MOTION { + MOTIONA , + MOTIONB1 +}; + +Each objects needs intialisation with a specific input +from which ADC reading will be performed. + +Users may choose and identify inputs aa INPUT[A0, ... ,A7]. +ex: MotionA.init(INPOUTA5); + +INPUT { + INPUTA0, + INPUTA1, + INPUTA2, + INPUTA3, + INPUTA4, + INPUTA5, + INPUTA6, + INPUTA7 +} + +All calculation of physics (position, velocity and acceleration) +are computed internally usign interrupts and timers. To access +such information, user may call getPosition(), getVelocity() +and getAcceleration() respectively on a initialised Motion object. + +int getPosition(); +float getVelocity(); +float getAcceleration(); + +*/ + +void setup() { + MotionA.init(INPUTA0); + Serial.begin(9600); +} + +void loop() { + Serial.print("position: "); Serial.println(MotionA.getPosition()); + Serial.print("velocity: "); Serial.println(MotionA.getVelocity()); + Serial.print("accel: "); Serial.println(MotionA.getAcceleration()); + Serial.println("-------"); + delay(100); +} + + diff --git a/software/lib/MMM/Motion.cpp b/software/lib/MMM/Motion.cpp index a587da9..7baccdb 100644 --- a/software/lib/MMM/Motion.cpp +++ b/software/lib/MMM/Motion.cpp @@ -37,19 +37,24 @@ Motion MotionB(MOTIONA); uint8_t lb; uint8_t hb; int x, xx; -float T = N * 0.004f; // 4ms +float T = N * 0.004f; // 4ms (see TCNT1) float v; +float MAX_POS = 1023; +float MAX_VEL = MAX_POS / T; +float MAX_ACC = MAX_VEL / T; + Motion::Motion(MOTION m){ _m = m; _i = false; + _fcb = NULL; }; void Motion::init(INPUT sensor) { if(!motion_reg_init){ - TCNT1 = 1000; //4 ms + TCNT1 = 1000; //4 ms (TCNT1) TIMSK1 = (1 << TOIE1); motion_reg_init = true; } @@ -57,11 +62,6 @@ void Motion::init(INPUT sensor) _s = sensor; } -void Motion::updatePhysics() -{ - -} - int Motion::getPosition() { return _x; } @@ -74,6 +74,11 @@ float Motion::getAcceleration() { return _a; } +void Motion::set_force_callback(force_callback fcb, PHY physics) { + _fcb = fcb; + _fcb_phy = physics; +} + // clocked at 4ms period ISR(TIMER1_OVF_vect) { diff --git a/software/lib/MMM/Motion.h b/software/lib/MMM/Motion.h index 8ffeb0d..b066034 100644 --- a/software/lib/MMM/Motion.h +++ b/software/lib/MMM/Motion.h @@ -25,6 +25,8 @@ #define N 10 +typedef float (*force_callback)(float position); + enum MOTION { MOTIONA = 0, MOTIONB = 1 @@ -41,6 +43,12 @@ enum INPUT { INPUTA7 = 0x0111 }; +enum PHY { + POSITION = 0, + VELOCITY = 1, + ACCELERATION = 2 +}; + class Motion { @@ -53,12 +61,13 @@ public: float getVelocity(); float getAcceleration(); - void updatePhysics(); + void set_force_callback(force_callback fcb, PHY physics); // raw position vector int _xv[N]; int _ix; + int _x; float _v; float _a; @@ -67,6 +76,8 @@ public: INPUT _s; bool _i; + force_callback _fcb; + PHY _fcb_phy; }; extern Motion MotionA;