Did a simulation here and the code seemed to work.
Simulation:
- IR sensor = 1
- HALL sensor 10 ms pulses 0->1->0 each 0.51 sec
- wheel diameter 0.7
- distance 1km
If you have other parameters, let me know.
Simulation is a thread in code, which sets output pins 21, 20 for IR, HALL sensor. Connect em to the inputs with jumper wire.
Simulation:
- IR sensor = 1
- HALL sensor 10 ms pulses 0->1->0 each 0.51 sec
- wheel diameter 0.7
- distance 1km
If you have other parameters, let me know.
Simulation is a thread in code, which sets output pins 21, 20 for IR, HALL sensor. Connect em to the inputs with jumper wire.
Code:
class Simulator: """connect SENSOR_HALL_OUT = 21 to SENSOR_HALL_PIN = 22 SENSOR_OBJECT_OUT = 20 to SENSOR_OBJECT_PIN = 23 """ def __init__(self): self.SENSOR_HALL_OUT = 21 self.SENSOR_OBJECT_OUT = 20 pi.set_mode(self.SENSOR_HALL_OUT, pigpio.OUTPUT) pi.set_mode(self.SENSOR_OBJECT_OUT, pigpio.OUTPUT) pi.write(self.SENSOR_HALL_OUT, 0) pi.write(self.SENSOR_OBJECT_OUT, 0) self.thread = threading.Thread(target=self.run) self.thread.start() def run(self): print("simulating sensor signal") pi.write(self.SENSOR_OBJECT_OUT, 1) while True: pi.write(self.SENSOR_HALL_OUT, 1) time.sleep(0.010) pi.write(self.SENSOR_HALL_OUT, 0) time.sleep(0.5) simulator = Simulator()[/codeWhat I would change in the code: in the callback method "count_pulse", I would increment pulses only on either pos edge or negative edge.
Statistics: Posted by ghp — Thu Jan 02, 2025 9:32 pm