Setting EKF origin through MAVLink

So I found in the patch notes for AC3.5-rc5 that Do-set-home sets EKF origin, but I can’t figure out how to do it right. Mission planner does it well, but when I try to do it myself, MAVProxy gives me a response of 4 (which I assume to be fail). What special sauce is required to set EKF home?

Here’s what I do in dronekit (with lat, lon, lat set to 0):

msg = vehicle.message_factory.command_long_encode(
        0, 0,    # target system, target component
        mavutil.mavlink.MAV_CMD_DO_SET_HOME, #command
        0,    #confirmation
        0,    # param 1, (1=use current location, 0=use specified location)
        0,    # param 2, unused
        0,    # param 3,unused
        0,    # param 4, unused
        lat, lon, alt)    # param 5 ~ 7 latitude, longitude, altitude
2 Likes

Olle,

That message should work but the lat, lon and alt need to be set to reasonable values (i.e. not “0”).

3 Likes

Oh, putting in values for my city worked well, thanks!

I figured I really didn’t care since the drone is flying in a small indoor location, but this is fine!

1 Like

Olle,
Excellent, glad to hear it worked! It is actually important to at least roughly pick your actual location because the compass declination is looked up from a small database within ardupilot. Having the declination wrong could lead to the vehicle’s heading being off although for most places in the world the differences is only a few degrees.

I’m trying to do the same, and it is not working. It does not matter what lat and lon I choose, I always get the response 4.

def set_ekf_origin(vehicle, location):
    msg = vehicle.message_factory.command_long_encode(
       0, 0,    # target system, target component
       mavutil.mavlink.MAV_CMD_DO_SET_HOME, #command
       0,    #confirmation
       0,    # param 1, (1=use current location, 0=use specified location)
       0, 0,  0,    # param 2-4, unused
       location.lat, location.lon, location.alt)  
    vehicle.send_mavlink(msg)
    vehicle.flush()

https://github.com/ardupilot/MAVProxy/blob/master/MAVProxy/modules/mavproxy_map/init.py#L492

Interestingly enough, with MAVProxy I get the same error

('Setting home to: ', -35.36511625906776, 149.1714741901144, 579.0802729880293)
Got MAVLink msg: COMMAND_ACK {command : 179, result : 4}

Mission Planner works fine though.

I’m running ArduCopter V3.6-dev (670d3cee) and trying with SITL only for now.

I have analyzed the problem further. I have compared the MAVlink messages with Wireshark.
The only difference between the Mission Planner Message and the dronekit-python message is the component ID now, which is 0xbe for MP and 0x00 with dronekit.

set_ekf_origin

I haven’t found out how I can control this field via the API yet. From the documentation I am not sure if it is even accessible without editing the dronekit-python source code?

Same problem here @moobsen @ollenorelius, mission planner working, dronekit not and gives result 4 “Executed but failed”. Have you found a solution?

Yes, system and component ids in the mavlink header are related to the sender of the packet: system 0xff = 255 (common GCS id), component 0xbe = 190 = Mission Planner component id

Maybe I can test a sightly modified version of the MAVproxy style code suggested by @peterbarker

vehicle._master.set_gps_global_origin_send(
            target_system,
            lat*10000000, # lat
            lon*10000000, # lon
            0*1000) # no height change

By the way the ArduCopter code that executes the command is here https://github.com/ArduPilot/ardupilot/blob/Copter-3.6/ArduCopter/GCS_Mavlink.cpp#L728-L769

1 Like

@guglie did that work?

In my tests it worked only pymavlink’s set_gps_global_origin_send (http://mavlink.org/messages/common#SET_GPS_GLOBAL_ORIGIN).

@rmackay9 here (https://github.com/ArduPilot/MissionPlanner/issues/1702) states that

…in older versions of the vehicle firmware we used the SET_HOME_POSITION message (http://mavlink.org/messages/common#SET_HOME_POSITION) to set the EKF origin but this led to some issues…

So probably it only works on older versions of the firmware.

Hello.Can somebody help me with instructions on how to setup EKF origin without Mission Planner.If I could enter a permanent one in some config file.That would be best so i could use the Lidar based nongps Rover as soon as it boots and connects to companion computer.Thanks

yes i am interested too…
set EKF origin permanently in the same location

1 Like