ME 405 Romi
Loading...
Searching...
No Matches
motor_encoder_right_class.py
Go to the documentation of this file.
1
from
motor
import
Motor
2
from
encoder
import
Encoder
3
from
pyb
import
Timer, Pin
4
# yield the state it completed
5
10
class
motor_encoder_right_class
:
11
12
22
def
__init__
(self, motor, encoder, m_state_r, position_r, velocity_r, times, PWM_r, delay):
23
self.
my_motor_Right
= motor
24
self.
encoder_Right
= encoder
25
self.
m_state_r
= m_state_r
26
self.
position_r
= position_r
27
self.
velocity_r
= velocity_r
28
self.
times
= times
29
self.
PWM_r
= PWM_r
30
self.
delay_count
= 0
31
self.
state
= 0
32
self.
delay
=delay
33
34
47
48
def
run
(self):
49
while
True
:
50
51
# state 0 initialize
52
53
if
self.
state
== 0:
54
self.
my_motor_Right
.enable()
55
56
self.
state
= 1
57
self.
m_state_r
.put(0)
58
yield
0
59
60
# state 1 wait for next state
61
elif
self.
state
== 1:
62
self.
encoder_Right
.update()
63
self.
position_r
.put(self.
encoder_Right
.get_position())
64
self.
velocity_r
.put(self.
encoder_Right
.get_velocity())
65
# Check share from UI for what to do with motor next
66
if
self.
m_state_r
.get() != 0:
67
self.
state
= self.
m_state_r
.get()
68
yield
1
69
# state 2 Right set effort
70
elif
self.
state
== 2:
71
self.
encoder_Right
.update()
72
self.
position_r
.put(self.
encoder_Right
.get_position())
73
self.
velocity_r
.put(self.
encoder_Right
.get_velocity())
74
self.
my_motor_Right
.set_effort(self.
PWM_r
.get())
75
#self.my_motor_Right.set_effort(50)
76
#print(f"PWM RIGHT IN MOTOR: {self.PWM_r.get()}")
77
#print("PWM RIGHT IN MOTOR: 50")
78
self.
m_state_r
.put(0)
79
self.
state
=1
80
yield
2
81
# State 3 Rigth disable
82
elif
self.
state
== 3:
83
self.
my_motor_Right
.disable()
84
self.
m_state_r
.put(0)
85
self.
state
= 4
86
yield
3
87
# State 4 Right Enable Wait
88
elif
self.
state
== 4:
89
if
self.
m_state_r
.get() == 4:
90
self.
my_motor_Right
.enable()
91
self.
m_state_r
.put(0)
92
self.
state
= 1
93
yield
4
94
# State 5
95
elif
self.
state
== 5:
96
self.
my_motor_Right
.set_effort(0)
97
self.
encoder_Right
.zero()
98
self.
delay_count
+= 1
99
if
self.
delay_count
== 100:
100
self.
delay_count
= 0
101
self.
state
= 1
102
self.
m_state_r
.put(1)
103
self.
delay
.put(1)
104
# print("m_state_2")
105
# print(self.m_state_r.get())
106
yield
5
107
else
:
108
raise
ValueError(
"Not that many states"
)
109
yield
self.
state
motor_encoder_right_class.motor_encoder_right_class
Right Motor Encoder Class.
Definition
motor_encoder_right_class.py:10
motor_encoder_right_class.motor_encoder_right_class.encoder_Right
encoder_Right
Definition
motor_encoder_right_class.py:24
motor_encoder_right_class.motor_encoder_right_class.velocity_r
velocity_r
Definition
motor_encoder_right_class.py:27
motor_encoder_right_class.motor_encoder_right_class.state
int state
Definition
motor_encoder_right_class.py:31
motor_encoder_right_class.motor_encoder_right_class.times
times
Definition
motor_encoder_right_class.py:28
motor_encoder_right_class.motor_encoder_right_class.PWM_r
PWM_r
Definition
motor_encoder_right_class.py:29
motor_encoder_right_class.motor_encoder_right_class.position_r
position_r
Definition
motor_encoder_right_class.py:26
motor_encoder_right_class.motor_encoder_right_class.delay_count
int delay_count
Definition
motor_encoder_right_class.py:30
motor_encoder_right_class.motor_encoder_right_class.__init__
__init__(self, motor, encoder, m_state_r, position_r, velocity_r, times, PWM_r, delay)
Right Encoder Initialization.
Definition
motor_encoder_right_class.py:22
motor_encoder_right_class.motor_encoder_right_class.delay
delay
Definition
motor_encoder_right_class.py:32
motor_encoder_right_class.motor_encoder_right_class.my_motor_Right
my_motor_Right
Definition
motor_encoder_right_class.py:23
motor_encoder_right_class.motor_encoder_right_class.m_state_r
m_state_r
Definition
motor_encoder_right_class.py:25
motor_encoder_right_class.motor_encoder_right_class.run
run(self)
Runs the tasks for the Right Motor.
Definition
motor_encoder_right_class.py:48
vscode_python
motor_encoder_right_class.py
Generated by
1.15.0