Picar-x calibration motor

Hi, I have this problem with picar-x when calibrating and checking the motors with E (run/stop ) the wheels rotate forward but when I give another E to stop the motors the wheels rotate in different direction to each other and do not stop, when I press control-c and stop the calibration the motors continue to run and resetting ras Pi from the command line does not stop them. Running python3 move.py also causes the motors to keep running even after the program is stopped.

Let the user provide a video of the problem so that we can analyze the problem.
We went to do a reproduction test for your problem and did not encounter your situation.
When you are on the calibration page, select the number keys 4 and 5 to select the left and right motors, press the E key and the cart will move forward normally, press the E key again and the motors will stop working.
When executing the move.py script, after the move.py script finishes running, the program will stop and the motors will stop.

the problem has been solved, the problem was due to the connection of the VL53L0X sensor to I2C on the robot-hat, the VL53L0X was connected but the script.py from reading the values from the sensor during calibration was not running.
On the other hand, an interesting problem is that I wrote a program that reads the distances from the VL53L0X and turns the steering wheel in case of close proximity through the wires and forward/reverse driving.
And when the wires from the wheel motors are connected to the robot-hat then the script crashes and the steering wheel freezes in one position o does not react to changes in the distance of the obstacle. And when script.py is run but the motors are disconnected then script.py does not crash and the steering wheel turns when an obstacle is detected.

It should be that the i2c communication conflict caused the robot_hat’s i2c to hang up. Can you provide the code you wrote? If you don’t want to make it public, you can send it to our email, service@sunfounder.com. Please mark this question link in the email: https://forum .sunfounder.com/t/picar-x-calibration-motor/463/2

the idea is that when the ultrasonic sensor detects an obstacle, the picarx is supposed to stop and turn the camera on which the VL53L0X will be mounted, if the vl53 sensor does not detect an obstacle then it is supposed to turn the wheels and move forward, the code is under construction and at this stage they will hang up while connecting the wires from the motors to the robot-hat, as they are physically disconnected then the picarx will not hang up.
D3- D4 ultrasonic
I2C VL53L0X

import time
from picarx import Picarx
import VL53L0X

def main():
try:
px = Picarx()
vl53 = VL53L0X()

    vl53.start_ranging(VL53L0X.VL53L0X_BETTER_ACCURACY_MODE)

    while True:
        ultrasonic_distance = px.ultrasonic.read()
        vl53_distance = vl53.read()
        
        print("Ultradźwięk: {} cm, VL53L0X: {} mm".format(ultrasonic_distance, vl53_distance))
        
        if ultrasonic_distance < 25:  # Dopasuj wartość odległości ultradźwiękowej według potrzeb
            px.forward(0)  # Zatrzymanie jazdy
            px.set_camera_servo1_angle(30)  # Obrót kamery w prawo
            time.sleep(1)  # Poczekaj chwilę po zatrzymaniu
            
            if vl53_distance >= 250:  # Dopasuj wartość odległości VL53L0X według potrzeb
                px.set_camera_servo1_angle(0)  # Wyzerowanie serwa kamery
                px.turn_right(30)  # Skręt w prawo
                time.sleep(1)  # Poczekaj chwilę po skręcie
                px.turn_left(0)  # Wyzerowanie kierunku
        else:
            px.set_camera_servo1_angle(0)  # Wyzerowanie serwa kamery
            px.forward(30)  # Normalna jazda w przód

        time.sleep(0.1)  # Poczekaj chwilę przed kolejnym odczytem

except KeyboardInterrupt:
    pass
finally:
    px.forward(0)  # Upewnij się, że koła są zatrzymane

if name == “main”:
main()= “main”:
main()

We need to analyze and validate the code you provided. It might take some time before we can get back to you.

sorry, I mistakenly sent another code below is correct, in addition, after reinstalling the raspberry os the problem with robot-hat hanging stopped
I will do some more tests and confirm it.

import time
from picarx import Picarx
import VL53L0X

def main():
try:
px = Picarx()
vl53 = VL53L0X.VL53L0X()

    vl53.start_ranging(VL53L0X.VL53L0X_BETTER_ACCURACY_MODE)

    while True:
        ultrasonic_distance = px.ultrasonic.read()
        vl53_distance = vl53.get_distance()
        
        print("Ultradźwięk: {} cm, VL53L0X: {} mm".format(ultrasonic_distance, vl53_distance))
        
        if ultrasonic_distance < 25:  # Dopasuj wartość odległości ultradźwiękowej według potrzeb
            px.forward(0)  # Zatrzymanie jazdy
            px.set_camera_servo1_angle(30)  # Obrót kamery w prawo
            time.sleep(1)  # Poczekaj chwilę po zatrzymaniu
            
            if vl53_distance >= 250:  # Dopasuj wartość odległości VL53L0X według potrzeb
                px.set_camera_servo1_angle(0)  # Wyzerowanie serwa kamery
                px.set_dir_servo_angle(-35) # Skręt w prawo
                time.sleep(1)  # Poczekaj chwilę po skręcie
                px.set_dir_servo_angle(0)  # Wyzerowanie kierunku
        else:
            px.set_camera_servo1_angle(0)  # Wyzerowanie serwa kamery
            px.forward(30)  # Normalna jazda w przód

        time.sleep(0.1)  # Poczekaj chwilę przed kolejnym odczytem

except KeyboardInterrupt:
    pass
finally:
    px.forward(0)  # Upewnij się, że koła są zatrzymane

if name == “main”:
main()

Hi, I checked again and rather there is a deeper problem. I recorded some videos showing the problem

  1. the video shows the standard avoiding_obstacles.py code with the motors connected. the operation of the ultrasonic sensor is not stable. The wheels turn in spite of the fact that there is no obstacle in front of the picar.
  1. the video the same code, but the motors are disconnected, the sensor works stably wheels turn when an obstacle is detected.

3rd and 4th video shows the code avoiding_obstacles.py but modified so that it reads the distance from VL53L0X, code name aaa.py
in one video the sensor operation stable and shortens the wheels when an obstacle is detected. in the next video, the motors connected and the operation of VL53L0X is suspended

I’m very sorry, the code you provided is too small, can you provide us with the full code, you can send it to us via email.

Hello, the code in the attachment is a modified avoiding_obstacles.py code to handle VL53L0X

library to handle VL53L0X downloaded from http://www.pibits.net/code/raspberry-pi-and-vl53l0x-time-of-flight-example.php

from what I’ve noticed picarx crashes during the VL53L0X as well as the ultrasonic sensor as you can see with the videos I attached to the forum post

wt., 22 sie 2023, 11:54 użytkownik SunFounder_Moderator via Sunfounder Forum <notifications@sunfounder.discoursemail.com> napisał:

(Attachment aaa.py is missing)

Hello, the code in the attachment is a modified avoiding_obstacles.py code to handle VL53L0X

library to handle VL53L0X downloaded from http://www.pibits.net/code/raspberry-pi-and-vl53l0x-time-of-flight-example.php

from what I’ve noticed picarx crashes during the VL53L0X as well as the ultrasonic sensor as you can see with the videos I attached to the forum post

from picarx import Picarx
import time
import VL53L0X

POWER = 20
SafeDistance = 250 # > 300 safe
DangerDistance = 200 # > 200 && < 300 turn around,

< 200 backward

def main():
try:
px = Picarx()
vl53 = VL53L0X.VL53L0X()
vl53.start_ranging(VL53L0X.VL53L0X_BETTER_ACCURACY_MODE)

while True:
distance = vl53.get_distance()
print("distance: ",distance)
if distance >= SafeDistance:
px.set_dir_servo_angle(0)
px.forward(POWER)
elif distance >= DangerDistance:
px.set_dir_servo_angle(35)
px.forward(POWER)
time.sleep(0.1)
else:
px.set_dir_servo_angle(-35)
px.backward(POWER)
time.sleep(0.5)

finally:
px.forward(0)

if name == “main”:
main()

wt., 22 sie 2023, 11:54 użytkownik SunFounder_Moderator via Sunfounder Forum <notifications@sunfounder.discoursemail.com> napisał:

This issue is being addressed and is being analyzed to see if it is a software issue or a hardware issue. It will take some time.