dronekit / dronekit-python

DroneKit-Python library for communicating with Drones via MAVLink.
https://readthedocs.org/projects/dronekit-python/
Apache License 2.0
1.59k stars 1.44k forks source link

Mathematical operations on objects #304

Open djnugent opened 9 years ago

djnugent commented 9 years ago

Implement __add__, __sub__,__mul__, etc to the Location and Attitude object. Simple but I am currently preoccupied by something else.

eliao commented 9 years ago

I have a bunch of Location helper functions that could be put into Dronekit.

djnugent commented 9 years ago

As do I. Probably not as much as you but I have made a fair amount of extensions to dronekit that should probably be standard...IMO

hamishwillee commented 9 years ago

@djnugent What is the point? ie what does it mean to add, subtract, multiply two location objects?

Same question or Attitude - also at this point we can't set attitudes at this point (though that would be handy) so manipulating them doesn't seem useful.

It would however be useful to have more functions for manipulating postions/headings/distances. We already documented a few frame conversion functions here and @mrpollo wants those ones in the API too (#133).

@eliao What are those functions you want to add?

FYI from AC3.4 maybe not quite so necessary as copter will add proper support for local frames so you will be able to specify more easily "distances X, Y, Z, metres from your current position).

eliao commented 9 years ago

@hamishwillee The functions I had in mind include the frame conversion functions you mentioned.
I do use a different method for calculating distance between two locations, and I have 2d and 3d versions (including altitude).

newLocationFromAzimuthAndDistance is one I find super handy. crossTrack functions may be useful as well.

Once local frames are added, I expect one would want conversion functions between the two, as well as some vector math functions, which may be what @djnugent is referring to.

hamishwillee commented 9 years ago

@eliao Your functions sound great. Minimally could we get them added to the documents? (ie what are they!)

I'd like them in the API but we need to decide how. The easy way is to just provide a library of primitives. I like this because it means you can choose to use them or not.

The hard way is to modify the Location object so that it understands frames better and handles conversions automatically. I like this because it reduces the things that users have to think about. I dislike it because all the methods have some level of error, and this approach makes it harder to swap out the options.

eliao commented 9 years ago

Library of primitives sounds good to me.

I think it should be fine to post my code, but I should make sure.

Why are we posting code in the documents? Is it a stopgap measure?

djnugent commented 9 years ago

@hamishwillee I have just added a few things that make dronekit a bit easier to use...for me. The biggest one is not letting the my script use location data, especially the home location, until we are armed.

Adding objects means: loc.lat = loc1.lat + loc2.lat; loc.lon = loc1.lon + loc2.lon; loc.alt = loc1.alt + loc2.alt; ----> can be replaced with loc = loc1 + loc2

hamishwillee commented 9 years ago

@eliao Great!

Why are we posting code in the documents? Is it a stopgap measure?

Yes. Because there are lots of ways this can be done, I was hoping for a technical architect to mandate the approach that would be used (and ideally someone who has more Python experience than me to do the work). As I have the power to update the docs directly that was my "patch" on the problem. As it turns out, a good solution because no one has stepped forward to do the work ...

That said, I am sure if someone created a library that we could then discuss, it would be accepted unless the infrastructure was insane. hint hint!

@djnugent I see this useful for alts, but can you really just add two lats or lons in absolute decimal degrees?

The home location change makes sense if all platforms set the home position only after arming. I'm not sure that is true - doesn't plane set it as soon as the GPS gets a lock?

We're also planning some other work on home in #252 - worth adding a note about what you want to achieve in that post?

djnugent commented 9 years ago

@hamishwillee no adding a relative to an absolute location.

I'll give it a look.

hamishwillee commented 9 years ago

@djnugent Thanks. As it is now the only "relative" information is the alt. It would be handy to add a location with values say in metres for lat, lon, but we would need some way for the system to manage relative frames and report misuse.