@@ -132,49 +132,23 @@ def reset_state(self):
132
132
self ._ticks_counter = 0
133
133
self ._is_moving = False # resetting moving flag
134
134
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
167
138
168
- # velocity calculation
169
- self._current_timer = time()
139
+ self ._power = power # setting current power
170
140
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 ))
174
147
148
+ # releasing lock on motor
175
149
self ._motor_lock .release ()
176
- """
177
150
151
+ # CALLBACK
178
152
# callback function
179
153
def rotary_callback (self , tick ):
180
154
self ._motor_lock .acquire ()
0 commit comments