Could someone explain to me how does the get_usb_power() function work, exactly? I am building an motorized pano head controlled from a chdk (lua) script and this function is giving me a lot of grief.
By turning the AF LED on I can rotate the pano head with a constant speed. I also have a USB 'feedback' in a form of a push switch (normally off) that gets momentarily turned on when it passes over a small barrier. That way, by reading the state of the get_usb_power() I can detect when the camera points to a specified direction.
That's the hardware. My script (heavily simplified) is supposed to work like this:
1. determine the rotation speed
- start the rotation
- the time difference between the first and the second get_usb_power()>0 is the period of one full rotation
2. shoot the photos
- a bunch of math to determine the slide angle from photo to photo
- a loop that slides for the said angle, takes a photo and checks if get_usb_power() got triggered (to know when to stop)
The problem is that the speed is always correctly measured but the same get_usb_power() function does not, most of the time, get triggered (>0) in the photo-taking loop. Let me repeat that. When I have a continuous rotation the 'switch' works but when I loop slide-stop-slide-stop... the switch stops working. Here are both functions:
function calibrate()
local t
local tt
get_usb_power()
set_led(9,1)
repeat
sleep(1)
until get_usb_power()>0
t=get_tick_count()
repeat
sleep(1)
until get_usb_power()>0
set_led(9,0)
tt=get_tick_count()
az=0
return tt-t
end
function slide(time) -- slide (rotate) for a specified duration
local t=0
local p=0
local tt=0
get_usb_power() -- clear
set_led(9,1) -- start the rotation
t=get_tick_count() -- start time
repeat
sleep(1)
p=get_usb_power()
until p>0 or get_tick_count()-t>time
set_led(9,0) -- stop the rotation
tt=get_tick_count() -- end time
if p>0 then
print("full circle")
return 1
else
return nil
end
end
Does anyone know why would get_usb_power() fail to return positive integer when the power was on and off?