Can pan/tilt be blocking?

Discussion related to "under the hood" OpenMV topics.
ScottM
Posts: 91
Joined: Thu May 30, 2019 2:12 pm
Location: Ottawa, Canada

Can pan/tilt be blocking?

Postby ScottM » Mon Mar 09, 2020 2:11 pm

I am testing my pan/tilt shield and have a couple of issues. In the code segment below, I tell it to pan - 5 degrees in 2 seconds and then I read the position.

Pan.angle(-5,2000)
current_pan = Pan.angle()
print ("Current pan angle is %s" % current_pan)

What happens is that the code does not wait for the servo to get to 5 degrees. It sends the command and then prints the position almost right away.

Question: Can I use a wait or do loop after issuing Pan.angle(-5,2000) to not move forward in the code until the movement is finished?
User avatar
iabdalkader
Posts: 1193
Joined: Sun May 24, 2015 3:53 pm

Re: Can pan/tilt be blocking?

Postby iabdalkader » Mon Mar 09, 2020 2:57 pm

Just add sleep(2000) after the command.
ScottM
Posts: 91
Joined: Thu May 30, 2019 2:12 pm
Location: Ottawa, Canada

Re: Can pan/tilt be blocking?

Postby ScottM » Mon Mar 09, 2020 4:58 pm

That does not work.
User avatar
iabdalkader
Posts: 1193
Joined: Sun May 24, 2015 3:53 pm

Re: Can pan/tilt be blocking?

Postby iabdalkader » Mon Mar 09, 2020 5:39 pm

Why not ?
ScottM
Posts: 91
Joined: Thu May 30, 2019 2:12 pm
Location: Ottawa, Canada

Re: Can pan/tilt be blocking?

Postby ScottM » Tue Mar 10, 2020 10:55 am

This code seems to work.

print("1. Pan angle 0")

Pan.angle(0)
utime.sleep_ms(5000)

print("2. Pan angle -10")
Pan.angle(-10)
utime.sleep_ms(5000)

print("3. Pan angle 10")
Pan.angle(10,2000)
utime.sleep_ms(5000)

print ("Done")
ScottM
Posts: 91
Joined: Thu May 30, 2019 2:12 pm
Location: Ottawa, Canada

Re: Can pan/tilt be blocking?

Postby ScottM » Wed Mar 11, 2020 11:58 am

For some reason, I have much better success with utime.sleep_ms() than I had with time.sleep().

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 19 guests