-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoboHeart.h
105 lines (84 loc) · 2.48 KB
/
RoboHeart.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*!
* @file RoboHeart.h
*
* Arduino library for the RoboHeart.
*
*/
#ifndef RoboHeart_h
#define RoboHeart_h
#include <Arduino.h>
#include <SparkFunLSM6DS3.h>
#include <Wire.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "RoboHeartDRV8836.h"
#include "RoboHeartStepperMotor.h"
#include "pins_RoboHeart.h"
#include <math.h>
#define TRESHOLD 0.3 //treshold in degrees/s
#define PERIOD_US 200
#define MOTOR_A_CHANNEL1 0
#define MOTOR_A_CHANNEL2 1
#define MOTOR_B_CHANNEL1 2
#define MOTOR_B_CHANNEL2 3
#define MOTOR_C_CHANNEL1 4
#define MOTOR_C_CHANNEL2 5
#define MOTOR_A 0
#define MOTOR_B 1
#define MOTOR_C 2
#define CALIBRATION_COUNTDOWN 5
#define ACCELEROMETER_CUTOFF 32
#define NEW_IMU_DATA_BIT 1
#define LSM6DS3_I2C_ADDR 0x6A // or 0x6B - Address is defined in Library
typedef struct {
int command;
int speed;
int steeringPower;
} MotorMSGType;
typedef struct {
int16_t rX;
int16_t rY;
int16_t rZ;
int16_t aX;
int16_t aY;
int16_t aZ;
} tIMUdata;
class RoboHeart {
public:
RoboHeart();
RoboHeart(Stream& debug);
~RoboHeart();
bool begin();
void setAutomaticRotation();
char* handleMotorMessage(MotorMSGType motorMSG);
void setDirectionTurnMotors(RoboHeartDRV8836& directionMotor, RoboHeartDRV8836& turnMotor);
float getRotationX();
float getRotationY();
float getRotationZ();
void resetGyro();
RoboHeartStepperMotor stepper;
RoboHeartDRV8836 motorA;
RoboHeartDRV8836 motorB;
RoboHeartDRV8836 motorC;
static LSM6DS3 imu;
static EventGroupHandle_t xIMUeventGroup;
static SemaphoreHandle_t xVarMutex;
static float _rotationX;
static float _rotationY;
static float _rotationZ;
static bool tick;
static tIMUdata imuData;
float getTemperatureC();
float getTemperatureF();
void setPWM(int motor, int freq, int pwm);
static void computeEulerRates(float omega_x, float omega_y, float omega_z, float phi, float theta, float* dphi, float* dtheta, float* dpsi);
static void rungeKutta4(float* phi, float* theta, float* psi, float omega_x, float omega_y, float omega_z, float dt);
static void rungeKutta2(float* phi, float* theta, float* psi, float omega_x, float omega_y, float omega_z, float dt);
static void IMUgetDataTask(void *pvParameter);
static void IMUcalculateDataTask(void *pvParameter);
private:
Stream* _debug = NULL;
RoboHeartDRV8836* _turnMotor = NULL;
RoboHeartDRV8836* _directionMotor = NULL;
};
#endif