AHRS.Source lua script errors

I’m trying to run the AHRS Source GPS Optflow.lua and I get the following error:

ahrs-source-gps-optiflow.lua:124: attempt to call a nil value (method 'distance_orient')

I’ve also tried ardupilot/libraries/AP_Scripting/applets/ahrs-source-extnav-optflow.lua at master · ArduPilot/ardupilot · GitHub and same error in what appears to be the same code.

(Yes, I did have the wind calibration script running, but I’ve removed that in case somehow that was causing the issue. It wasn’t)

The only edit I made to either script was to change from switch 1 (300) to switch 2 (301).

-- get rangefinder distance
  local rngfnd_distance_m = 0
  if rangefinder:has_data_orient(rangefinder_rotation) then
    rngfnd_distance_m = rangefinder:distance_orient(rangefinder_rotation)  -- this is line 124
  end
  local rngfnd_over_threshold = (rngfnd_distance_m == 0) or (rngfnd_distance_m > rangefinder_thresh_dist)

Matek H743-Bdshot AC4.5.3 Micoair MTF-01 Optical flow (all calibrated and working)

Any ideas?

Edit: Just add the ranger finder was working and I was getting accurate data from it.

Just been playing with this some more and have more info, but still no solution:

When I power the drone with USB the script works as advertised, however there is also an error that there’s no range finder data.

Once I plug in battery power the script returns to the error I mentioned above. It doesn’t seem to matter what order I apply power it’s the same. Script works with USB power (but no range finder data). Script doesn’t work on Battery (range finder working).

I’m open to suggestions.

I’ve tried a couple other range finder related scripts from the examples and none seem to work. But the range finder is working otherwise.

Does it matter that the micoair MTF-01P uses Mavlink rather than a specific driver?

I’ve just tried running the script rangefinder_test.lua. I get the GCS message that I have one rangefinder. But then I get the same Nil value errors when it tries to return any data about the range finder. (line 22…)

I’ve also tried a boot delay on the board of 3 seconds. No joy.

Anybody?

TLDR:

AC 4.6.0 beta 5
Matek H743-Wlite
MicoAir MTF-01P

Ranger finder and optical flow both work. Surface track works. All good until I try the script ahrs_source_gps_optflow.lua

These lines:

 local rngfnd_distance_m = 0
  if rangefinder:has_data_orient(rangefinder_rotation) then
    rngfnd_distance_m = rangefinder:distance_orient(rangefinder_rotation)
  end

This error

Lua: /APM/scripts/ahrs-source-gps-optflow.lua:125: attempt to call a nil value (method 'distance_orient')

@Yuri_Rage , sorry to call you in but I’m stuck. Tried nothing and I’m all out of ideas.

distance_cm_orient was deprecated in 4.7, but I think that’s the binding you need for your script.

2 Likes

Thanks! Only had a second to test it, but that seemed to do the trick.

I’ve just take the scripts from the AP libraries on Github, I’m not smart enough to write my own. Does that mean there is an error in these scripts or are they updated based on the dev version, not beta or stable?

They are not errors, just updates to master. You can choose a different branch on GitHub pretty easily:

1 Like

:man_facepalming:

Being new to Github I didn’t understand what that was all about. But now that makes a ton of sense. Thanks! That helped a lot!