-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathTrapezoidalPlanner.h
43 lines (36 loc) · 1.25 KB
/
TrapezoidalPlanner.h
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
#pragma once
#include "common/base_classes/FOCMotor.h"
/**
* Trapezoidal planner
*
* Very simple class to demonstrate higher level control on top of the FOC library.
*
* This class is used to generate trapezoidal velocity profiles for the motor.
* Configure the motor in MotionControlMode::velocity. Link the motor to the planner,
* and set the target angle. The planner will take care of controlling the motor
* velocity to follow a trapezoidal profile.
* Call the run() method in the loop, and use the return value to update the motor
* target velocity. Call the trapezoidal planner less frequently than the motor.move()
* method, to ensure the motor has time to reach the target velocity.
*
*/
class TrapezoidalPlanner {
public:
TrapezoidalPlanner(float max, float accel, float decel = NOT_SET, float min = NOT_SET);
~TrapezoidalPlanner();
void linkMotor(FOCMotor& motor);
void setTarget(float target);
float getTarget() { return target; };
float run();
float arrived_distance = 0.02f;
float arrived_velocity = 0.2f;
float max_velocity;
float min_velocity;
float accel;
float decel;
protected:
FOCMotor* motor;
float target = NOT_SET;
float last_target = NOT_SET;
float start_ang = 0.0f;
};