2019-11-11 22:26:34 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
#include "motor.h"
|
2020-02-10 19:48:31 +01:00
|
|
|
#include "PID_v1.h"
|
2019-11-11 22:26:34 +01:00
|
|
|
|
|
|
|
//PID Constants
|
2020-02-10 19:48:31 +01:00
|
|
|
#define KP 1.2
|
|
|
|
#define KI 0.0
|
|
|
|
#define KD 0.25
|
2020-01-29 18:56:49 +01:00
|
|
|
|
|
|
|
#define UNLOCK_THRESH 800
|
2019-11-11 22:26:34 +01:00
|
|
|
|
|
|
|
class DriveController{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
DriveController(Motor* m1_, Motor* m2_, Motor* m3_, Motor* m4_);
|
2019-11-13 16:26:03 +01:00
|
|
|
|
2019-12-09 19:08:05 +01:00
|
|
|
void drive(int dir=0, int speed=0, int tilt=0);
|
2020-01-31 13:35:40 +01:00
|
|
|
void prepareDrive(int dir, int speed, int tilt);
|
|
|
|
void prepareDrive(int dir, int speed);
|
2019-11-11 22:26:34 +01:00
|
|
|
void drivePrepared();
|
|
|
|
float updatePid();
|
2019-11-18 14:37:55 +01:00
|
|
|
float torad(float f);
|
2019-11-11 22:26:34 +01:00
|
|
|
|
2019-12-05 11:53:01 +01:00
|
|
|
int vxp, vyp, vxn, vyn;
|
|
|
|
bool canUnlock;
|
2020-01-29 18:56:49 +01:00
|
|
|
unsigned long unlockTime;
|
2019-12-05 11:53:01 +01:00
|
|
|
|
2019-11-11 22:26:34 +01:00
|
|
|
private:
|
|
|
|
Motor* m1;
|
|
|
|
Motor* m2;
|
|
|
|
Motor* m3;
|
|
|
|
Motor* m4;
|
2020-02-10 19:48:31 +01:00
|
|
|
PID* pid;
|
2019-11-11 22:26:34 +01:00
|
|
|
int pDir, pSpeed, pTilt;
|
2020-02-10 19:48:31 +01:00
|
|
|
int gDir, gSpeed, gTilt;
|
|
|
|
int speed1, speed2, speed3, speed4, errorePre, integral, pidfactor, errorP, errorD, errorI, delta;
|
|
|
|
double input, output, setpoint;
|
2019-11-11 22:26:34 +01:00
|
|
|
int vx, vy;
|
|
|
|
|
|
|
|
float sins[360], cosins[360];
|
|
|
|
|
|
|
|
};
|