XYZ platform including 3 motors and 8 magnetometers (LIS3MDL).
Fork of XYZ_sensor_Platform by
xyz_sensor_platform.h@15:db753c75e53f, 2018-08-03 (annotated)
- Committer:
- hober
- Date:
- Fri Aug 03 01:32:16 2018 +0000
- Revision:
- 15:db753c75e53f
- Parent:
- 14:1363e4b2fbac
Change AltIMU_10_v5 to magring board, and change transmit interface from I2C to SPI.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hober | 0:b9e728e5c47c | 1 | #ifndef __XYZ_SENSOR_PLATFORM_H |
hober | 0:b9e728e5c47c | 2 | #define __XYZ_SENSOR_PLATFORM_H |
hober | 0:b9e728e5c47c | 3 | |
hober | 0:b9e728e5c47c | 4 | /*** Includes ----------------------------------------------------------------- ***/ |
hober | 2:856f03e64695 | 5 | //#include "mbed.h" |
hober | 15:db753c75e53f | 6 | #include "mag_ring.h" |
hober | 0:b9e728e5c47c | 7 | #include "motor.h" |
hober | 0:b9e728e5c47c | 8 | #include "motor_targets.h" |
hober | 7:0ad7d240be7a | 9 | #define MOTOR_INITIAL |
hober | 14:1363e4b2fbac | 10 | #define CALIBRATION_TIME 100 |
hober | 7:0ad7d240be7a | 11 | |
hober | 0:b9e728e5c47c | 12 | /*** Typedefs ----------------------------------------------------------------- ***/ |
hober | 0:b9e728e5c47c | 13 | typedef struct { |
hober | 0:b9e728e5c47c | 14 | int32_t AXIS_X; |
hober | 0:b9e728e5c47c | 15 | int32_t AXIS_Y; |
hober | 0:b9e728e5c47c | 16 | int32_t AXIS_Z; |
hober | 0:b9e728e5c47c | 17 | } AxesRaw_TypeDef; |
hober | 0:b9e728e5c47c | 18 | |
hober | 15:db753c75e53f | 19 | typedef struct { |
hober | 15:db753c75e53f | 20 | AxesRaw_TypeDef Magnetic[NUMBER_OF_MAGNETOMETERS]; |
hober | 15:db753c75e53f | 21 | } MagneticArray_TypeDef; |
hober | 15:db753c75e53f | 22 | |
hober | 0:b9e728e5c47c | 23 | class XYZSensorPlatform |
hober | 0:b9e728e5c47c | 24 | { |
hober | 0:b9e728e5c47c | 25 | public: |
hober | 0:b9e728e5c47c | 26 | XYZSensorPlatform(); |
hober | 0:b9e728e5c47c | 27 | void init(void); |
hober | 12:e2b7e030193c | 28 | void reset(void); |
hober | 0:b9e728e5c47c | 29 | |
hober | 8:679a5428d584 | 30 | void go_forward(); |
hober | 8:679a5428d584 | 31 | void go_backward(); |
hober | 8:679a5428d584 | 32 | void go_up(); |
hober | 8:679a5428d584 | 33 | void go_down(); |
hober | 8:679a5428d584 | 34 | void go_right(); |
hober | 8:679a5428d584 | 35 | void go_left(); |
hober | 0:b9e728e5c47c | 36 | |
hober | 15:db753c75e53f | 37 | bool isMoving(){ return motorX->moving() || motorY->moving() || motorZ->moving(); } |
hober | 15:db753c75e53f | 38 | |
hober | 0:b9e728e5c47c | 39 | void set_speed(float speed) { |
hober | 0:b9e728e5c47c | 40 | motorX->setSpeed(speed); |
hober | 0:b9e728e5c47c | 41 | motorY->setSpeed(speed); |
hober | 0:b9e728e5c47c | 42 | motorZ->setSpeed(speed); |
hober | 0:b9e728e5c47c | 43 | } |
hober | 0:b9e728e5c47c | 44 | |
hober | 0:b9e728e5c47c | 45 | float speed() { |
hober | 0:b9e728e5c47c | 46 | return motorX->speed(); |
hober | 0:b9e728e5c47c | 47 | } |
hober | 0:b9e728e5c47c | 48 | |
hober | 0:b9e728e5c47c | 49 | void position(float* pos) { |
hober | 0:b9e728e5c47c | 50 | pos[0] = motorX->position(); |
hober | 0:b9e728e5c47c | 51 | pos[1] = motorY->position(); |
hober | 0:b9e728e5c47c | 52 | pos[2] = motorZ->position(); |
hober | 0:b9e728e5c47c | 53 | } |
hober | 0:b9e728e5c47c | 54 | |
hober | 12:e2b7e030193c | 55 | void setPosition(float x, float y, float z) { |
hober | 12:e2b7e030193c | 56 | motorX->setPosition(x); |
hober | 12:e2b7e030193c | 57 | motorY->setPosition(y); |
hober | 12:e2b7e030193c | 58 | motorZ->setPosition(z); |
hober | 0:b9e728e5c47c | 59 | } |
hober | 12:e2b7e030193c | 60 | |
hober | 8:679a5428d584 | 61 | |
hober | 8:679a5428d584 | 62 | void to(float x, float y, float z) ; |
hober | 0:b9e728e5c47c | 63 | |
hober | 15:db753c75e53f | 64 | MagneticArray_TypeDef get_mag() { |
hober | 15:db753c75e53f | 65 | MagneticArray_TypeDef ret; |
hober | 0:b9e728e5c47c | 66 | magnetometer->get_m_axes((int32_t *)&ret); |
hober | 0:b9e728e5c47c | 67 | return ret; |
hober | 0:b9e728e5c47c | 68 | } |
hober | 0:b9e728e5c47c | 69 | |
hober | 15:db753c75e53f | 70 | int get_mag_raw(int16_t ret[][3]) { |
hober | 15:db753c75e53f | 71 | return sensor->get_m_axes_raw(ret); |
hober | 3:2194b5b4f82a | 72 | } |
hober | 3:2194b5b4f82a | 73 | |
hober | 15:db753c75e53f | 74 | int get_mag_raw(int magIndex, int16_t *ret) { |
hober | 15:db753c75e53f | 75 | return sensor->get_m_axes_raw(magIndex, ret); |
hober | 15:db753c75e53f | 76 | } |
hober | 15:db753c75e53f | 77 | |
hober | 15:db753c75e53f | 78 | void resetMagnetometer(int magIndex) |
hober | 15:db753c75e53f | 79 | { |
hober | 15:db753c75e53f | 80 | sensor->resetMagnetometer(magIndex); |
hober | 15:db753c75e53f | 81 | } |
hober | 15:db753c75e53f | 82 | /* |
hober | 0:b9e728e5c47c | 83 | AxesRaw_TypeDef get_acc() { |
hober | 0:b9e728e5c47c | 84 | AxesRaw_TypeDef ret; |
hober | 0:b9e728e5c47c | 85 | accelerometer->get_x_axes((int32_t *)&ret); |
hober | 0:b9e728e5c47c | 86 | return ret; |
hober | 0:b9e728e5c47c | 87 | } |
hober | 0:b9e728e5c47c | 88 | |
hober | 0:b9e728e5c47c | 89 | AxesRaw_TypeDef get_gyr() { |
hober | 0:b9e728e5c47c | 90 | AxesRaw_TypeDef ret; |
hober | 0:b9e728e5c47c | 91 | gyroscope->get_g_axes((int32_t *)&ret); |
hober | 0:b9e728e5c47c | 92 | return ret; |
hober | 0:b9e728e5c47c | 93 | } |
hober | 15:db753c75e53f | 94 | */ |
hober | 15:db753c75e53f | 95 | void setSensorSpiFrequency(int hz){ sensor->setSpiFrequency(hz); } |
hober | 0:b9e728e5c47c | 96 | private: |
hober | 15:db753c75e53f | 97 | void checkMovedTimes(); |
hober | 0:b9e728e5c47c | 98 | Motor *motorX, *motorY, *motorZ; |
hober | 3:2194b5b4f82a | 99 | float x,y,z; |
hober | 15:db753c75e53f | 100 | int _movedTimes; |
hober | 4:229de5852b9e | 101 | InterruptIn xZero, xEnd, yZero, yEnd, zZero, zEnd; |
hober | 15:db753c75e53f | 102 | MagRing *sensor; |
hober | 15:db753c75e53f | 103 | //GyroSensor *gyroscope; |
hober | 15:db753c75e53f | 104 | //MotionSensor *accelerometer; |
hober | 0:b9e728e5c47c | 105 | MagneticSensor *magnetometer; |
hober | 15:db753c75e53f | 106 | //TempSensor *temp_sensor; |
hober | 0:b9e728e5c47c | 107 | }; |
hober | 0:b9e728e5c47c | 108 | #endif // __XYZ_SENSOR_PLATFORM_H |