@@ -132,49 +132,23 @@ def reset_state(self):
132132 self ._ticks_counter = 0
133133 self ._is_moving = False # resetting moving flag
134134
135- # CALLBACK
136- """ The callback function rotary_callback is called on FALLING_EDGE by the
137- rotary_decoder with a parameter value of 1 (1 new tick)
138-
139- - Gearbox ratio: 120:1 (1 wheel revolution = 120 motor revolution)
140- - Encoder ratio: 16:1 encoder ticks for 1 motor revolution
141- - 1 wheel revolution = 120 * 16 = 1920 ticks
142- - R = 30mm - 1 wheel revolution = 2πR = 2 * π * 30mm = 188.5mm
143- - 1920 ticks = 188.5mm
144- - 1 tick = 0.0981mm
145- - 1 tick : 0.0981mm = x : 1000mm -> x = 10193 ticks approximately
146- So 0.0981 is the ticks->distance(mm) conversion coefficient
147-
148- The callback function calculates current velocity by taking groups of
149- ticks_threshold ticks"""
150-
151- """
152- # callback function
153- # it calculates velocity via approssimation
154- # it doeas a mean on current time passed and actual distance travelled
155- # NOT USEFUL FOR VELOCITY REGULATION since we need to know the current
156- # velocity updated each time
157- def rotary_callback(self, tick):
158- self._motor_lock.acquire()
159-
160- # on first movement
161- if(self._distance == 0):
162- self._start_timer = time() # clock started
163-
164-
165- self._ticks += tick # updating ticks
166- self._distance = self._ticks * 0.0981 # (mm) travelled
135+ # adjust power for velocity control loop
136+ def adjust_power (self , power ):
137+ self ._motor_lock .acquire () # acquiring lock
167138
168- # velocity calculation
169- self._current_timer = time()
139+ self ._power = power # setting current power
170140
171- elapse = self._current_timer - self._start_timer
172- if(elapse != 0):
173- self._encoder_speed = self._distance / elapse #(mm/s)
141+ # adjusting power forward
142+ if (self ._direction == 1 ):
143+ self ._pi .set_PWM_dutycycle (self ._forward_pin , abs (power ))
144+ # adjusting power bacakward
145+ else :
146+ self ._pi .set_PWM_dutycycle (self ._backward_pin , abs (power ))
174147
148+ # releasing lock on motor
175149 self ._motor_lock .release ()
176- """
177150
151+ # CALLBACK
178152 # callback function
179153 def rotary_callback (self , tick ):
180154 self ._motor_lock .acquire ()
0 commit comments