Error when using set_position_target_local_ned

439 views
Skip to first unread message

David Mathias

unread,
Apr 18, 2015, 6:49:45 PM4/18/15
to drones-...@googlegroups.com

As suggested by Randy in another thread, I'm trying to use set_position_target_local_ned to control a quadcopter.  Did my first test today (in a simulator) and I get an error.  First, a little about my setup.

I'm running with dronekit-python, mavproxy and the vehicle_sim simulator.  The simulator indicates that it's using: APM: ArduCopter V3.3-dev (10ec1b82).  I created a simple test script to takeoff and then give a small x velocity using set_position_target_local_ned.  Here's the relevant part of the script:
arm_and_takeoff()

home_loc        = getPosition()

msg = vehicle.message_factory.set_position_target_local_ned_encode(
                0,              # time_boot_ms
                0, 0,           # target_system, target_component
                mavutil.mavlink.MAV_FRAME_LOCAL_NED,
                0,              # type_mask
                0, 0, 0,        # x, y, z position
                1, 0, 0,        # v_x, v_y, v_z
                0, 0, 0,        # x, y, z acceleration
                0, 0)           # yaw, yaw_rate

vehicle.send_mavlink(msg)
vehicle.flush()

Note that arm_and_takeoff() is a function used in some of the examples included with dronekit and getPosition is a simple function I wrote.


Here's the error I get when I run the script:

Exception in APIThread-0: 'MPStatus' object has no attribute 'target_system'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/droneapi/module/api.py", line 322, in run
    self.fn()
  File "/usr/local/lib/python2.7/dist-packages/droneapi/module/api.py", line 593, in <lambda>
    APIThread(self, lambda: execfile(args[1], g), args[1])
  File "velocity_test.py", line 52, in <module>
    vehicle.send_mavlink(msg)
  File "/usr/local/lib/python2.7/dist-packages/droneapi/module/api.py", line 244, in send_mavlink
    self.__module.fix_targets(message)
  File "/usr/local/lib/python2.7/dist-packages/droneapi/module/api.py", line 392, in fix_targets
    message.target_system = status.target_system
AttributeError: 'MPStatus' object has no attribute 'target_system'


The set_position_target_local_ned message is in the ardupilotmega.py file that I'm using so I don't think that's the issue.  Does this error indicate that the simulator "firmware" doesn't support the command?  It says that it's 3.3 so I assumed that it would.  Is it something else?

If it is a firmware problem, I'll also likely need to update my Iris+ before trying this on a real vehicle.  How stable is the APM version that includes support for set_position_target_local_ned?

Thanks.

David

Timothy Locke

unread,
Apr 19, 2015, 1:23:46 PM4/19/15
to drones-...@googlegroups.com
David, I had the issue. The latest release broke DroneKit. See my post "MAVProxy Attribute Error Revisited", it has more information regarding the issue.

David Mathias

unread,
Apr 19, 2015, 7:15:32 PM4/19/15
to drones-...@googlegroups.com

Tim, thanks very much.  That took care of it.  I should have found your thread but I made assumptions about what was causing the error.  I should have just searched using the error message.

You mentioned that when you send commands to the drone from droneapi you get crazy roll, pitch and thrust values.  I'm curious about this because while I'm now able to send the commands, they don't seem to impact anything going on in the simulator.  The drone doesn't move on the map and the roll, pitch and thrust values in the console remain unchanged.  If I print attitude or channel_readback values, I can see changes.  I would think that I'm not correctly interfacing mavproxy and sim_vehicle except for the fact that commands.goto commands do change values in the console and move the vehicle on the map. 

In a terminal window I run: sim_vehicle.sh -j 2

Then in another terminal window, I run: mavproxy.py --master=localhost:14550 --console --map

I've just tried experimenting a bit by adding --sitl=127.0.0.1:5501 to the mavproxy command but that didn't help.  I also edited sim_vehicle.sh to add --console --map options to the mavproxy invocation there (and removed it from the mavproxy I launch manually) but didn't see any change.  Any idea what I'm doing wrong?  Thanks again.

David

Kirby Linvill

unread,
Apr 21, 2015, 12:49:14 AM4/21/15
to drones-...@googlegroups.com
Hi David, 

Are the local_NED commands showing a change on the map/console for you? If not, you likely need to add in some kind of delay. If you send a command but then immediately send another message, such as setting the drone to loiter, the local_NED command is likely being executed for only the split second it takes the octo to receive and process the next command. The (somewhat kludgy) way I've been handling this is with a conditional loop with a delay inside. For instance: 
while (vehicle.location.alt - target_location.alt < -.1 or vehicle.location.alt - target_location.alt > .1) \ and not api.exit:
 
print "Ascending"
 sleep
(1)

David Mathias

unread,
Apr 21, 2015, 10:49:44 AM4/21/15
to drones-...@googlegroups.com

Hi Kirby,

Thanks for taking time to reply.  My ad hoc solution for delay during testing is considerably less elegant than yours -- I've just been using sleep statements.  The problem I was having is solved.  I'm embarrassed to say that it was an incorrect type_mask.  I hate making mistakes like that...  Thanks again.

David
Reply all
Reply to author
Forward
0 new messages