CAN_read.lua not work

Hello

Id try to get data from CUAV neo v3 PRO, whats connected to FC via CAN.
2023 13:00:54 : ArduCopter V4.4.0 (502702df)

I’d try use example script, https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Scripting/examples/CAN_read.lua, but no luck.

  • [CAN_P1_DRIVER]set to 1.
  • [CAN_P2_DRIVER]set to 1.
  • [CAN_D1_PROTOCOL]set to 1.
  • [CAN_D2_PROTOCOL]set to 1.

get device give me some data as
22.11.2023 12:13:11 : driver2ScriptingCANBuffer: 0x24036170
22.11.2023 12:13:11 : driver1ScriptingCANBuffer: 0x24036148

but frames itself is nil.

I did try set local driver1 = CAN:get_device(1) and 5 and 10 and 12 and trying change CAN_D2_PROTOCOL to 1/5/10/12. Still nothing.

GPS itself working great, but i can’t get data from it via LUA.
Any suggestion? There is no much info about CAN + Lua, makes me think example code should work from box. Did i miss something?

Thanks!

If you’re using the GPS for navigation, you won’t be accessing it directly on the CAN bus with Lua. To access a CAN device via scripting, you need to use the scripting back end (CAN_Dx_PROTOCOL=10), which will render that device inaccessible to the autopilot as a nav device (unless there is a workaround of which I’m unaware).

Why not just use the GPS bindings?

So for script working,
in FC:
CAN_D1_PROTOCOL = 10
CAN_P1_DRIVER = 1
in script:
local driver1 = CAN:get_device(10)

device is in CAN1

After that frames are not nil.

I was wanna extract data from GPS NEO, like status if i set GPS type to 0. Any ideas how to do that? Thanks!

Be more specific. I don’t know what your goal is. Are you going to use this GPS for navigation or not?

I am doing indoor navigation, but part of the path we take is outdoors. I want to automatically turn GPS on and off depending on the accuracy (conditionally, the number of satellites). Since GPS involves waves, reflections off buildings can significantly affect navigation.

My plan was this - if I see that there are less than 10 satellites, I set GPS type to 0 and no longer use it for AHRS and navigation. When I receive data through a Lua script via the CAN bus that there are more than 20 satellites, I set GPS type to 9 and turn on the GPS data in AHRS.

Issue comes that if set gps type 0, i don’t know current amount of sats.

I think you’re overcomplicating the solution (and likely causing EKF issues in so doing). See here:

GPS / Non-GPS Transitions — Copter documentation (ardupilot.org)

You could script the source selection just as easily without resorting to CAN magic.

You should probably trigger auto-selection based on something more concrete like fix state and HDOP rather than simple satellite count.

Yes, but our system working as GPS(mavlink).
So surely best solution would be just “amount” of sats that system see (like AHRS_GPS_MINSATS), but i not sure if it work the way i wanna.

In current test gpstype 0 working great, but its not auto solution

Yes, surely I checked link .
Solution " from External Nav" is not our case, as i say, we use GPS_input via Mavlink. Or i not understand somethings? In my idea " from External Nav" mean we got some sensors, but we don’t.

The solution is laid out very clearly in the document that I linked. Use it.

And satellite count is surely NOT the best way to determine whether the GPS is fit for use as a nav source.

I cannot change “from GPS” as source, since we are use GPS_input, mavlink one.
Link that you send is for usage sensors(Intel camera), with VISION_POSITION_ESTIMATE.

Surely it will work as document said

Perhaps rather than sending GPS-like messages for indoor position, you could use Poszyx like this:

Pozyx for Non-GPS Navigation — Copter documentation (ardupilot.org)

And then switching between BCN and GPS sources becomes trivial as in the example I first sent.

Otherwise, I think you’re probably on your own, as the system you described sounds a bit ill-conceived.

I set ahrs min sat to 10, but gps start used when there was 4 sat, so no luck with that setup.

Yes, you correct, but position estimatw will not work great on open space (in city) since long distance.

So lets be straight - flying inside buildings is issue since gps send trash to us and some randome 5m spike could lead to crash.
Turn gps off when there is no sats is great, but i need to know when its good.

I understand the basic issue. What I don’t understand is your external system for position estimate via Mavlink and why it’s also coded as a GPS source.

That way long distance travel and outdoor operation is not a issue if use gps input. Position input is issue with that

Why would you be trying to travel long distances within building clutter in an urban environment in the first place? This type of operation is highly illegal in most locations.

Its research just :slight_smile:

Well, good luck.