2019-11-11 22:26:34 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
2020-02-29 22:10:53 +01:00
|
|
|
|
|
|
|
#include "behaviour_control/complementary_filter.h"
|
|
|
|
#include "motors_movement/motor.h"
|
|
|
|
|
2020-02-17 19:14:48 +01:00
|
|
|
#include "PID_v2.h"
|
2020-02-29 22:10:53 +01:00
|
|
|
|
2019-11-11 22:26:34 +01:00
|
|
|
|
2020-12-23 21:23:03 +01:00
|
|
|
//BEST NUMBERS YET
|
|
|
|
//USE MOVING AVERAGE AND ANGLE WRAP
|
2021-06-23 15:34:57 +02:00
|
|
|
#define KP 1.0
|
2021-06-22 20:53:11 +02:00
|
|
|
#define KI 0.5
|
2021-02-22 18:43:43 +01:00
|
|
|
#define KD 0.025
|
2020-01-29 18:56:49 +01:00
|
|
|
|
2020-02-21 13:37:32 +01:00
|
|
|
#define KSPD 0.3
|
|
|
|
|
2020-01-29 18:56:49 +01:00
|
|
|
#define UNLOCK_THRESH 800
|
2019-11-11 22:26:34 +01:00
|
|
|
|
2021-04-14 15:00:43 +02:00
|
|
|
//Max possible vel 310
|
|
|
|
|
2021-06-23 15:34:57 +02:00
|
|
|
#define MAX_VEL 110
|
2021-04-14 15:00:43 +02:00
|
|
|
#define MAX_VEL_EIGTH ((int)MAX_VEL*0.8)
|
|
|
|
#define MAX_VEL_HALF ((int)MAX_VEL*0.5)
|
|
|
|
#define MAX_VEL_3QUARTERS ((int)MAX_VEL*0.75)
|
|
|
|
#define MAX_VEL_QUARTER ((int)MAX_VEL*0.25)
|
2021-03-01 18:35:54 +01:00
|
|
|
|
2021-05-13 19:14:45 +02:00
|
|
|
//#define DRIVE_VECTOR_SUM
|
|
|
|
|
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-02-10 19:55:56 +01:00
|
|
|
void prepareDrive(int dir, int speed, int tilt=0);
|
2019-11-11 22:26:34 +01:00
|
|
|
void drivePrepared();
|
2021-06-22 10:39:14 +02:00
|
|
|
int directionAccountingForTilt(int, int);
|
2019-11-11 22:26:34 +01:00
|
|
|
float updatePid();
|
2019-11-18 14:37:55 +01:00
|
|
|
float torad(float f);
|
2021-04-14 15:00:43 +02:00
|
|
|
void resetDrive();
|
2021-05-07 21:39:03 +02:00
|
|
|
void stopAll();
|
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-11-11 22:26:34 +01:00
|
|
|
Motor* m1;
|
|
|
|
Motor* m2;
|
|
|
|
Motor* m3;
|
|
|
|
Motor* m4;
|
2020-03-03 11:52:39 +01:00
|
|
|
|
|
|
|
private:
|
2020-02-10 19:48:31 +01:00
|
|
|
PID* pid;
|
2020-02-26 18:56:39 +01:00
|
|
|
ComplementaryFilter* speedFilter;
|
2021-02-22 18:43:43 +01:00
|
|
|
ComplementaryFilter* dirFilter;
|
2020-02-21 13:37:32 +01:00
|
|
|
int pDir, pSpeed, pTilt, oldSpeed;
|
2020-02-17 19:14:48 +01:00
|
|
|
float x, y, vx, vy, speed1, speed2, speed3, speed4, pidfactor, delta;
|
|
|
|
|
2020-02-10 19:48:31 +01:00
|
|
|
double input, output, setpoint;
|
2019-11-11 22:26:34 +01:00
|
|
|
|
|
|
|
};
|