ME 405 Romi
Loading...
Searching...
No Matches
motor_encoder_left_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
9
class
motor_encoder_left_class
:
10
11
21
def
__init__
(self, motor, encoder, m_state_l, position_l, velocity_l, times, PWM_l, delay):
22
self.
my_motor_Left
= motor
23
self.
encoder_Left
= encoder
24
self.
m_state_l
= m_state_l
25
self.
position_l
= position_l
26
self.
velocity_l
= velocity_l
27
self.
times
= times
28
self.
PWM_l
= PWM_l
29
self.
delay_count
= 0
30
self.
state
= 0
31
self.
delay
=delay
32
33
46
47
def
run
(self):
48
while
True
:
49
# state 0 initialize
50
51
if
self.
state
== 0:
52
self.
my_motor_Left
.enable()
53
54
self.
state
= 1
55
self.
m_state_l
.put(0)
56
yield
0
57
58
# state 1 wait for next state
59
elif
self.
state
== 1:
60
61
self.
encoder_Left
.update()
62
self.
position_l
.put(self.
encoder_Left
.get_position())
63
self.
velocity_l
.put(self.
encoder_Left
.get_velocity())
64
# Check share from UI for what to do with motor next
65
if
self.
m_state_l
.get() != 0:
66
self.
state
= self.
m_state_l
.get()
67
68
yield
1
69
# state 2 Left set effort
70
elif
self.
state
== 2:
71
self.
encoder_Left
.update()
72
self.
position_l
.put(self.
encoder_Left
.get_position())
73
self.
velocity_l
.put(self.
encoder_Left
.get_velocity())
74
self.
my_motor_Left
.set_effort(self.
PWM_l
.get())
75
#self.my_motor_Left.set_effort(100)
76
#print(f"PWM LEFT IN MOTOR: {self.PWM_l.get()}")
77
#print("PWM LEFT IN MOTOR: 50")
78
self.
m_state_l
.put(0)
79
self.
state
=1
80
yield
2
81
# state 3 Left disable
82
elif
self.
state
== 3:
83
self.
my_motor_Left
.disable()
84
self.
m_state_l
.put(0)
85
self.
state
=4
86
yield
3
87
# state 4 left enable wait
88
elif
self.
state
== 4:
89
if
self.
m_state_l
.get() == 4:
90
self.
my_motor_Left
.enable()
91
self.
m_state_l
.put(0)
92
self.
state
= 1
93
yield
4
94
elif
self.
state
== 5:
95
self.
my_motor_Left
.set_effort(0)
96
self.
delay_count
+= 1
97
self.
encoder_Left
.zero()
98
if
self.
delay_count
== 100:
99
self.
delay_count
= 0
100
self.
state
= 1
101
self.
m_state_l
.put(1)
102
self.
delay
.put(1)
103
# print("m_state_1")
104
# print(self.m_state_l.get())
105
106
yield
5
107
else
:
108
raise
ValueError(
"Not that many states"
)
109
yield
self.
state
motor_encoder_left_class.motor_encoder_left_class
Left Motor Encoder Class.
Definition
motor_encoder_left_class.py:9
motor_encoder_left_class.motor_encoder_left_class.position_l
position_l
Definition
motor_encoder_left_class.py:25
motor_encoder_left_class.motor_encoder_left_class.delay_count
int delay_count
Definition
motor_encoder_left_class.py:29
motor_encoder_left_class.motor_encoder_left_class.times
times
Definition
motor_encoder_left_class.py:27
motor_encoder_left_class.motor_encoder_left_class.m_state_l
m_state_l
Definition
motor_encoder_left_class.py:24
motor_encoder_left_class.motor_encoder_left_class.state
int state
Definition
motor_encoder_left_class.py:30
motor_encoder_left_class.motor_encoder_left_class.run
run(self)
Runs the tasks for the Right Motor.
Definition
motor_encoder_left_class.py:47
motor_encoder_left_class.motor_encoder_left_class.delay
delay
Definition
motor_encoder_left_class.py:31
motor_encoder_left_class.motor_encoder_left_class.encoder_Left
encoder_Left
Definition
motor_encoder_left_class.py:23
motor_encoder_left_class.motor_encoder_left_class.my_motor_Left
my_motor_Left
Definition
motor_encoder_left_class.py:22
motor_encoder_left_class.motor_encoder_left_class.velocity_l
velocity_l
Definition
motor_encoder_left_class.py:26
motor_encoder_left_class.motor_encoder_left_class.__init__
__init__(self, motor, encoder, m_state_l, position_l, velocity_l, times, PWM_l, delay)
Right Encoder Initialization.
Definition
motor_encoder_left_class.py:21
motor_encoder_left_class.motor_encoder_left_class.PWM_l
PWM_l
Definition
motor_encoder_left_class.py:28
vscode_python
motor_encoder_left_class.py
Generated by
1.15.0