dronekit / dronekit-python

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

play_tune example does not work #757

Open GekoCH opened 6 years ago

GekoCH commented 6 years ago

Hy

the play_tune example does not work with the dronekit version 2.9.1 is this there not yert implemented? AttributeError: 'Vehicle' object has no attribute 'play_tune'

Andy

peterbarker commented 6 years ago

On Thu, 12 Oct 2017, GekoCH wrote:

the play_tune example does not work with the dronekit version 2.9.1 is this there not yert implemented? AttributeError: 'Vehicle' object has no attribute 'play_tune'

Some other dronekit-python is in your path. If the example is present in a checkout then the vehicle will have the code for it...

GekoCH commented 6 years ago

hmm I did install the dronekit over pip install do I need to clone the GIT and use it that way?

peterbarker commented 6 years ago

On Thu, 12 Oct 2017, GekoCH wrote:

hmm I did install the dronekit over pip install do I need to clone the GIT and use it that way?

Yes. And pip uninstall the pip-installed version to avoid confusion.

I assume you grabbed the demo from the internet, then?

GekoCH commented 6 years ago

I did that and now did the same thing with the MAVproxy everything is now loaded by GIT and installed but still now I get this error: AttributeError: 'MAVLink' object has no attribute 'play_tune_encode'

edit: yes I saw the demo by searching for play tune

peterbarker commented 6 years ago

On Thu, 12 Oct 2017, GekoCH wrote:

I did that and now did the same thing with the MAVproxy everything is now loaded by GIT and installed but still now I get this error: AttributeError: 'MAVLink' object has no attribute 'play_tune_encode'

Sorry, now you need to update your pymavlink :-)

You can do this in much the same way as you did dronekit-python, with the exception that you need to tell setup.py where to find the message definitions. I usually do this with:

MDEF=$HOME/rc/ardupilot/modules/mavlink/message_definitions python setup.py build install --user --force

GekoCH commented 6 years ago

sorry to disturb you once more...

ok I did now clone https://github.com/ArduPilot/pymavlink and https://github.com/ArduPilot/mavlink

the I did run the python setup.py build and sudo python setup.py install command in den pymavlink folder

then I used the command MDEF=$HOME/xxx/mavlink/message_definitions and python setup.py build install --user --force in the pymavlink folder

but I still get the error message AttributeError: 'MAVLink' object has no attribute 'play_tune_encode'

what am I doing wrong?

peterbarker commented 6 years ago

On Thu, 12 Oct 2017, GekoCH wrote:

but I still get the error message AttributeError: 'MAVLink' object has no attribute 'play_tune_encode'

what am I doing wrong?

Did you remove the pip-installed version of pymavlink?

Yeep removing things with pip 'til it starts telling there's none left, then install from the reo....

GekoCH commented 6 years ago

i did remove but now when I look for the new installed by using pip list there is no pymavlink even the code posted above finished with Finished processing dependencies for pymavlink==2.2.5

without --user it does appear but still no success...

even if I go to the installtion folder :/usr/local/lib/python2.7/dist-packages/pymavlink-2.2.5-py2.7-linux-armv7l.egg/pymavlink/dialects/v10$ and search in the common.xml file I can finde the message 258 PLAY_TUNE

I also did a search in all git folder (dronekit-python-master, mavlink-master, pymavlink-master, MAVProxy-master, ardupilot-master) and couldn't find play_tune_encode (only found it in the __init__.py file of dronekit where it gets called)

APMLover commented 6 years ago

Im suffering this issues too. it worked well with JTK1 board but with new raspberry it doesnt work

sgh055 commented 6 years ago

play_tune function doesn't work in raspberry Pi3 and ubuntu image how fix it?

sgh055 commented 6 years ago

I try mavlink message...

def send_play_tune(tune): msg = vehicle.message_factory.play_tune_encode(0, 0, tune) vehicle.send_mavlink(msg)

it doesn't work image

no attribute play_tune / play_tune_encode

tizianofiorenzani commented 6 years ago

So, it looks like you need to set mavlink2 typing MAVLINK20=1. I set it up in rc.local

YusufYigitbasi commented 6 years ago

On linux ubuntu i tested dronekit-sitl copter simulation simple_go_to.py when i entered "mavproxy.py --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501 --out 127.0.0.1:14550 --out 127.0.0.1:14551 --map --console" on terminal it gave this crush Terminal map and console connection error :

Exception in thread main_loop: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 801, in bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 754, in run self.target(*self.args, **self.__kwargs) File "/home/yusuf/.local/bin/mavproxy.py", line 783, in main_loop master.wait_heartbeat() File "/usr/local/lib/python2.7/dist-packages/pymavlink/mavutil.py", line 383, in wait_heartbeat return self.recv_match(type='HEARTBEAT', blocking=blocking) File "/usr/local/lib/python2.7/dist-packages/pymavlink/mavutil.py", line 344, in recv_match m = self.recv_msg() File "/usr/local/lib/python2.7/dist-packages/pymavlink/mavutil.py", line 318, in recv_msg msg = self.mav.parse_char(s) File "/usr/local/lib/python2.7/dist-packages/pymavlink/dialects/v10/ardupilotmega.py", line 9257, in parse_char self.callbacks(m) File "/usr/local/lib/python2.7/dist-packages/pymavlink/dialects/v10/ardupilotmega.py", line 9234, in __callbacks self.callback(msg, *self.callback_args, **self.callback_kwargs) File "/home/yusuf/.local/lib/python2.7/site-packages/MAVProxy/modules/mavproxy_link.py", line 460, in master_callback mavutil.mavlink.MAV_TYPE_DODECAROTOR]: AttributeError: 'module' object has no attribute 'MAV_TYPE_DODECAROTOR' then when i wanted to run simple_go_to.py it gave timeout error: Link timeout, no heartbeat in last 5 seconds

No heartbeat in 30 seconds, aborting. Traceback (most recent call last): File "simple_goto.py", line 38, in vehicle = connect(connection_string, wait_ready=True) File "/home/yusuf/.local/lib/python2.7/site-packages/dronekit/init.py", line 2845, in connect vehicle.initialize(rate=rate, heartbeat_timeout=heartbeat_timeout) File "/home/yusuf/.local/lib/python2.7/site-packages/dronekit/init.py", line 2117, in initialize raise APIException('Timeout in initializing connection.') dronekit.APIException: Timeout in initializing connection.

pip version is 8.1.1 python : 2.7 mavlink 2.0.6 what should i do i saw? someone said that upgrade mavlink to 2.2.8 but i couldnt do that thanks for help :)

peterbarker commented 6 years ago

On Sat, 30 Jun 2018, YusufYigitbasi wrote:

what should i do i saw? someone said that upgrade mavlink to 2.2.8 but i couldnt do that

Upgrading that is the solution.

Why can't you upgrade?

tizianofiorenzani commented 5 years ago

The current implementation of vehicle.play_tunes is not compatible with the last Mavlink protocol. An extra argument is expected. Here it is my simple patch in the code: if vehicle.version.major == 3 and vehicle.version.minor <= 5 and vehicle.version.patch <=5:

print ("Older than 3.5.5 release")

                    vehicle.play_tune(tune_to_play)
                else:
                    # print ("New release")
                    msg = vehicle.message_factory.play_tune_encode(0, 0, tune_to_play, tune_to_play)
                    vehicle.send_mavlink(msg)
                # print ("-- Tune Played --")
peterbarker commented 5 years ago

On Fri, 12 Oct 2018, Tiziano Fiorenzani wrote:

The current implementation of vehicle.play_tunes is not compatible with the last Mavlink protocol. An extra argument is expected. Here it is my simple

What error do you get with the old code?

tizianofiorenzani commented 5 years ago

Something like "s must be a string"

On Fri, Oct 12, 2018, 4:19 PM Peter Barker notifications@github.com wrote:

On Fri, 12 Oct 2018, Tiziano Fiorenzani wrote:

The current implementation of vehicle.play_tunes is not compatible with the last Mavlink protocol. An extra argument is expected. Here it is my simple

What error do you get with the old code?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dronekit/dronekit-python/issues/757#issuecomment-429465373, or mute the thread https://github.com/notifications/unsubscribe-auth/AB-xskyC8yyvXOimm_Ujxe97U87rTbyxks5ukQdMgaJpZM4P2jqZ .

peterbarker commented 5 years ago

Please note your autopilot has to speaking mavlink2 for play_tune_encode to appear.

That's param set SERIAL0_PROTOCOL 2 in MAVProxy.

peterbarker commented 5 years ago

On Fri, 12 Oct 2018, Tiziano Fiorenzani wrote:

Something like "s must be a string"

OK, so I reproduced that easily enough, thanks.

I've a concern about the patch you're suggesting here, however. It will certainly fix the test - but it's a workaround.

I think this issue might arise any time a message has extensions; we need to come to grips with the wider problem, I think.

peterbarker commented 5 years ago

https://github.com/ArduPilot/pymavlink/blob/master/generator/mavgen_python.py#L315 <- that's the problem line.

peterbarker commented 5 years ago

https://github.com/ArduPilot/pymavlink/pull/227 <- I believe that might be the correct fix.

tizianofiorenzani commented 5 years ago

Thanks Peter, the suggestion for patching was very quick and dirty, more for giving an idea of the problem rather that been a real solution. I will test it right away

On Mon, Oct 15, 2018, 5:00 AM Peter Barker notifications@github.com wrote:

ArduPilot/pymavlink#227 https://github.com/ArduPilot/pymavlink/pull/227 <- I believe that might be the correct fix.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dronekit/dronekit-python/issues/757#issuecomment-429783263, or mute the thread https://github.com/notifications/unsubscribe-auth/AB-xsjMY9MhE_QKXbsLoa4omffXoeobrks5ulFyggaJpZM4P2jqZ .

tizianofiorenzani commented 5 years ago

Just uninstalled pymavlink and reinstalled through dronekit (went from 2.2.15 to 2.2.16). I still get "argument for 's' must be a string" when I call play_tunes. MAVLINK20 is set to 1

peterbarker commented 5 years ago

On Mon, 15 Oct 2018, Tiziano Fiorenzani wrote:

Just uninstalled pymavlink and reinstalled through dronekit (went from 2.2.15 to 2.2.16). I still get "argument for 's' must be a string" when I call play_tunes. MAVLINK20 is set to 1

The patch is still in the PR I referenced - not even merged yet, let alone released into the wild :-)

peterbarker commented 5 years ago

On Tue, 16 Oct 2018, Peter Barker wrote:

The patch is still in the PR I referenced - not even merged yet, let alone released into the wild :-)

The PR has now been merged.

Next pymavlink release will have the fix.

In the meantime you can run from the master branch if you need the fix :-)

sergiimokin commented 1 month ago

I am using pymavlink version 2.4.41 and have installed mavlink from the main branch of https://github.com/mavlink/mavlink.git.

However, I am still encountering the following error:

Traceback (most recent call last):
  File "/home/opi/ws/mavlink/play_tune.py", line 41, in <module>
    vehicle.play_tune(args.tune)
  File "/home/opi/.venv/lib/python3.11/site-packages/dronekit/__init__.py", line 2362, in play_tune
    msg = self.message_factory.play_tune_encode(0, 0, tune)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'MAVLink' object has no attribute 'play_tune_encode'. Did you mean: 'altitude_encode'?

I have carefully reviewed the related topic from 2018, and I believed this issue had been resolved. However, the problem still persists for me.

Could you please provide any guidance or updates on how to resolve this issue?

Thank you.