Pixhawk 4 + Raspberry pi, GeoFence is not setting up in SITL

Hello everyone,

I am working on a sea vessel.

The electronics we using are :

Our aim is to set a mission, send GeoFence points to pixhawk from raspberry pi.

We are NOT using mission planner in this Project to set up this Fencing and waypoints.

We successfully sent waypoints to the pixhawk, however in GeoFencing, we are having an issue.

from pymavlink import mavutil, mavwp

master = mavutil.mavlink_connection(device= "tcp:127.0.0.1:5762")
master.wait_heartbeat()

fence = mavwp.MAVFenceLoader(master.target_system, master.target_component)
fence.load(“fence.txt”)

for i in range(fence.count()):
    master.mav.send(fence.point(i))

master.mav.command_long_send ( master.target_system , master.target_component , mavutil.mavlink.MAV_CMD_DO_FENCE_ENABLE , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 )
master.arducopter_arm( )
print ( " Waiting for the vehicle to arm " )
master.motors_armed_wait ( )
print ( ' Armed ! ' )

i am having “Armed !” message but in SITL geofence is not activated. what can be the problem?

fence.txt file

34.5314348 35.6353176
34.5319927 35.6348468
34.5317996 35.6340448
34.5306516 35.6335741
34.5292354 35.6346115
34.5279801 35.6339751
34.5294499 35.6323100
34.5332694 35.6327546
34.5343530 35.6349340
34.5325291 35.6363811
34.5314670 35.6353524

Take a look at it here.

send_fence function is what you’re looking for.

i also tried this but didnt work

from pymavlink import mavutil

master =  mavutil.mavlink_connection(device="tcp:127.0.0.1:5762")
master.wait_heartbeat()

poli = [(35.63604046,34.53116655), 
(35.63638925,34.53209996),
(35.63584863,34.53270078),
(35.63536032,34.53252912),
(35.63520337,34.53167081),
(35.63554344,34.53127384)]

#enable fence
master.mav.command_long_send(
            master.target_system,
            master.target_component,
            mavutil.mavlink.MAV_CMD_DO_FENCE_ENABLE, 0,
            1, 0, 0, 0, 0, 0, 0)

print(len(poli))
for i in range(len(poli)):
    master.mav.command_long_send(
                master.target_system,
                master.target_component,
                mavutil.mavlink.MAV_CMD_NAV_FENCE_POLYGON_VERTEX_INCLUSION, 0,
                len(poli), 
                1, 
                0, 
                0, 
                poli[i][0],
                poli[i][1], 
                0)

master.arducopter_arm()

print("Waiting for the vehicle to arm")
master.motors_armed_wait()
print('Armed!')

Did you manage to solve it? I’m stuck trying to send GeoFence points via MAVLink