Skip to content

Added Rangefinder class - #175

Merged
mrpollo merged 1 commit into
dronekit:masterfrom
krufab:rangefinder
Jul 1, 2015
Merged

mrpollo merged 1 commit into
dronekit:masterfrom
krufab:rangefinder

Conversation

@krufab

@krufab krufab commented Jun 30, 2015

Copy link
Copy Markdown
Contributor

No description provided.

@mrpollo

mrpollo commented Jun 30, 2015

Copy link
Copy Markdown
Member

@jmacgithu Thanks for the contribution, can you add a description to this PR with what this is and how to use this? ( I some of this on autodocs, but a description on the PR is good for archive )

@djnugent can you please test this

@hamishwillee can you check the docs on this please?

@krufab

krufab commented Jun 30, 2015

Copy link
Copy Markdown
Contributor Author

I have extended the dronekit apis in order to listen and parse also RANGEFINDER MAVLink messages so that it is possible to extract the distance and voltage values read by the main rangefinder.
The class structure and docs reflects the Battery and Location classes' structure and docs formats.
Distances and voltages can be read via vehicle.rangefinder.distance and vehicle.rangefinder.voltage, supposing that you are connected to the vehicle and vehicle is the variable to access vehicle's info (as in vehicle = api.get_vehicles()[0]).
Moreover, it si possible to hook a listener that gets called every time a new RANGEFINDER message is received setting a callback like vehicle.add_attribute_observer('mode', rangefinder_callback) and defining something like:

def rangefinder_callback(rangefinder):
        if last_distance == round(vehicle.rangefinder.distance, 1):
            return
        last_distance = round(vehicle.rangefinder.distance, 1)
        print "Distance: {}" . format(last_distance)

I have tested it on the SITL and with a Iris+ with companion computer.

@djnugent

djnugent commented Jul 1, 2015

Copy link
Copy Markdown

@mrpollo +1

mrpollo added a commit that referenced this pull request Jul 1, 2015
@mrpollo
mrpollo merged commit ce8de35 into dronekit:master Jul 1, 2015
@mrpollo

mrpollo commented Jul 1, 2015

Copy link
Copy Markdown
Member

thanks @jmacgithu @djnugent

@hamishwillee

Copy link
Copy Markdown
Contributor

@jmacgithu are the units metres and volts?

@hamishwillee

Copy link
Copy Markdown
Contributor

@jmacgithu How did you set up SITL to test this? I have modified the vehicle_state.py example to display the rangefinder data and both voltage/distance report None (which I would assume is correct if no rangefinder is configured by default). I tried setting a sonar in Mission Planner (APM-MAxbotixI2C) - do I need to somehow reboot the system for this to be detected? Anything else?

@krufab

krufab commented Jul 7, 2015

Copy link
Copy Markdown
Contributor Author

Hi @hamishwillee, I believe I followed these steps http://dev.ardupilot.com/wiki/simulation-2/sitl-simulator-software-in-the-loop/using-sitl-for-ardupilot-testing/#adding_a_virtual_rangefinder
But I insert those commands before implementing the code. When I started implementing it, the rangefinder messages were already flowing in... So that might have helped, or not 😄
Then if you add vehicle.add_attribute_observer('rangefinder', rangefinder_callback), you should be able to read the distance with vehicle.rangefinder.distance in the callback.
You should be able to test it also with:
module load graph (when starting mavproxy)
graph RANGEFINDER.distance (once the sitls is running)

And I believe units are meters and volts, according to the RANGEFINDER mavlink format.

@hamishwillee

Copy link
Copy Markdown
Contributor

@jmacgithu Awesome. Thanks. Works well. I'll tidy the docs today.

@hamishwillee

Copy link
Copy Markdown
Contributor

FYI Docs issues addressed by #184

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants