-
Notifications
You must be signed in to change notification settings - Fork 0
/
Wheel.cpp
48 lines (36 loc) · 1.14 KB
/
Wheel.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
#include "Wheel.h"
Wheel::Wheel(MD *md, double wheel_angle, double position_angle)
{
this->md = md;
this->wheel_angle = wheel_angle;
this->wheel_radius = 0;
this->position_angle = position_angle;
this->position_radius = 1;
}
Wheel::Wheel(MD *md, double wheel_angle, double position_x, double position_y, double wheel_radius)
{
this->md = md;
this->wheel_angle = wheel_angle;
this->wheel_radius = wheel_radius;
set_position(position_x, position_y);
}
void Wheel::set_position(double position_x, double position_y)
{
position_angle = atan2(position_y, position_x);
position_radius = sqrt( position_y * position_y + position_x * position_x );
}
double Wheel::set_wheel_vel(double move_angle, double move_radius, double yaw)
{
double speed;
double moving, rotating;
while(move_angle > M_PI)
move_angle -= 2.0 * M_PI;
moving = cos(wheel_angle - move_angle) * move_radius;
rotating = sin(wheel_angle - position_angle) * yaw * position_radius;
speed = moving + rotating;
return speed;
}
void Wheel::drive(double duty)
{
md->drive(duty);
}