64 def __init__(self, fwd_ref, arc_ref, piv_ref, c_state, my_controller_left, my_controller_right,
65 position_l, velocity_l, position_r, velocity_r, PWM_l, PWM_r, encoder_Right, encoder_Left,
66 m_state_l, m_state_r, centroid, line_controller, automatic_mode, line_sensor, need_Calibrate, real_yaw, centroid_goal, yaw_goal, controller_yaw):
80 self.
enc_R = encoder_Right
81 self.
enc_L = encoder_Left
127 if self.automatic_mode.get() == 1:
130 self.line_controller.change_Ref(0)
131 if self.startup == 0:
134 self.enc_R.set_offset(((.141/2))*self.real_yaw.get())
135 self.enc_L.set_offset(-((.141/2))*self.real_yaw.get())
137 elif self.c_state.get() != 0:
138 self.state = self.c_state.get()
141 elif self.state == 1:
142 if self.c_state.get() == 4:
146 self.controller_left.change_Ref(self.fwd_ref.get())
148 self.controller_right.change_Ref(self.fwd_ref.get())
153 elif self.state == 2:
154 if self.c_state.get() == 4:
156 v_r = 15*((2*self.arc_ref.get()+141)/(2*self.arc_ref.get()-141))
157 self.controller_left.change_Ref(15)
158 self.controller_right.change_Ref(v_r)
163 elif self.state == 3:
164 if self.c_state.get() == 4:
166 self.controller_left.change_Ref(-(self.piv_ref.get()*141//2))
169 self.controller_right.change_Ref((self.piv_ref.get()*141//2))
175 elif self.state == 4:
176 print(
"I tried to turn them off")
177 self.controller_left.change_Ref(0)
178 self.controller_right.change_Ref(0)
186 elif self.state == 5:
193 if self.automatic_mode.get() == 0:
195 if self.c_state.get() == 4:
198 if self.centroid_goal.get() != self.line_controller.get_Ref():
199 print(
"Centroid Ref Changed")
200 self.line_controller.change_Ref(self.centroid_goal.get())
201 print(self.line_controller.get_Ref())
203 self.yaw_rate = self.line_controller.pi_Control(self.centroid.get(), 15)
209 self.controller_left.change_Ref(100-self.yaw_rate)
210 self.controller_right.change_Ref(100+self.yaw_rate)
213 elif self.state == 6:
214 if self.need_Calibrate.get() == 0:
221 yaw_actuation = self.controller_yaw.pi_Control(self.yaw_goal.get(), 15)
222 self.controller_left.change_Ref(-yaw_actuation)
223 self.controller_right.change_Ref(yaw_actuation)
225 if self.c_state.get() == 4:
227 if yaw_actuation <= 1:
229 self.controller_left.change_Ref(0)
230 self.controller_right.change_Ref(0)
234 raise ValueError(
"Not that many states")
247 new_left_pwm = self.controller_left.pi_Control(self.velocity_l.get(), self.enc_L.get_dt())
248 new_right_pwm = self.controller_right.pi_Control(self.velocity_r.get(), self.enc_R.get_dt())
258 if new_left_pwm > 0
and new_right_pwm > 0:
260 self.PWM_l.put(new_left_pwm)
261 self.PWM_r.put(new_right_pwm)
262 elif new_left_pwm < 0
and new_right_pwm < 0:
264 self.PWM_l.put(new_left_pwm)
265 self.PWM_r.put(new_right_pwm)
266 elif new_left_pwm > 0
and new_right_pwm < 0:
269 self.PWM_l.put(-new_left_pwm)
270 self.PWM_r.put(-new_right_pwm)
271 elif new_left_pwm < 0
and new_right_pwm > 0:
274 self.PWM_l.put(-new_left_pwm)
275 self.PWM_r.put(-new_right_pwm)
276 elif new_left_pwm != 0
and new_right_pwm == 0:
279 self.PWM_l.put(-new_left_pwm)
281 elif new_left_pwm == 0
and new_right_pwm != 0:
285 self.PWM_r.put(new_right_pwm)
306 self.m_state_l.put(2)
307 self.m_state_r.put(2)
__init__(self, fwd_ref, arc_ref, piv_ref, c_state, my_controller_left, my_controller_right, position_l, velocity_l, position_r, velocity_r, PWM_l, PWM_r, encoder_Right, encoder_Left, m_state_l, m_state_r, centroid, line_controller, automatic_mode, line_sensor, need_Calibrate, real_yaw, centroid_goal, yaw_goal, controller_yaw)