SPQR-Team1-2020/include/motors_movement/drivecontroller.h

54 lines
1.1 KiB
C
Raw Normal View History

#pragma once
#include <Arduino.h>
#include "behaviour_control/complementary_filter.h"
#include "motors_movement/motor.h"
2020-02-17 19:14:48 +01:00
#include "PID_v2.h"
//PID Constants
2020-02-17 19:14:48 +01:00
#define KP 1.5
#define KI 0.2
2020-02-19 17:44:31 +01:00
#define KD 0.1
#define KSPD 0.3
//BEST NUMBERS YET
//USE MOVING AVERAGE AND ANGLE WRAP
// #define KP 1.5
// #define KI 0
// #define KD 0.1
#define UNLOCK_THRESH 800
class DriveController{
public:
DriveController(Motor* m1_, Motor* m2_, Motor* m3_, Motor* m4_);
2019-11-13 16:26:03 +01:00
void drive(int dir=0, int speed=0, int tilt=0);
void prepareDrive(int dir, int speed, int tilt=0);
void drivePrepared();
float updatePid();
2019-11-18 14:37:55 +01:00
float torad(float f);
int vxp, vyp, vxn, vyn;
bool canUnlock;
unsigned long unlockTime;
Motor* m1;
Motor* m2;
Motor* m3;
Motor* m4;
2020-03-03 11:52:39 +01:00
private:
PID* pid;
2020-02-26 18:56:39 +01:00
ComplementaryFilter* speedFilter;
int pDir, pSpeed, pTilt, oldSpeed;
2020-02-17 19:14:48 +01:00
float x, y, vx, vy, speed1, speed2, speed3, speed4, pidfactor, delta;
double input, output, setpoint;
};