TR-mbed 1.0
Loading...
Searching...
No Matches
OmniWheelSubsystem.h
Go to the documentation of this file.
1#pragma once
2
3#include "mbed.h"
4#include <cstdint>
7#include "Subsystem.h"
8#include "TurretSubsystem.h"
9
10#define WHEEL_DIAMETER_METERS 0.146
11#define PI 3.14159265
12
13
15{
16public:
17 struct config
18 {
19 short flid;
20 short frid;
21 short blid;
22 short brid;
23
24 float radius;
26
27 float max_vel = 2.92;
28 float max_accel = 100;
29 float feed_forward = 0.065 * INT16_MAX;
30 float max_beyblade = 4.8;
31
36
38
39 IMU &imu; // We should change this to be of type IMU which will obv have all the same read function
40
41 TurretSubsystem &yaw; // Need to expose turretsubsystem yaw, or just expose the yaw>>ANGLE
42 float initial_angle = 0;
43 float yawAlign = 0;
44 };
45
47 {
48 float vX; // Forward m/s
49 float vY; // Left m/s
50 float vOmega; // Clockwise rad/s
51 };
52
62
64 {
65 ChassisSpeed vel = {0.0, 0.0, 0.0};
67 };
68
69
71
72 inline void setPowerLimit(int powerLimit) {power_limit = powerLimit;};
73
74 void setChassisState(ChassisState state);
75
76 ChassisState getChassisState();
77
86 void setYawReference(TurretSubsystem &_yaw, float initial_offset_ticks = 0, float _yawAlign = 0);
87
93 bool setOdomReference();
94
95 void periodic();
96
97private:
98 struct WheelSpeed
99 {
100 float fl; // rpm
101 float fr; // rpm
102 float bl; // rpm
103 float br; // rpm
104 };
105
106 ChassisState desired_state;
107 ChassisState curr_state;
108
109 WheelSpeed desired_wheelspeed;
110 WheelSpeed curr_wheelspeed;
111
112 unsigned long prev_time;
113 unsigned long dt; // delta time in ms
114
115 int motor_power[4];
116
117
118 DJIMotor fl;
119 DJIMotor fr;
120 DJIMotor bl;
121 DJIMotor br;
122
123 IMU &imu;
124 IMU::EulerAngles imuAngles;
125
126 // We need to establish a yaw encoder reference here for head to body conversion
127 TurretSubsystem &yaw; // pointer to turret for head reference
128 int yawAlign;
129 float yawPhase;
130 float yawOdom;
131 float imuOdom;
132
133 float radius;
134 int power_limit;
135
136 float FF_Ks;
137 float maxVel;
138 float maxAccel;
139 float maxBeyblade;
140
141 // TODO :) (idk if we need em)
142 // void calculateAccelLimit();
143 // void setOmniKinematics();
144
145 // Updates curr_state and curr_wheelspeed from motors
146 void getOmniState();
147
148 // Calculates necessary wheelspeeds for the desired state
149 void setDesiredWheelSpeed();
150
151 // Calculate the ChassisSpeed in the desired frame of reference
152 ChassisSpeed rotateChassisSpeed(ChassisSpeed desired_vel, float frame_angle);
153
154 // Calculate and update the desired wheelSpeed using the rotated chassisSpeed
155 void calculateWheelSpeed(ChassisSpeed chassisSpeeds);
156
157 // Calculate the ChassisSpeed from the current WheelSpeed
158 void calculateChassisSpeed();
159
160 // Sends the power needed for the wheels to reach the desired speeds
161 void sendPower();
162
163 // Bisection
164 float Bisection(int LeftFrontPower, int RightFrontPower, int LeftBackPower, int RightBackPower, int LeftFrontRpm, int RightFrontRpm, int LeftBackRpm, int RightBackRpm, float chassisPowerLimit);
165
166 // p-theory
167 float p_theory(int LeftFrontPower, int RightFrontPower, int LeftBackPower, int RightBackPower, int LeftFrontRpm, int RightFrontRpm, int LeftBackRpm, int RightBackRpm);
168};
CANBus
Definition CANHandler.h:45
Definition DJIMotor.h:47
Definition IMU.h:5
Definition OmniWheelSubsystem.h:15
void setChassisState(ChassisState state)
Definition OmniWheelSubsystem.cpp:58
bool setOdomReference()
Definition OmniWheelSubsystem.cpp:80
ChassisState getChassisState()
Definition OmniWheelSubsystem.cpp:68
ChassisMode
Definition OmniWheelSubsystem.h:54
@ ROBOT_ORIENTED
Definition OmniWheelSubsystem.h:57
@ YAW_ORIENTED
Definition OmniWheelSubsystem.h:55
@ OFF
Definition OmniWheelSubsystem.h:60
@ BEYBLADE
Definition OmniWheelSubsystem.h:56
@ YAW_ALIGNED
Definition OmniWheelSubsystem.h:59
@ ODOM_ORIENTED
Definition OmniWheelSubsystem.h:58
void setPowerLimit(int powerLimit)
Definition OmniWheelSubsystem.h:72
void periodic()
Definition OmniWheelSubsystem.cpp:87
void setYawReference(TurretSubsystem &_yaw, float initial_offset_ticks=0, float _yawAlign=0)
Definition OmniWheelSubsystem.cpp:73
Definition Subsystem.h:5
Definition TurretSubsystem.h:15
Definition IMU.h:8
Definition OmniWheelSubsystem.h:47
float vOmega
Definition OmniWheelSubsystem.h:50
float vX
Definition OmniWheelSubsystem.h:48
float vY
Definition OmniWheelSubsystem.h:49
Definition OmniWheelSubsystem.h:64
ChassisMode mode
Definition OmniWheelSubsystem.h:66
ChassisSpeed vel
Definition OmniWheelSubsystem.h:65
Definition OmniWheelSubsystem.h:18
float max_vel
Definition OmniWheelSubsystem.h:27
PID::config br_vel_config
Definition OmniWheelSubsystem.h:35
PID::config fr_vel_config
Definition OmniWheelSubsystem.h:33
PID::config fl_vel_config
Definition OmniWheelSubsystem.h:32
float feed_forward
Definition OmniWheelSubsystem.h:29
float max_accel
Definition OmniWheelSubsystem.h:28
int power_limit
Definition OmniWheelSubsystem.h:25
PID::config bl_vel_config
Definition OmniWheelSubsystem.h:34
short brid
Definition OmniWheelSubsystem.h:22
float max_beyblade
Definition OmniWheelSubsystem.h:30
CANHandler::CANBus canBus
Definition OmniWheelSubsystem.h:37
float radius
Definition OmniWheelSubsystem.h:24
float yawAlign
Definition OmniWheelSubsystem.h:43
float initial_angle
Definition OmniWheelSubsystem.h:42
short frid
Definition OmniWheelSubsystem.h:20
short flid
Definition OmniWheelSubsystem.h:19
IMU & imu
Definition OmniWheelSubsystem.h:39
TurretSubsystem & yaw
Definition OmniWheelSubsystem.h:41
short blid
Definition OmniWheelSubsystem.h:21
Definition PID.h:154