JMotor
Loading...
Searching...
No Matches
JTwoDTransform.h
Go to the documentation of this file.
1#ifndef J_TWO_D_TRANSFORM_H
2#define J_TWO_D_TRANSFORM_H
3#include <Arduino.h>
13 float x;
17 float y;
21 float theta;
22
24 {
25 return { tIn.x * cos(-theta) - tIn.y * sin(-theta), tIn.x * sin(-theta) + tIn.y * cos(-theta), tIn.theta };
26 }
27
35 static JTwoDTransform fromNice(float fb, float sideways, float turn)
36 {
37 return { fb, -sideways, (float)radians(-turn) };
38 }
39
41 {
42 return t.x;
43 }
44
45 static float getRight(JTwoDTransform t)
46 {
47 return -t.y;
48 }
49
51 {
52 return -degrees(t.theta);
53 }
54
61 {
62
63 this->y = this->y + cos(this->theta) * t.y + sin(this->theta) * t.x;
64 this->x = this->x + cos(this->theta) * t.x + sin(this->theta) * t.y;
65 this->theta = this->theta + t.theta;
66 return *this;
67 }
68
70 {
71 this->y = this->y + t.y;
72 this->theta = this->theta + t.theta;
73 this->x = this->x + t.x;
74 return *this;
75 }
77 {
78 this->y = this->y - t.y;
79 this->theta = this->theta - t.theta;
80 this->x = this->x - t.x;
81 return *this;
82 }
84 {
85 this->y = this->y * t.y;
86 this->theta = this->theta * t.theta;
87 this->x = this->x * t.x;
88 return *this;
89 }
91 {
92 this->y = this->y / t.y;
93 this->theta = this->theta / t.theta;
94 this->x = this->x / t.x;
95 return *this;
96 }
98 {
99 this->y = this->y * v;
100 this->theta = this->theta * v;
101 this->x = this->x * v;
102 return *this;
103 }
105 {
106 this->y = this->y / v;
107 this->theta = this->theta / v;
108 this->x = this->x / v;
109 return *this;
110 }
112 {
113 this->y = -this->y;
114 this->theta = -this->theta;
115 this->x = -this->x;
116 return *this;
117 }
119 {
120 this->y += t.y;
121 this->theta += t.theta;
122 this->x += t.x;
123 return *this;
124 }
126 {
127 this->y -= t.y;
128 this->theta -= t.theta;
129 this->x -= t.x;
130 return *this;
131 }
133 {
134 this->y *= t.y;
135 this->theta *= t.theta;
136 this->x *= t.x;
137 return *this;
138 }
140 {
141 this->y /= t.y;
142 this->theta /= t.theta;
143 this->x /= t.x;
144 return *this;
145 }
147 {
148 this->y *= v;
149 this->theta *= v;
150 this->x *= v;
151 return *this;
152 }
154 {
155 this->y /= v;
156 this->theta /= v;
157 this->x /= v;
158 return *this;
159 }
160
166 float getByNumber(int8_t index)
167 {
168 if (index == 0)
169 return this->x;
170 if (index == 1)
171 return this->y;
172 if (index == 2)
173 return this->theta;
174 return NAN;
175 }
176
181 void setByNumber(int8_t index, float value)
182 {
183 if (index == 0)
184 this->x = value;
185 if (index == 1)
186 this->y = value;
187 if (index == 2)
188 this->theta = value;
189 }
190
194 float sumAbs()
195 {
196 return abs(this->y) + abs(this->x) + abs(this->theta);
197 }
204 void print(bool labels = true, bool newline = false, Stream* serial = &Serial)
205 {
206 if (labels)
207 serial->print("x_fb:");
208 serial->print(x, 5);
209 serial->print(" ");
210 if (labels)
211 serial->print("y_lr:");
212 serial->print(y, 5);
213 serial->print(" ");
214 if (labels)
215 serial->print("rz_ccw:");
216 serial->print(theta, 5);
217 serial->print(" ");
218 if (newline)
219 serial->print("\n");
220 }
221};
222#endif
struct for storing a 2 dimensional transformation. Used for telling a drivetrain how to move.
Definition JTwoDTransform.h:9
JTwoDTransform operator/=(const JTwoDTransform &t)
Definition JTwoDTransform.h:139
JTwoDTransform operator*(const float v)
Definition JTwoDTransform.h:97
JTwoDTransform operator/(const float v)
Definition JTwoDTransform.h:104
float theta
clockwise- | counterclockwise+
Definition JTwoDTransform.h:21
static float getRight(JTwoDTransform t)
Definition JTwoDTransform.h:45
void print(bool labels=true, bool newline=false, Stream *serial=&Serial)
use to print values of transform to serial port
Definition JTwoDTransform.h:204
static JTwoDTransform fromNice(float fb, float sideways, float turn)
converts from a coordinate system that might be more intuitive for some people
Definition JTwoDTransform.h:35
static float getTurnDegreesCW(JTwoDTransform t)
Definition JTwoDTransform.h:50
JTwoDTransform operator/=(const float v)
Definition JTwoDTransform.h:153
JTwoDTransform operator*=(const float v)
Definition JTwoDTransform.h:146
JTwoDTransform operator-()
Definition JTwoDTransform.h:111
float getByNumber(int8_t index)
access the three values based on a numerical index
Definition JTwoDTransform.h:166
JTwoDTransform operator/(const JTwoDTransform &t)
Definition JTwoDTransform.h:90
JTwoDTransform operator+=(const JTwoDTransform &t)
Definition JTwoDTransform.h:118
float sumAbs()
sum of absolute value of the three values
Definition JTwoDTransform.h:194
float x
backwards- | forward+
Definition JTwoDTransform.h:13
JTwoDTransform operator-=(const JTwoDTransform &t)
Definition JTwoDTransform.h:125
JTwoDTransform operator&(const JTwoDTransform &t)
adds the second transform after the first, assuming movement, then rotation
Definition JTwoDTransform.h:60
static JTwoDTransform rotate(JTwoDTransform tIn, float theta)
Definition JTwoDTransform.h:23
JTwoDTransform operator-(const JTwoDTransform &t)
Definition JTwoDTransform.h:76
void setByNumber(int8_t index, float value)
sets one of the three values based on a numerical index
Definition JTwoDTransform.h:181
JTwoDTransform operator*=(const JTwoDTransform &t)
Definition JTwoDTransform.h:132
static float getForwards(JTwoDTransform t)
Definition JTwoDTransform.h:40
JTwoDTransform operator+(const JTwoDTransform &t)
Definition JTwoDTransform.h:69
float y
right- | left+
Definition JTwoDTransform.h:17
JTwoDTransform operator*(const JTwoDTransform &t)
Definition JTwoDTransform.h:83