Takeoff_and_land.py error


#1

Hi, we are unable to run the autonomous takeoff_and_land.py script. Instead of writing the code we copied it from a GitHub repository linked blow the video. When we attempt to run the script with the line “python takeoff_and_land.py --connect 127.0.0.1:14550”, we get the error:
" File “takeoff_and_land.py”, line 13, in
targetAltitude=float(sys.argv[1])
ValueError: could not convert string to float: – connect "

Also, are we supposed to change our port number from the one in your video, or is it universal? And if so, how do we find the right port number?


#2

Hey Fritz,

I feel your confusion here, it seems like lines 10 through 15 could be rewritten.

11   targetAltitude=1
12   if len(sys.argv)>1:
13      targetAltitude=float(sys.argv[1])
14   else:
15      targetAltitude=1

Some python background: argv is the list of command line arguments passed to the Python script. argv[0] is the script name (takeoff_and_land.py in this case), argv[1], [2]…[x] are the next arguments.

Here, the “- -connect” is interpreted as argv[1] however the script covered in the video tutorial is different than the one in the Github! For that reason, I’d say you should not use any arguments after the script name in the terminal. The only argument you could optionally enter would be the target altitude, as the ip address to connect to is handled in line 18:

17     ############DRONEKIT#################
18     vehicle = connect('udp:127.0.0.1:14550',wait_ready=True)

Now your next question regarding the port number/ip address, I think most of your questions can be answered in the “Configure Ardupilot on RPI (Navio))” where you can see how to configure the ardupilot telemetry ports. By default, Telem1 is set to the local host (127.0.0.1) on the 14550 port.

To summarize, simply running “python takeoff_and_land.py" with the script from Github should run successfully and will be preconfigured to takeoff to a height of 1m. If its your first time (which it sounds like it is) I highly recommend you remove the props and check if the scripts executes correctly.

Cheers,
Jon


#3

1st: @PhotonJon 10 points


closed #4