Servers by jDrones

Read GPS and IMU data form PixHawk to raspberry pi

Hello, I am trying to communicate to pixhawk via raspberry pi 2 over MAVLink. I can send commands but i can not read the real time sensor data from the pixhawk. Is it possible to do that??
Because I want the NED position co-ordinates provided by the IMU and GPS. Can anyone help me in this?

I know it can be done in dronekit by overriding the .on_message method
example:

#Create a message listener using the decorator.
@vehicle.on_message(’*’)
def listener(self, name, message):
print message

More info here

The two messages would then be for example GLOBAL_POSITION_INT and HIGHRES_IMU

To listen to more multiple messages I think you need to use the .add_message_listener function. so your code would look something like:

vehicle.add_message_listener(‘GLOBAL_POSITION_INT’,receivedPos)
vehicle.add_message_listener(‘HIGHRES_IMU’,receivedImu)

def receivedPos(self, name, posMsg):
#Do something with the message

def receivedImu(self, name, imuMsg):
#Do something with the message

1 Like

I have the same issue. Have you figured it out??

Hello Sameena,
It is easy to use the command “add_message _listener”.
Eg.

def any_func_name(self, name, msg):
print msg
vehicle.add_message_listener(‘GLOBAL_POSITION_INT’, any_func_name)

Hi Ronnie,
I didn’t get you. After doing the mavlink mavproxy setup and getting this


what should be done?
I’m stuck at this. Would be grateful if you could help

Thanks & Regards
Sameena Shaikh

Sameena_Shaikh http://discuss.ardupilot.org/u/sameena_shaikh
December 12

Hi Ronnie,
I didn’t get you. After doing the mavlink mavproxy setup and getting this

http://discuss.ardupilot.org/uploads/default/original/2X/3/3f849fd58618435a299234a22e1203cac25765e2.png

what should be done?
I’m stuck at this. Would be grateful if you could help

Thanks & Regards
Sameena Shaikh

Visit Topic
http://discuss.ardupilot.org/t/read-gps-and-imu-data-form-pixhawk-to-raspberry-pi/17436/5

Hello Sameena,
You have successfully made the mavlink connection.
Now you have to write a code in C or python to access the data that you
need.
Follow the python syntax that i send in my last email.
Address the serial port as you did in the command line.

http://python.dronekit.io/guide/quick_start.html#installation

Follow the steps in the above link to install dronekit python.

http://python.dronekit.io/examples/vehicle_state.html

Take the help from the example code to write your own. If you do not want
to work with Dronekit SITL, then wisely remove the sitl parts from the
code.

Regards
Ronnie

To unsubscribe from these emails, click here

Hi Ronnie,
Thanks for the help.
Yesi will write a python code for it.
But how can i get real time data like pitch n roll through commands. I frst need to do that and then next go to writing a python script

Hello Sameena,
http://mavlink.org/messages/common
Message number 30 gives you the roll, pitch and yaw information.
Regards
Ronnie

Hi Ronnie,
I tried running that code from the start guide hello drone and got this error. Trying to figure out this error

pi@raspberrypi:~ $ python hello.py
Start simulator (SITL)
Starting copter simulator (SITL)
SITL already Downloaded and Extracted.
Ready to boot.
Failed to run (/home/pi/.dronekit/sitl/copter-3.3/apm)
Traceback (most recent call last):
File “hello.py”, line 3, in
sitl = dronekit_sitl.start_default()
File “/home/pi/.local/lib/python2.7/site-packages/dronekit_sitl/init.py”, line 454, in start_default
sitl.launch(sitl_args, await_ready=True, restart=True)
File “/home/pi/.local/lib/python2.7/site-packages/dronekit_sitl/init.py”, line 253, in launch
caps = ArdupilotCapabilities(self.path)
File “/home/pi/.local/lib/python2.7/site-packages/dronekit_sitl/init.py”, line 165, in init
self.has_defaults_path = “–defaults path” in helptext
UnboundLocalError: local variable ‘helptext’ referenced before assignment

and the meassage or command for getting the imu data should be given how. Like i used param set arming_check 0. It was successful. bt when i use get_imu or attitude i get unknown command

There might be some issue with your sitl setup.
Mavlink messages directly feeding into cmd line is something i never tried
for it doesnt serve my purpose.
However the mavlink messages works fine with python and C.

Hi,
Did you use it on assh client server or just with a screen on raspberry pi. On some blog i read sitl wont work for arm processors…

I can receive the messages with python and C. But it can only get three types(though I have set it to get all the information),


I need the IMU message, GPS, how can I get them.

Hi, I meet the same issue with you! Have you get the method?

Servers by jDrones