You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the command prompt you should see (something like):
49
44
50
-
The ``--connect`` parameter above connects to SITL on udp port 127.0.0.1:14550, while
51
-
``--mission_id`` specifies we're replaying mission 101. Both of these are the default
52
-
values for the parameters, and may be omitted.
53
-
45
+
.. code:: bash
46
+
47
+
Generating waypoints from tlog...
48
+
Generated 96 waypoints from tlog
49
+
Starting copter simulator (SITL)
50
+
SITL already Downloaded.
51
+
Connecting to vehicle on: tcp:127.0.0.1:5760
52
+
>>> APM:Copter V3.3 (d6053245)
53
+
>>> Frame: QUAD
54
+
>>> Calibrating barometer
55
+
>>> Initialising APM...
56
+
>>> barometer calibration complete
57
+
>>> GROUND START
58
+
Uploading 96 waypoints to vehicle...
59
+
Arm and Takeoff
60
+
Waiting for vehicle to initialise...
61
+
>>> flight plan received
62
+
Waiting for arming...
63
+
...
64
+
Waiting for arming...
65
+
>>> ARMING MOTORS
66
+
>>> GROUND START
67
+
Waiting for arming...
68
+
>>> Initialising APM...
69
+
Waiting for arming...
70
+
>>> ARMING MOTORS
71
+
Taking off!
72
+
Altitude: 0.010000 < 28.500000
73
+
Altitude: 0.020000 < 28.500000
74
+
...
75
+
Altitude: 26.150000 < 28.500000
76
+
Altitude: 28.170000 < 28.500000
77
+
Reached target altitude of ~30.000000
78
+
Starting mission
79
+
Distance to waypoint (1): 6.31671220061
80
+
Distance to waypoint (1): 5.54023406731
81
+
>>> Reached Command #1
82
+
Distance to waypoint (2): 4.05805003875
83
+
...
84
+
Distance to waypoint (2): 4.66600036548
85
+
>>> Reached Command #2
86
+
Distance to waypoint (3): 1.49371523482
87
+
Distance to waypoint (3): 0.13542601646
88
+
Distance to waypoint (3): 0.708432959397
89
+
>>> Reached Command #3
90
+
Distance to waypoint (4): 3.29161427437
91
+
Distance to waypoint (4): 3.63454331996
92
+
Distance to waypoint (4): 2.89070828637
93
+
>>> Reached Command #4
94
+
Distance to waypoint (5): 0.955857968149
95
+
>>> Reached Command #5
96
+
>>> Reached Command #6
97
+
>>> Reached Command #7
98
+
...
99
+
>>> Reached Command #42
100
+
Distance to waypoint (42): 7.6983209285
101
+
...
102
+
Distance to waypoint (43): 6.05247510021
103
+
>>> Reached Command #43
104
+
Distance to waypoint (43): 4.80180763387
105
+
>>> Reached Command #44
106
+
Distance to waypoint (44): 3.89880557617
107
+
...
108
+
Distance to waypoint (45): 11.0865559753
109
+
>>> Reached Command #45
110
+
Distance to waypoint (46): 9.45419808223
111
+
...
112
+
Distance to waypoint (46): 13.2676499949
113
+
Return to launch
114
+
Close vehicle object
115
+
Completed...
116
+
117
+
.. tip::
118
+
119
+
It is more interesting to watch the example run on a map than the console. The topic :ref:`viewing_uav_on_map`
120
+
explains how to set up *Mission Planner* to view a vehicle running on the simulator (SITL).
54
121
55
-
.. tip::
56
-
57
-
It is more interesting to watch the example above on a map than the console. The topic :ref:`viewing_uav_on_map`
58
-
explains how to set up *Mission Planner* to view a vehicle running on the simulator (SITL).
122
+
#. You can run the example against a specific connection (simulated or otherwise) by passing the :ref:`connection string <get_started_connect_string>` for your vehicle in the ``--connect`` parameter.
59
123
60
-
On the command prompt you should see (something like):
124
+
For example, to connect to SITL running on UDP port 14550 on your local computer:
61
125
62
-
.. code-block:: bash
63
-
64
-
Connecting to vehicle on: 127.0.0.1:14550
65
-
>>> APM:Copter V3.3 (d6053245)
66
-
>>> Frame: QUAD
67
-
JSON downloaded...
68
-
Generating 95 waypoints from replay...
69
-
Close vehicle object
70
-
Completed...
126
+
.. code-block:: bash
71
127
128
+
python simple_goto.py --connect 127.0.0.1:14550
129
+
72
130
131
+
73
132
How it works
74
133
============
75
134
76
-
The example requests the web server for representative points from the flight, parses the JSON response
77
-
and uses that data to generate 100 waypoints. These are then sent to the vehicle.
135
+
The example parses the **flight.tlog** file for position information. It then selects about 100
136
+
points that are evenly spread across the log and uploads them as a mission.
78
137
138
+
For safety reasons, the altitude for the waypoints is set to 30 meters (irrespective of the recorded height).
79
139
80
140
Getting the points
81
141
------------------
82
142
83
-
The following simple function asks for the droneshare flight data:
143
+
The following simple function parses the tlog for points and then
144
+
returns 100 evenly points from the collected set.
84
145
85
146
.. code:: python
86
147
87
-
defdownload_messages(mission_id, max_freq=1.0):
88
-
"""Download a public mission from droneshare (as JSON)"""
89
-
f = urllib.urlopen("%s/api/v1/mission/%s/messages.json?max_freq=%s&api_key=%s"% (api_server, mission_id, max_freq, api_key))
90
-
j = json.load(f, object_hook=_decode_dict)
91
-
f.close()
92
-
return j
93
-
94
-
Some comments:
148
+
defposition_messages_from_tlog(filename):
149
+
"""
150
+
Given telemetry log, get a series of waypoints approximating the previous flight
151
+
"""
152
+
# Pull out just the global position msgs
153
+
messages = []
154
+
mlog = mavutil.mavlink_connection(filename)
155
+
whileTrue:
156
+
try:
157
+
m = mlog.recv_match(type=['GLOBAL_POSITION_INT'])
158
+
if m isNone:
159
+
break
160
+
exceptException:
161
+
break
162
+
# ignore we get where there is no fix:
163
+
if m.lat ==0:
164
+
continue
165
+
messages.append(m)
166
+
167
+
# Shrink the # of pts to be lower than the max # of wpts allowed by vehicle
shorter = [messages[i] for i inxrange(0, num_points, step)]
173
+
messages = shorter
174
+
return messages
95
175
96
-
* ``max_freq`` is used to throttle the messages found in the raw flight data to a lower message rate
97
-
* ``_decode_dict`` is a utility function found on stack overflow which extracts usable strings from unicode encoded JSON (see `flight_replay.py <https://github.com/hamishwillee/dronekit-python/blob/master/examples/flight_replay/flight_replay.py>`_ for its implementation).
0 commit comments