-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uploading fence to Ardupilot by dronekit #1092
Comments
For mavlink1 vs mavlink´2 issues have you tried the workaround:
|
I tried your code but I get this error : |
Hi There! Right now entering a fence erases the others. How would you go about keeping them? I am looking as well, but your help would be appreciated. Thank you by the way!! |
Hi, I've tried your code -thanks!- and managed to get it working maybe twice before getting the error: Now it's stuck in the loop: In _wp_uploaded, only the first element is true. Any ideas on how to fix it? Thanks |
I am using Cube purple with ArduRover 4.0, and am using dronekit for many of my applications.
But I tried to upload fence points by creating a similar mission file as QGC WPL 110 format (same like when we download from Mission Planner). On that text file, I changed the mission command value to 5002 and 5004 and also corresponding param1 and MAV_FRAME value, and I used the same method as describe here to upload the fence points, but it didn't work, and I found that it stuck at the while loop here.
After sometime of looking the code of dronekit and pymavlink and some trial and error, I found out some way to upload fence mission. So in case some one is looking for a similar thing, you can try this out.
on
__init__.py
at line 46dronekit-python/dronekit/__init__.py
Line 46 in 27b292b
we need to change
from pymavlink.dialects.v10 import ardupilotmega
topymavlink.dialects.v20 import ardupilotmega
from Command class,
dronekit-python/dronekit/__init__.py
Line 2871 in 27b292b
I added one extra function name as
upload_fence()
, which I copied from original upload()On the new
upload_fence()
, instead ofself._vehicle._master.waypoint_count_send(self._vehicle._wploader.count())
, I changed toself._vehicle._master.fence_count_send(self._vehicle._wploader.count())
.And I comment out
self._vehicle._master.waypoint_clear_all_send()
because I don't want it to clear all my previous waypoint mission. Then we need to create a functionfence_count_send()
as well on mavutil.pyon
mavutil.py
atdef waypoint_count_send(self,seq)
function hereI copied and made a new function from that which called
def fence_count_send(self, seq)
, and on that new function I changedmission_count_send()
tomission_fence_count_send()
on dialects/v20/ardupilotmega.py
at line 18439, I copied
mission_count_send(self, target_system, target_component, count, mission_type=0, force_mavlink1=False)
function and made a new function calledmission_fence_count_send(self, target_system, target_component, count, mission_type=1, force_mavlink1=False)
. Please make sure to have mission_type = 1 on the new function.make sure you set this one
os.environ["MAVLINK20"] = "1"
on topI have followed the way to download/upload waypoints from here, so on that page you will see an example of upload_mission() function, so I made a copy of that function and called upload_fence(). So the code is almost same but just the for loop
the original mission is like this
But for fence, you will need to add
command.mission_type=1
like thisbecause the mission message will set mission_type default as 0 which is for MISSION, so we need to change it to 1 for FENCE. More detail of mission_type is here
So your fence points file should be in QGC WPL 110 format, you can simply make some dummy fence and save file from Mission Planner and take a look in there how the format looks like.
Your MISSION_ITEM command should be 5000, 5002, 5003, or 5004 depends on what type of fence you need, please check detail from here
and the param1 and frame values are different for each fence type, so from my observation are here
Example1.
This is in case of MAV_CMD_NAV_FENCE_POLYGON_VERTEX_EXCLUSION (5002)
0 on third column is MAV_FRAME_GLOBAL or Absoulute in Mission Planner, more detail of MAV_FRAME https://mavlink.io/en/messages/common.html#MAV_FRAME
4 on fifth column is param1, and in this case it represents 4 points of polygon fence
Example2.
This is in case of MAV_CMD_NAV_FENCE_CIRCLE_EXCLUSION (5004)
3 on third column is MAV_FRAME_GLOBAL_RELATIVE_ALT
2 and 6 on fifth column are param1 of each point, and it represents a radius of circle fence
Here is my full example code
I am not sure the proper way to do it, but this seems to work for temporary.
I will need to check that other of my feature like guide mode yaw and others still working properly after I changed to
pymavlink.dialects.v20
. So I am looking forward for a high-level of geofence uploading on dronekit without these modification by myself :) . If some of you guys want to do a PR according to my code here, feel free!The text was updated successfully, but these errors were encountered: