[SOLVED] right motor encoder issues


#1

I initially thought that I had a hardware problem because a function from the Find a Hole Example was not doing what I expected.

My problem was fixed by changing a line in the control.py file found HERE. Or on the GoPiGo directory at GoPiGo/Software/Python/Examples/Find Hole/control.py

line 42: enc_tgt(0,1,pulse)
change to: enc_tgt(1,0,pulse)

--------------- Original post:
Hello,

I just built the GoPiGo and I believe I might have an issue. The right motor doesn’t stop while using “right_deg(30)” from the Find a Hole example.
Im using a raspberry 2. I enabled I2C.

Steps taken:
Using control.py from Find a Hole example:
https://github.com/DexterInd/GoPiGo/tree/master/Software/Python/Examples/Find%20Hole

sudo python
>>> from gopigo import *
>>> from control import *
>>> left_deg(30)

left motor turns 30 degrees.

>>> right_deg(30)

right motor turns endlessly.

>>> read_status()
[1, 0]
>>> read_enc_status()
1

I have not removed the paper from the encoder wheels. How can I verify if this is a hardware issue?
volts() currently returns 10.2
python enc_val_read.py
0, 0
0, 0
0, 0

Thanks in advance for any info given !


#2

Hey,
An easy way to test if the encoders work for you is run this example: https://github.com/DexterInd/GoPiGo/blob/master/Software/Python/other_scripts/encoder_tgt_complete_test.py . You should gets both the values which slowly increment. Can you also post the output here so we can double check if everything is alright.

-Karan


#3

Hello Karan, Thanks for replying.

HEre is the output of the script:

Ver: 1.1
4.26 V

CHECKING ENCODER READINGS
0 0
Both motors moving Forward with LED On
after 5 sec 0 0
Both motors stopped with LED Off
None after stop cmd 0 0
None after 2 more sec 0 0
Both motors moving back with LED On
after 5 sec 0 0
Both motors stopped with LED Off
None after stop cmd 0 0
None after 2 more sec  0 0

CHECKING ENCODER TARGETING

Initial encoder read vals: 257 257
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  0
Final encoder read vals: 0 0

Initial encoder read vals: 257 257
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  0
Final encoder read vals: 0 0

Initial encoder read vals: 257 257
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  0
Final encoder read vals: 0 0

Initial encoder read vals: 257 257
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  0
Final encoder read vals: 0 0

Initial encoder read vals: 257 257
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  1
Enc tgt Status:  0
Final encoder read vals: 0 0


#4

Hey,
From the output above, there are 2 things that might be causing the problem. One, the voltage is very low. Are you using a 9-12V battery pack and is it charged and two, you have an older firmware on the GoPiGo. To update to a newer firmware, go to the folder here: https://github.com/DexterInd/GoPiGo/tree/master/Firmware on your GoPiGo repo, make the script executable: sudo chmod +x firmware_update.sh and run it sudo ./firmware_update.sh . Make sure that the motors are disconnected before you start. Run the same program again and post the output here.

-Karan


#5

Hello Karan, Just got home and performed the tasks you suggested.

I connected the pi’s micro usb to the laptop and also turned on the gopigo via the batteries.
Here is the output of the enconder test script:

Ver: 1.3
10.79 V

CHECKING ENCODER READINGS
0 0
Both motors moving Forward with LED On
after 5 sec 202 197
Both motors stopped with LED Off
None after stop cmd 210 204
None after 2 more sec 218 209
Both motors moving back with LED On
after 5 sec 411 410
Both motors stopped with LED Off
None after stop cmd 419 418
None after 2 more sec 426 423

CHECKING ENCODER TARGETING

Initial encoder read vals: 0 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 0
Final encoder read vals: 80 79

Initial encoder read vals: 0 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 0
Final encoder read vals: 79 79

Initial encoder read vals: 0 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 0
Final encoder read vals: 79 79

Initial encoder read vals: 0 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 0
Final encoder read vals: 79 79

Initial encoder read vals: 0 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 1
Enc tgt Status: 0
Final encoder read vals: 80 79

I also tested:
>>> import control
>>> control.left_deg(15)
>>> control.left_deg(30)
>>> control.right_deg(30)
>>> control.stop()

but the control.right_deg(30) is still continuing endlessly.

thanks for the help thus far!


#6

also result from python enc_val_read.py
284 42
292 48
299 55
306 62
313 69
320 76
327 83
334 89
341 96
348 103
356 110
363 117
370 124
377 130
384 137
391 144
398 151
405 158
412 164
419 171
426 178
433 185
440 192
448 199
455 205
462 212
469 219
476 226
483 233
490 240
498 246


#7

Hey,
Looks like the encoders are working properly. I think 30 degree might be too small of angle to turn using the encoders. Can you try larger angles and see if that helps. Do the wheels just turn endlessly no matter what input you give? How does left_deg() compare to right_deg().

-Karan


#8

Im able to excecute left_deg(15); the wheel turns for about half a second and then stops.
With right_deg(30) though, the wheel never stops. I’ve waited about 8 to 20 seconds to see what it does. I have also swapped the encoders but nothing changes.

I’ll try to get some debug output from control.py when i get back home to see whats causing it to never stop.

Thanks for the help in confirming that the encoders haven’t gone bananas.


#9

Hello Karan!

I found the problem! I documented it on my first post and updated the subject too…

I’d like to note that there seems to be a typo on the GoPiGo Python documentation Here:
http://www.dexterindustries.com/GoPiGo/programming/python-programming-for-the-raspberry-pi-gopigo/enc_tgt/

It states that for m2 one must input “1” to disable targeting and “1” to enable it.

Thanks a bunch for the help Karan. On to start making this thing do insteresting stuff! :slight_smile:


#10

Hey JPZ,
Thanks for letting is know about the error and extremely sorry for it. We just updated the page and it should be good now.

All the best for you projects and do share it with the community here.

-Karan