Skip to content

Commit a2d89d6

Browse files
committed
Comments + Indoor navigation
1 parent 2681c9b commit a2d89d6

File tree

5 files changed

+33
-105
lines changed

5 files changed

+33
-105
lines changed

Indoor_navigation.pdf

2.75 MB
Binary file not shown.

README.md

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,14 @@
1-
# solitude_test
2-
Solitude Aerial test case
1+
# Solitude Aerial test case
32

3+
Steps to reproduce:
4+
colcon build --packages-select px4_ros_com ros2_aruco px4_msgs && source install/local_setup.bash
5+
~/src/PX4-Autopilot make px4_sitl gazebo-classic
6+
MicroXRCEAgent udp4 -p 8888
47

5-
git clone https://github.com/PX4/PX4-Autopilot
6-
git clone https://github.com/PX4/px4_msgs
7-
git clone --recursive https://github.com/Auterion/px4-ros2-interface-lib
8-
9-
pip3 install kconfiglib
10-
pip3 install symforce
11-
12-
ros2 run example_mode_manual_cpp example_mode_manual
13-
make px4_sitl gz_x500
14-
~/addons/src/PX4-Autopilot make px4_sitl gazebo-classic
15-
16-
micro-xrce-dds-agent udp4 -p 8888 / MicroXRCEAgent udp4 -p 8888
17-
ros2 run px4_ros_com offboard_control.py
8+
To test the drone's flight in a circle
189
ros2 run px4_ros_com circle_flight.py
1910

20-
./generate_markers_model.py -i /home/vadim/Downloads/gazebo_models/marker.png -s 2000 -w 1000
21-
PX4_SIM_WORLD=iris_irlock.world make px4_sitl gazebo-classic
22-
23-
24-
25-
export PX4_HOME_LAT=59.92545296605414
26-
export PX4_HOME_LON=30.358049691155855
27-
export PX4_HOME_ALT=28.5
28-
29-
30-
ros2 run rqt_image_view rqt_image_view
11+
To test flight of a drone in a straight line and AAruco marker detection:
12+
ros2 run px4_ros_com straight_flight.py
3113
ros2 launch ros2_aruco aruco_recognition.launch.py
32-
colcon build --packages-select px4_ros_com ros2_aruco
33-
source /home/vadim/solitude_test/install/local_setup.bash
3414

35-
QGroundControl
36-
place QGroundControl AppImage to /usr/local/bin
37-
QGroundControl.AppImage

src/px4_ros_com/src/examples/offboard_py/circle_flight.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from rclpy.node import Node
55
from rclpy.qos import QoSProfile, ReliabilityPolicy, HistoryPolicy, DurabilityPolicy
66
from px4_msgs.msg import OffboardControlMode, TrajectorySetpoint, VehicleCommand, VehicleLocalPosition, VehicleStatus
7-
from colorama import Fore
87
import math
98

10-
class OffboardControl(Node):
9+
10+
class CircleFlight(Node):
1111
"""Node for controlling a vehicle in offboard mode."""
1212

1313
def __init__(self) -> None:
@@ -36,10 +36,10 @@ def __init__(self) -> None:
3636
VehicleStatus, '/fmu/out/vehicle_status', self.vehicle_status_callback, qos_profile)
3737

3838
# Initialize variables
39-
self.offboard_setpoint_counter = 0
39+
self.offboard_setpoint_counter = 0 # Counter for offboard setpoint publishing
4040
self.vehicle_local_position = VehicleLocalPosition()
4141
self.vehicle_status = VehicleStatus()
42-
self.takeoff_height = -15.0
42+
self.takeoff_height = -15.0 # Desired takeoff height
4343
self.radius = 10.0 # Radius of the circle
4444
self.num_points = 36 # Number of points on the circle
4545
self.circle_points = self.generate_circle_points(self.radius, self.num_points)
@@ -132,25 +132,28 @@ def timer_callback(self) -> None:
132132
"""Callback function for the timer."""
133133
self.publish_offboard_control_heartbeat_signal()
134134

135+
# After 10 iterations, engage offboard mode and arm the vehicle
135136
if self.offboard_setpoint_counter == 10:
136137
self.engage_offboard_mode()
137138
self.arm()
138139

140+
# If the vehicle has reached the takeoff height and is in offboard mode, start flying in a circle
139141
if self.vehicle_local_position.z > self.takeoff_height and self.vehicle_status.nav_state == VehicleStatus.NAVIGATION_STATE_OFFBOARD:
140142
x, y = self.circle_points[self.point_index]
141143
self.publish_position_setpoint(x, y, self.takeoff_height)
142144
self.point_index = (self.point_index + 1) % len(self.circle_points)
143145

146+
# Increment the offboard setpoint counter until it reaches 11
144147
if self.offboard_setpoint_counter < 11:
145148
self.offboard_setpoint_counter += 1
146149

147150

148151
def main(args=None) -> None:
149-
print('Starting offboard control node...')
152+
print("Starting offboard control node, drone is flying in a circle")
150153
rclpy.init(args=args)
151-
offboard_control = OffboardControl()
152-
rclpy.spin(offboard_control)
153-
offboard_control.destroy_node()
154+
circle_flight = CircleFlight()
155+
rclpy.spin(circle_flight)
156+
circle_flight.destroy_node()
154157
rclpy.shutdown()
155158

156159

src/px4_ros_com/src/examples/offboard_py/create_&_detect_aruco.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/px4_ros_com/src/examples/offboard_py/straight_flight.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@
99
import numpy as np
1010
from std_msgs.msg import String
1111

12-
1312
def generate_linear_trajectory():
14-
"""Generate points in a linear."""
13+
"""Generate points in a linear trajectory from 0.01 to 300.1 with a step of 0.01."""
1514
x = np.arange(0.01, 300.1, 0.01).tolist()
16-
y = list(map(lambda y: y, x))
15+
y = list(map(lambda y: y, x)) # This line is redundant since y will be the same as x
1716
points = list(zip(x, y))
18-
1917
return points
2018

2119

22-
class OffboardControl(Node):
20+
class StraightFlightArucoDetection(Node):
2321
"""Node for controlling a vehicle in offboard mode."""
2422

2523
def __init__(self) -> None:
@@ -55,6 +53,7 @@ def __init__(self) -> None:
5553
self.takeoff_height = -2.6
5654
self.point_index = 0 # Index of the current point in the circle
5755
self.aruco_marker_detected = False
56+
5857
# Create a timer to publish control commands
5958
self.timer = self.create_timer(0.1, self.timer_callback)
6059

@@ -67,6 +66,7 @@ def vehicle_status_callback(self, vehicle_status):
6766
self.vehicle_status = vehicle_status
6867

6968
def aruco_callback(self, msg):
69+
"""Callback function for aruco_detected topic subscriber."""
7070
if msg is not None:
7171
self.aruco_marker_detected = True
7272
else:
@@ -138,11 +138,14 @@ def timer_callback(self) -> None:
138138
"""Callback function for the timer."""
139139
self.publish_offboard_control_heartbeat_signal()
140140

141+
# After 10 iterations, engage offboard mode and arm the vehicle
141142
if self.offboard_setpoint_counter == 10:
142143
self.engage_offboard_mode()
143144
self.arm()
144145

146+
# If the vehicle has reached the takeoff height and is in offboard mode, start flying in a circle
145147
if self.vehicle_local_position.z > self.takeoff_height and self.vehicle_status.nav_state == VehicleStatus.NAVIGATION_STATE_OFFBOARD:
148+
# If an Aruco marker is detected, hover at the previous point and change altitude to 1m
146149
if self.aruco_marker_detected:
147150
self.get_logger().info("Aruco marker detected, hovering...")
148151
points = generate_linear_trajectory()
@@ -154,21 +157,22 @@ def timer_callback(self) -> None:
154157
self.publish_position_setpoint(x, y, self.takeoff_height)
155158
self.point_index += 1
156159

160+
# Increment the offboard setpoint counter until it reaches 11
157161
if self.offboard_setpoint_counter < 11:
158162
self.offboard_setpoint_counter += 1
159163

160164

161165
def main(args=None) -> None:
162-
print('Starting offboard control node...')
166+
print('Starting offboard control node, straight flight and aruco marker detection')
163167
rclpy.init(args=args)
164-
offboard_control = OffboardControl()
165-
rclpy.spin(offboard_control)
166-
offboard_control.destroy_node()
168+
straight_flight = StraightFlightArucoDetection()
169+
rclpy.spin(straight_flight)
170+
straight_flight.destroy_node()
167171
rclpy.shutdown()
168172

169173

170174
if __name__ == '__main__':
171175
try:
172176
main()
173177
except Exception as e:
174-
print(e)
178+
print(e)

0 commit comments

Comments
 (0)