View: 180|Reply: 2

PiCar AWR 4WD smart robot, Bug with "Auto Matic" function

[Copy link]

1

Threads

3

Posts

21

Credits

Newbie

Rank: 1

Credits
21
Post time 2021-10-20 16:46:23 | Show all posts |Read mode
Edited by 1634718277 at 2021-10-27 01:20 PM

Hello,

Thank you ...
Reply

Use magic Report

1

Threads

3

Posts

21

Credits

Newbie

Rank: 1

Credits
21
 Author| Post time 2021-10-22 21:34:11 | Show all posts
Edited by 1634718277 at 2021-10-22 09:50 PM

Hello,

My testing allowed me to determine that the problem was with a deadlock in the checkdist () function of the ultra.py module. Indeed the error happens because the GPIO.input (Ec) remains at 0 in the test of the first loop where it must go to 1. The error makes the loop infinite and the thread is blocked.
The main reason for triggering this anomaly is an obstacle placed on the ultrasonic. By the way, that's how I trigger it in a test by putting my hand on it.

Below is the original module that allows the error

  1. #! / usr / bin / python3
  2. # File name: Ultrasonic.py
  3. # Description: Detection distance and tracking with ultrasonic
  4. # Website: <a href="http://www.adeept.com" target="_blank">www.adeept.com</a>
  5. # E-mail: <a href="mailto:support@adeept.com">support@adeept.com</a>
  6. # Author: William
  7. # Date: 2019/02/23
  8. import RPi.GPIO as GPIO
  9. import time

  10. Tr = 11
  11. Ec = 8

  12. def checkdist (): #Reading distance
  13.     GPIO.setwarnings (False)
  14.     GPIO.setmode (GPIO.BCM)
  15.     GPIO.setup (Tr, GPIO.OUT, initial = GPIO.LOW)
  16.     GPIO.setup (Ec, GPIO.IN)
  17.     GPIO.output (Tr, GPIO.HIGH)
  18.     time.sleep (0.000015)
  19.     GPIO.output (Tr, GPIO.LOW)
  20.     while not GPIO.input (Ec):
  21.         pass
  22.     t1 = time.time ()
  23.     while GPIO.input (Ec):
  24.         pass
  25.     t2 = time.time ()
  26.     return (t2-t1) * 340/2>
Copy the Code

My tinkering led me to transform the module to unlock the "while not GPIO.input (Ec):" loop during the error.

  1. #! / usr / bin / python3
  2. # File name: Ultrasonic.py
  3. # Description: Detection distance and tracking with ultrasonic
  4. # Website: <a href="http://www.adeept.com" target="_blank">www.adeept.com</a>
  5. # E-mail: <a href="mailto:support@adeept.com">support@adeept.com</a>
  6. # Author: William
  7. # Date: 2019/02/23

  8. import RPi.GPIO as GPIO
  9. import time

  10. Tr = 11
  11. Ec = 8
  12. #dist = 0

  13. def checkdist (): #Reading distance
  14.     GPIO.setwarnings (False)
  15.     GPIO.setmode (GPIO.BCM)
  16.     GPIO.setup (Tr, GPIO.OUT, initial = GPIO.LOW)
  17.     GPIO.setup (Ec, GPIO.IN)
  18.     GPIO.output (Tr, GPIO.HIGH)
  19.     time.sleep (0.000015)
  20.     GPIO.output (Tr, GPIO.LOW)

  21.     global Error, totErr
  22.    
  23.     try:
  24.         if totErr == 0:
  25.             pass
  26.     except:
  27.         Error = False
  28.         totErr = 0
  29.    
  30.     # giec = 0
  31.     t0 = time.time ()
  32.     # while not giec:
  33.     while not GPIO.input (Ec):
  34.         # giec = GPIO.input (Ec)
  35.         if time.time () - t0> 1:
  36.             # giec = 1
  37.             Error = True
  38.             totErr + = 1
  39.             print (Error, 'totErr:', totErr)
  40.             print ('forced b1 output')
  41.             break
  42.         pass
  43.     t1 = time.time ()
  44.     #print ('t1:', t1)
  45.     #while giec:
  46.     while GPIO.input (Ec):
  47.         # giec = GPIO.input (Ec)
  48.         pass
  49.     t2 = time.time ()
  50.     # print ('t2:', t2)
  51.     # dist = (t2-t1) * 340 / 2A
  52.     #print ('(t2-t1) * 340/2', dist)
  53.     print (Error, 'totErr:', totErr)
  54.    
  55.     return (t2-t1) * 340/2

  56. Regarding the lines below, despite my multiple attempts I have not succeeded in making the Error and totErr variables initialized at the start of the main webServer.py module global.
  57. I'm sorry for the slowness of my python learning.

  58. <
  59. global Error, totErr
  60.    
  61.     try:
  62.         if totErr == 0:
  63.             pass
  64.     except:
  65.         Error = False
  66.         totErr = 0
Copy the Code

Regarding the lines below, despite my multiple attempts I have not succeeded in making the Error and totErr variables initialized at the start of the main webServer.py module global.
I'm sorry for the slow pace of my python learning.
  1. <div>global Error, totErr
  2.    
  3.     try:
  4.         if totErr == 0:
  5.             pass
  6.     except:
  7.         Error = False
  8.         totErr = 0</div>
Copy the Code





Once the module has been cleaned of all debugging lines, it remains

  1. #! / usr / bin / python3
  2. # File name: Ultrasonic.py
  3. # Description: Detection distance and tracking with ultrasonic
  4. # Website: <a href="http://www.adeept.com" target="_blank">www.adeept.com</a>
  5. # E-mail: <a href="mailto:support@adeept.com">support@adeept.com</a>
  6. # Author: William
  7. # Date: 2019/02/23

  8. import RPi.GPIO as GPIO
  9. import time

  10. Tr = 11
  11. Ec = 8

  12. def checkdist (): #Reading distance
  13.     GPIO.setwarnings (False)
  14.     GPIO.setmode (GPIO.BCM)
  15.     GPIO.setup (Tr, GPIO.OUT, initial = GPIO.LOW)
  16.     GPIO.setup (Ec, GPIO.IN)
  17.     GPIO.output (Tr, GPIO.HIGH)
  18.     time.sleep (0.000015)
  19.     GPIO.output (Tr, GPIO.LOW)

  20.     t0 = time.time ()
  21.     while not GPIO.input (Ec):
  22.         if time.time () - t0> 1:
  23.             break
  24.         pass
  25.     t1 = time.time ()
  26.     while GPIO.input (Ec):
  27.         pass
  28.     t2 = time.time ()

  29.     return (t2-t1) * 340/2
Copy the Code

There is certainly a much more elegant solution to solving the problem.
Reply

Use magic Report

1

Threads

3

Posts

21

Credits

Newbie

Rank: 1

Credits
21
 Author| Post time 2021-10-22 21:52:19 | Show all posts
Edited by 1634718277 at 2021-10-22 09:55 PM

Hello,

My testing allowed me to determine that the problem was with a deadlock in the checkdist () function of the ultra.py module. Indeed the error happens because the GPIO.input (Ec) remains at 0 in the test of the first loop where it must go to 1. The error makes the loop infinite and the thread is blocked.
The main reason for triggering this anomaly is an obstacle placed on the ultrasonic. By the way, that's how I trigger it in a test by putting my hand on it.

Below is the original module that allows the error

  1. <
  2. #! / usr / bin / python3
  3. # File name: Ultrasonic.py
  4. # Description: Detection distance and tracking with ultrasonic
  5. # Website: <a href="http://www.adeept.com" target="_blank">www.adeept.com</a>
  6. # E-mail: <a href="mailto:support@adeept.com">support@adeept.com</a>
  7. # Author: William
  8. # Date: 2019/02/23
  9. import RPi.GPIO as GPIO
  10. import time

  11. Tr = 11
  12. Ec = 8

  13. def checkdist (): #Reading distance
  14.     GPIO.setwarnings (False)
  15.     GPIO.setmode (GPIO.BCM)
  16.     GPIO.setup (Tr, GPIO.OUT, initial = GPIO.LOW)
  17.     GPIO.setup (Ec, GPIO.IN)
  18.     GPIO.output (Tr, GPIO.HIGH)
  19.     time.sleep (0.000015)
  20.     GPIO.output (Tr, GPIO.LOW)
  21.     while not GPIO.input (Ec):
  22.         pass
  23.     t1 = time.time ()
  24.     while GPIO.input (Ec):
  25.         pass
  26.     t2 = time.time ()
  27.     return (t2-t1) * 340/2
  28. >
Copy the Code



My tinkering led me to transform the module to unblock the "while not GPIO.input (Ec):" loop during the error.

  1. #! / usr / bin / python3
  2. # File name: Ultrasonic.py
  3. # Description: Detection distance and tracking with ultrasonic
  4. # Website: <a href="http://www.adeept.com" target="_blank">www.adeept.com</a>
  5. # E-mail: <a href="mailto:support@adeept.com">support@adeept.com</a>
  6. # Author: William
  7. # Date: 2019/02/23

  8. import RPi.GPIO as GPIO
  9. import time

  10. Tr = 11
  11. Ec = 8
  12. #dist = 0

  13. def checkdist (): #Reading distance
  14.     GPIO.setwarnings (False)
  15.     GPIO.setmode (GPIO.BCM)
  16.     GPIO.setup (Tr, GPIO.OUT, initial = GPIO.LOW)
  17.     GPIO.setup (Ec, GPIO.IN)
  18.     GPIO.output (Tr, GPIO.HIGH)
  19.     time.sleep (0.000015)
  20.     GPIO.output (Tr, GPIO.LOW)

  21.     global Error, totErr
  22.    
  23.     try:
  24.         if totErr == 0:
  25.             pass
  26.     except:
  27.         Error = False
  28.         totErr = 0
  29.    
  30.     # giec = 0
  31.     t0 = time.time ()
  32.     # while not giec:
  33.     while not GPIO.input (Ec):
  34.         # giec = GPIO.input (Ec)
  35.         if time.time () - t0> 1:
  36.             # giec = 1
  37.             Error = True
  38.             totErr + = 1
  39.             print (Error, 'totErr:', totErr)
  40.             print ('forced b1 output')
  41.             break
  42.         pass
  43.     t1 = time.time ()
  44.     #print ('t1:', t1)
  45.     #while giec:
  46.     while GPIO.input (Ec):
  47.         # giec = GPIO.input (Ec)
  48.         pass
  49.     t2 = time.time ()
  50.     # print ('t2:', t2)
  51.     # dist = (t2-t1) * 340 / 2A
  52.     #print ('(t2-t1) * 340/2', dist)
  53.     print (Error, 'totErr:', totErr)
  54.    
  55.     return (t2-t1) * 340/2
Copy the Code



Regarding the lines below, despite my multiple attempts I have not succeeded in making the Error and totErr variables initialized at the start of the main webServer.py module global.
I'm sorry for the slow pace of my python learning.

  1. global Error, totErr
  2.    
  3.     try:
  4.         if totErr == 0:
  5.             pass
  6.     except:
  7.         Error = False
  8.         totErr = 0
Copy the Code

Once the module has been cleaned of all debugging lines, it remains

  1. #! / usr / bin / python3
  2. # File name: Ultrasonic.py
  3. # Description: Detection distance and tracking with ultrasonic
  4. # Website: <a href="http://www.adeept.com" target="_blank">www.adeept.com</a>
  5. # E-mail: <a href="mailto:support@adeept.com">support@adeept.com</a>
  6. # Author: William
  7. # Date: 2019/02/23

  8. import RPi.GPIO as GPIO
  9. import time

  10. Tr = 11
  11. Ec = 8

  12. def checkdist (): #Reading distance
  13.     GPIO.setwarnings (False)
  14.     GPIO.setmode (GPIO.BCM)
  15.     GPIO.setup (Tr, GPIO.OUT, initial = GPIO.LOW)
  16.     GPIO.setup (Ec, GPIO.IN)
  17.     GPIO.output (Tr, GPIO.HIGH)
  18.     time.sleep (0.000015)
  19.     GPIO.output (Tr, GPIO.LOW)

  20.     t0 = time.time ()
  21.     while not GPIO.input (Ec):
  22.         if time.time () - t0> 1:
  23.             break
  24.         pass
  25.     t1 = time.time ()
  26.     while GPIO.input (Ec):
  27.         pass
  28.     t2 = time.time ()

  29.     return (t2-t1) * 340/2
Copy the Code


There is certainly a much more elegant solution to solving the problem.
Reply

Use magic Report

You have to log in before you can reply Login | Sign Up

Points Rules