Skip to content

Commit ba80ac3

Browse files
committed
Fixed pulses value (switched backward with forward)
1 parent d139a8c commit ba80ac3

File tree

3 files changed

+28
-40
lines changed

3 files changed

+28
-40
lines changed

rotary_encoder/motorencoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def stop(self):
125125
- 1 wheel revolution = 2πR = 2 * π * 30mm = 188.5mm
126126
- 1920 ticks = 188.5mm
127127
- 1 tick = 0.0981mm
128-
- 1 tick : 0.0981mm = x : 1000mm -> x = 10193 ticks aproximately """
128+
- 1 tick : 0.0981mm = x : 1000mm -> x = 10193 ticks approximately """
129129

130130
# callback function
131131
def rotary_callback(self, tick):

rotary_encoder/rotarydecoder.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,31 @@ def __init__(self, pi, feedback_pin_A, feedback_pin_B, callback):
3434
it returns a 1 if the square waves have A leading B because we're moving forward
3535
It returns a -1 if the square waves have B leading A because we're moving backwards
3636
In either case, A is staggered from B by (+-)pi/2 radiants
37+
Note: level = 0 falling edge
38+
1 raising edge
39+
2 from watchdog
3740
3841
+---------+ +---------+ 0
3942
| | | |
4043
A | | | |
4144
| | | |
4245
----+ +---------+ +----------+ 1 # A leading B
43-
+---------+ +---------+ 0 # forward
46+
+---------+ +---------+ 0 # backward
4447
| | | |
4548
B | | | |
4649
| | | |
4750
+---------+ +---------+ +----- 1
51+
52+
+---------+ +---------+ 0
53+
| | | |
54+
A | | | |
55+
| | | |
56+
+---------+ +---------+ +----- 1 # B leading A
57+
+---------+ +---------+ 0 # forward
58+
| | | |
59+
B | | | |
60+
| | | |
61+
----+ +---------+ +----------+ 1
4862
"""
4963
def _pulse(self, gpio, level, tick):
5064
# interrupt comes from pin A
@@ -57,22 +71,25 @@ def _pulse(self, gpio, level, tick):
5771
if (gpio != self._lastGpio): # debounce
5872
self._lastGpio = gpio
5973

74+
# backward (A leading B)
6075
if (gpio == self._feedback_pin_A and level == 1):
6176
if (self._levelB == 0):
62-
self._callback(1) # A leading B, moving forward
63-
self._direction = 1 # forward
77+
self._callback(-1) # A leading B, moving forward
78+
self._direction = -1 # backward
6479
elif (gpio == self._feedback_pin_A and level == 0):
6580
if (self._levelB == 1):
66-
self._callback(1) # A leading B, moving forward
67-
self._direction = 1 # forward
81+
self._callback(-1) # A leading B, moving forward
82+
self._direction = -1 # backward
83+
84+
# forward (B leading A)
6885
elif (gpio == self._feedback_pin_B and level == 1):
6986
if (self._levelA == 0):
70-
self._callback(-1) # B leading A, moving forward
71-
self._direction = -1 # backwards
87+
self._callback(1) # B leading A, moving forward
88+
self._direction = 1 # forward
7289
elif (gpio == self._feedback_pin_B and level == 0):
7390
if (self._levelA == 1):
74-
self._callback(-1) # A leading B, moving forward
75-
self._direction = -1 # forward
91+
self._callback(1) # A leading B, moving forward
92+
self._direction = 1 # forward
7693

7794
def cancel(self):
7895

rotary_encoder/wheelsaxel.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -100,39 +100,10 @@ def control_distance(self, power_left=100, power_right=100, target_distance=0):
100100
self.stop()
101101

102102
""" Motor speed control to travel given distance
103-
in given time adjusting power on motors invididually """
103+
in given time adjusting power on motors """
104104
def control_velocity(self, time_elapse=0, target_distance=0):
105105
pass
106106

107-
# old control distance, trying to adjust power
108-
# def control_distance(self, power_left = 100, power_right = 100, target_distance = 0):
109-
# self._is_moving = True
110-
# delta = 1
111-
#
112-
# while(target_distance > 0):
113-
#
114-
# self._left_motor.control(min(max(power_left * delta, power_left), 100))
115-
# self._right_motor.control(min(max(power_right * delta, power_right), 100))
116-
#
117-
# print("Target distance: " + str(target_distance))
118-
# print("Power left: " + str(power_left * delta))
119-
# print("Power right: " + str(power_right * delta))
120-
#
121-
# sleep(.2)
122-
#
123-
# try:
124-
# delta = self._left_motor.ticks() / self._right_motor.ticks()
125-
# target_distance = target_distance - self.distance()
126-
# except:
127-
# delta = 1
128-
#
129-
# print("delta_ticks: " + str(delta))
130-
# print("new target distance: " + str(target_distance))
131-
# print("")
132-
#
133-
# print("Stopping...")
134-
# self.stop()
135-
136107
""" The stop function calls the two stop functions of the two
137108
correspondent motors.
138109
Locks are automatically obtained """

0 commit comments

Comments
 (0)