-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMotor.cpp
More file actions
108 lines (91 loc) · 2.13 KB
/
Copy pathMotor.cpp
File metadata and controls
108 lines (91 loc) · 2.13 KB
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
/*
*This software includes the work that is distributed in the Apache License 2.0
*/
#include "Motor.h"
Motor::Motor()
{
init();
}
void Motor::init()
{
_duty_cycle = 0.0f;
_state = (State)default_state;
_rise_level = (DutyCycleChangeLevel)default_duty_cycle_chenge_level;
_fall_level = (DutyCycleChangeLevel)default_duty_cycle_chenge_level;
_pulse_period = default_pulse_period;
_release_time_ms = defalut_release_time_ms;
_control = (Control)default_control;
}
void Motor::duty_cycle(float value)
{
if ((0.00f <= value) && (value <= 1.00f))
{
_duty_cycle = value;
}
}
float Motor::duty_cycle() const
{
return _duty_cycle;
}
void Motor::state(int type)
{
if ((0 <= type) && (type < TotalState))
{
_state = (State)type;
}
}
int Motor::state() const
{
return _state;
}
void Motor::rise_level(int level)
{
if ((0 <= level) && (level < TotalDutyCycleChangeLevel))
{
_rise_level = (DutyCycleChangeLevel)level;
}
}
int Motor::rise_level() const
{
return _rise_level;
}
void Motor::fall_level(int level)
{
if ((0 <= level) && (level < TotalDutyCycleChangeLevel))
{
_fall_level = (DutyCycleChangeLevel)level;
}
}
int Motor::fall_level() const
{
return _fall_level;
}
void Motor::pulse_period(float seconds)
{
if ((0 < seconds) && (seconds <= max_pulse_period))
{
_pulse_period = seconds;
}
}
void Motor::frequency(float hz)
{
pulse_period(1.0f / hz);
}
void Motor::release_time_ms(float ms)
{
_release_time_ms = ms;
}
void Motor::control(int value)
{
if ((0 <= value) && (value < TotalControl))
{
_control = (Control)value;
}
}
const int Motor::default_state = Brake;
const int Motor::default_duty_cycle_chenge_level = OFF;
const float Motor::default_pulse_period = 0.00002f;
const float Motor::default_frequency = 1.0f / default_pulse_period;
const float Motor::defalut_release_time_ms = 100.0f;
const int Motor::default_control = SlowDecay;
const float Motor::max_pulse_period = 60000.0f;