-
Notifications
You must be signed in to change notification settings - Fork 2
/
SwerveDriveFunctions.cpp
166 lines (144 loc) · 3.96 KB
/
SwerveDriveFunctions.cpp
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <vector>
#define TITLE(A) cout<<""#A<<":\n";
/** !!!!!!!Notice!!!!!!!
This method of driving has been put
on hold until further notice
!!!!!!!Notice!!!!!!! **/
using namespace std;
struct Point {
float x;
float y;
};
struct Wheel {
Point location;
float angle;
float radius;
float power;
};
struct Joystick {
Point p;
float theta;
};
Point operator -(Point point1, Point point2) {
Point point3;
point3.x = point1.x-point2.x;
point3.y = point1.y-point2.y;
return point3;
}
ostream & operator<<(ostream&o,Joystick js){
o<<js.p.x<<"\n"<<js.p.y<<"\n"<<js.theta;
return o;
}
float turnRad(Point wheel, Point point) {
Point test = wheel-point;
return sqrt(test.x*test.x+test.y*test.y);
}
float wheelAngle(Point wheel, Point point) {
Point test = wheel-point;
return atan2(test.y,test.x)/(2*M_PI)*360+90;
}
float input(string prompt) {
string geti;
std::cout<<prompt<<": ";
getline(cin,geti);
std::cout<<"\n";
float i = atof(geti.c_str());
return i;
}
float wheelPower(float thisRadius, float maxRadius) {
return (thisRadius/maxRadius)*100;
}
void wheelSetup(Wheel &wheel, float inX, float inY, Point cent_rotat) {
wheel.location.x = inX;
wheel.location.y = inY;
wheel.radius = turnRad(wheel.location,cent_rotat);
wheel.angle = wheelAngle(wheel.location,cent_rotat);
}
float maxRad(float Rad1, float Rad2, float Rad3) {
float test = max(Rad1, Rad2);
return max(test, Rad3);
}
int main(){
Wheel joyStick;
Point center;
center.x = 0;
center.y = 0;
float J1X;
float J1Y;
float angleA;
Joystick testA;
testA.p.x = 0;
testA.p.y = 0;
testA.theta = 0;
Joystick testB;
testB.p.x = 1;
testB.p.y = 1;
testB.theta = 1;
Joystick testC;
testC.p.x = -1;
testC.p.y = -1;
testC.theta = -1;
Joystick testD
vector <Joystick> JoyTests;
JoyTests.push_back(testA);
JoyTests.push_back(testB);
JoyTests.push_back(testC);
for(unsigned i = 0; i < JoyTests.size(); i++) {
std::cout<<JoyTests[i]<<"\n";
std::cout<<wheelAngle(JoyTests[i].p,center)<<"\n";
}
/**while (J1X != 0 || J1Y != 0) {
J1X = input();
J1Y = input();
//float theta = input();
wheelSetup(joyStick, -J1X, -J1Y, center);
if (joyStick.angle < 0) {
joyStick.angle = 360 + joyStick.angle;
}
//std::cout<<joyStick.angle<<"\n";
if(joyStick.angle < 45) {
angleA = joyStick.angle;
}else if(joyStick.angle < 90) {
angleA = 90 - joyStick.angle;
}else if(joyStick.angle < 135) {
angleA = joyStick.angle - 90;
}else if(joyStick.angle < 180) {
angleA = 180 - joyStick.angle;
}else if(joyStick.angle < 225) {
angleA = joyStick.angle - 180;
}else if(joyStick.angle < 270) {
angleA = 270 - joyStick.angle;
}else if(joyStick.angle < 315) {
angleA = joyStick.angle - 270;
}else{
angleA = 360 - joyStick.angle;
}
std::cout<<angleA<<"\n";
}
/**Point cent_rotat;
cent_rotat.x = input();
cent_rotat.y = input();
Wheel wheel_left;
wheelSetup(wheel_left,-14.6,8.5,cent_rotat);
Wheel wheel_right;
wheelSetup(wheel_right,14.6,8.5,cent_rotat);
Wheel wheel_back;
wheelSetup(wheel_back,0,-17,cent_rotat);
float referenceMax = maxRad(wheel_left.radius,wheel_right.radius,wheel_back.radius);
wheel_left.power = wheelPower(wheel_left.radius,referenceMax);
wheel_right.power = wheelPower(wheel_right.radius,referenceMax);
wheel_back.power = wheelPower(wheel_back.radius,referenceMax);
//std::cout<<wheel_left.x<<" "<<wheel_left.y<<"\n";
std::cout<<"Left wheel's turn radius: "<<wheel_left.radius<<"\n";
std::cout<<"Left wheel's turn angle: "<<wheel_left.angle<<"\n";
std::cout<<"Left wheel's power: "<<wheel_left.power<<"\n";
std::cout<<"Right wheel's turn radius: "<<wheel_right.radius<<"\n";
std::cout<<"Right wheel's turn angle: "<<wheel_right.angle<<"\n";
std::cout<<"Right wheel's power: "<<wheel_right.power<<"\n";
std::cout<<"Back wheel's turn radius: "<<wheel_back.radius<<"\n";
std::cout<<"Back wheel's turn angle: "<<wheel_back.angle<<"\n";
std::cout<<"Back wheel's power: "<<wheel_back.power<<"\n";**/
}