Author Topic: choosing focuspoints with lua script: need help  (Read 1297 times)

alext

  • New to the forum
  • *
  • Posts: 4
choosing focuspoints with lua script: need help
« on: July 31, 2017, 01:50:11 PM »
I'm working on a projekt, where I try to get the orientation of a plane by reading the focus motor position with different focuspoints on my 50d with the magiclanter-lua_fix.2017Jul06.50D109 build.
I already managed to automaticly focus and get the correct motor position with lens.focus_pos but I always have to change the focuspoint manually.
I got the Idea to use the key.press() funktion to automaticly change the focuspoints, but KEY.ZOOMIN (same hardware key as for choosing focuspoints) only works to zoom in on pictures.
I tried to use the keys:getkey() funtion to see, if i used the wrong key code for choosing focuspoints, but I always get an error in ML/Scripts/lib/keys.lua. With the following code I get an error in line 48: bad argument #1 to 'remove' ...

Code: [Select]
require('keys')
console.clear()
console.show()
console.write('press Key')
task.yield(500)
console.write(keys:getkey())

By using keys:keys() befor calling keys:getkey() I get the error: attempt to call a nil value (method 'keys)

Is there any point I'm missing or does anyone have a better idea for solving this problem?

Thanks in advance

Alexander

dmilligan

  • Developer
  • Hero Member
  • *****
  • Posts: 3217
  • 60Da / 1100D / EOSM
Re: choosing focuspoints with lua script: need help
« Reply #1 on: August 01, 2017, 01:12:27 AM »
There appears to be a typo in the lua API docs. It's keys:start() not keys:keys(). These functions are designed to be used in a main loop. If you just want to detect a single key press, key.last or key.wait() will be easier.

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12183
  • Maintenance mode
Re: choosing focuspoints with lua script: need help
« Reply #2 on: August 01, 2017, 01:49:08 AM »
To change zoom in LiveView, try lv.zoom(5). That's what I've tested (see api_test.lua), although I'd expect the key event to work as well (will check).

ML has an API to change the focus box position; it's just not exposed to Lua.

alext

  • New to the forum
  • *
  • Posts: 4
Re: choosing focuspoints with lua script: need help
« Reply #3 on: August 01, 2017, 03:34:27 PM »
thanks for your quick reply
@dmilligan it worked with keys:start() but like I suspected, there is no key code for this event.
@a1ex I found your tutorial on writing modules and I'll try to solve it this way. I set everything up for compiling modules and allready found a few things in the source code but I didn't find anything on how to use autofocus. could you give me a few hints on how to solve this?

a1ex

  • Administrator
  • Hero Member
  • *****
  • Posts: 12183
  • Maintenance mode
Re: choosing focuspoints with lua script: need help
« Reply #4 on: August 01, 2017, 08:29:37 PM »
For autofocus, look at lens_take_picture arguments (should_af can be AF_ENABLE, AF_DISABLE or AF_DONT_CHANGE - keep current setting from Canon menu). The same argument is also used in Lua camera.shoot(), but only with the first two choices.