Trouble setting waypoints and running a mission using mavros

asked 2019-05-02 09:19:34 -0500

Drkstr gravatar image

I am trying to create a set of waypoints, add them to a waypoint list and then fly a mission using rospy and MAVROS.

I could not find any python sample code. So, I tried to figure it out on my own. Unfortunately, I did not have much luck.

Here is the code I am using to create a waypoint and add it to the waypointlist.

    def create_waypoint(self):
        latitude = self.current_location.latitude
        longitude = self.current_location.longitude

        waypoint = Waypoint()
        waypoint.x_lat = latitude
        waypoint.y_long = longitude
        waypoint.autocontinue = True
        waypoint.is_current = False
        waypoint.frame = Waypoint.FRAME_GLOBAL
        waypoint.command = CommandCode.NAV_WAYPOINT

        self.waypoint_list._request_class.waypoints.push_back(waypoint)

I get an error message saying "AttributeError: 'member_descriptor' object has no attribute 'push_back'" when I do the push_back(waypoint)

This is how I am trying to start the mission after setting the waypoints:

    def start_waypoint_mission(self):
    rospy.wait_for_service('/mavros/mission/push')
    try:
        self.waypoint_push_srv.call(self.waypoint_list)
    except rospy.ServiceException, e:
        print "Service arm call failed: %s" % e

    rospy.wait_for_service('/mavros/set_mode')
    try:
        # https://github.com/mavlink/mavros/blob/master/mavros_msgs/srv/SetMode.srv
        self.drive_mode.call(220)
    except rospy.ServiceException, e:
        print "Service arm call failed: %s" % e

Questions:

  • What is the correct method for creating a waypointlist and running a mission?
  • Where can I find some python sample code for doing this?
edit retag flag offensive close merge delete

Comments

Hey, i was doing a similar task. I want to know if you figured the correct way out ad if you can help me with it?

Mohit Singh gravatar image Mohit Singh  ( 2019-05-24 07:25:03 -0500 )edit