#vl53l1x time of flight and motor
1 messages ยท Page 1 of 1 (latest)
That's what the while True: loop is for
You want your motor to run when the sensor value is in a range between yourstart_valueand stop_value , right?
yes
this i colud be going about the hole proces in corectoley as i am quite new
the end gool is to make a ajustabull higth desk
I'll just call your start and stop values v1 and v2 , then you can do something like this every iteration
while True:
check sensor value = v
if (v >= v1 and v <= v2) and motor_started == False:
start_motor()
motor_started = True
if (v<v1 or v > v2) and motor_started == True:
stop_motor()
motor_started = False
Ideally, you would want to start with a simple example, like the one in the sensor guide https://learn.adafruit.com/adafruit-vl53l1x/python-circuitpython
with plenty of prints, to make sure that the values you are getting from the sensor are as expected
And only then introduce the motor functionality
i have tried that and the i am geting that sensor data corectley
Other things to consider:
-
the lower value cannot be 0, since this particular sensor doesn't detect stuff that close, it will not give accurate readings
-
your
soft_stop()function doesn't actually stop the motor, it reverses it ... at the end the throttle value is almost -1, which is almost full speed in reverse direction
so i guss im understanding the 'for i in range (100)'
it is not 100 loops of that function?
so long as the throttle is 1 at the start of the function it reduce by .01 fore each loop
you're doing 1-i so basically you end up with -0.99 at the end, which is just full speed in reverse
you probably want range(100, -1, -1) to stop, and i, not 1-i
ok i think i understand that in the loung run i plan to have it do a soft stop but only down to like .05 untill it reatches the target hight then full stop
so i colud do range (95 ,-1 , -1)
range(100, 0, -1) will go from full, to just before 0 ... or even range(100, 5,-1) to keep the motor running really really slowly
anyway, this is all adaptable to your needs when you get it going ๐
sweet
I'm pretty sure the problem in your current code is the infinite loop when you check the sensor value, that's why I tried to simplify the logic of your code
so the def tof_Range(): while call_range == True: global call_range, value if TOF.data_ready: print("Distance: {} cm".format(TOF.distance)) value = TOF.distance TOF.clear_interrupt() call_range = False else: pass
so it sholud onley enact the loop when the call_range varible is set to True
sure
and sincei have in the function to set call_range = False it sholud end the loop?
yep
ok so that sholdu solve the infinit loop maby not in teh best way thow
as long as it works, all good
you don't need global call_range, value there tho, they were already declared above the function, right?
yes