PX4 ROS 2 Interface Library
Library to interface with PX4 from a companion computer using ROS 2
Loading...
Searching...
No Matches
trajectory.hpp
1/****************************************************************************
2 * Copyright (c) 2023 PX4 Development Team.
3 * SPDX-License-Identifier: BSD-3-Clause
4 ****************************************************************************/
5
6#pragma once
7
8#include <px4_msgs/msg/trajectory_setpoint.hpp>
9#include <Eigen/Eigen>
10
11#include <px4_ros2/common/setpoint_base.hpp>
12
13namespace px4_ros2
14{
19struct TrajectorySetpoint;
20
27{
28public:
29 explicit TrajectorySetpointType(Context & context);
30
31 ~TrajectorySetpointType() override = default;
32
33 Configuration getConfiguration() override;
34
35 void update(
36 const Eigen::Vector3f & velocity_ned_m_s,
37 const std::optional<Eigen::Vector3f> & acceleration_ned_m_s2 = {},
38 std::optional<float> yaw_ned_rad = {},
39 std::optional<float> yaw_rate_ned_rad_s = {});
40
51 void update(const TrajectorySetpoint & setpoint);
52
61 const Eigen::Vector3f & position_ned_m);
62
63private:
64 rclcpp::Node & _node;
65 rclcpp::Publisher<px4_msgs::msg::TrajectorySetpoint>::SharedPtr _trajectory_setpoint_pub;
66};
67
93{
94 std::optional<float> position_ned_m_x;
95 std::optional<float> position_ned_m_y;
96 std::optional<float> position_ned_m_z;
97
98 std::optional<float> velocity_ned_m_s_x;
99 std::optional<float> velocity_ned_m_s_y;
100 std::optional<float> velocity_ned_m_s_z;
101
102 std::optional<float> acceleration_ned_m_s2_x;
103 std::optional<float> acceleration_ned_m_s2_y;
104 std::optional<float> acceleration_ned_m_s2_z;
105
106 std::optional<float> yaw_ned_rad;
107 std::optional<float> yaw_rate_ned_rad_s;
108
109
116 {
117 position_ned_m_x = x_ned_m;
118 return *this;
119 }
120
127 {
128 position_ned_m_y = y_ned_m;
129 return *this;
130 }
131
138 {
139 position_ned_m_z = z_ned_m;
140 return *this;
141 }
142
149 {
150 velocity_ned_m_s_x = x_ned_m_s;
151 return *this;
152 }
153
160 {
161 velocity_ned_m_s_y = y_ned_m_s;
162 return *this;
163 }
164
171 {
172 velocity_ned_m_s_z = z_ned_m_s;
173 return *this;
174 }
175
182 {
183 acceleration_ned_m_s2_x = x_ned_m_s2;
184 return *this;
185 }
186
193 {
194 acceleration_ned_m_s2_y = y_ned_m_s2;
195 return *this;
196 }
197
204 {
205 acceleration_ned_m_s2_z = z_ned_m_s2;
206 return *this;
207 }
208
215 {
216 this->yaw_ned_rad = yaw_rad;
217 return *this;
218 }
219
225 TrajectorySetpoint & withYawRate(float rate_rad_s)
226 {
227 this->yaw_rate_ned_rad_s = rate_rad_s;
228 return *this;
229 }
230
231 // Helper methods for setting multiple components at once
237 TrajectorySetpoint & withPosition(const Eigen::Vector3f & position_ned_m)
238 {
239 position_ned_m_x = position_ned_m.x();
240 position_ned_m_y = position_ned_m.y();
241 position_ned_m_z = position_ned_m.z();
242 return *this;
243 }
244
250 TrajectorySetpoint & withHorizontalPosition(const Eigen::Vector2f & position_ned_m)
251 {
252 position_ned_m_x = position_ned_m.x();
253 position_ned_m_y = position_ned_m.y();
254 return *this;
255 }
256
262 TrajectorySetpoint & withVelocity(const Eigen::Vector3f & velocity_ned_m_s)
263 {
264 velocity_ned_m_s_x = velocity_ned_m_s.x();
265 velocity_ned_m_s_y = velocity_ned_m_s.y();
266 velocity_ned_m_s_z = velocity_ned_m_s.z();
267 return *this;
268 }
269
275 TrajectorySetpoint & withHorizontalVelocity(const Eigen::Vector2f & velocity_ned_m_s)
276 {
277 velocity_ned_m_s_x = velocity_ned_m_s.x();
278 velocity_ned_m_s_y = velocity_ned_m_s.y();
279 return *this;
280 }
281
287 TrajectorySetpoint & withAcceleration(const Eigen::Vector3f & acceleration_ned_m_s2)
288 {
289 acceleration_ned_m_s2_x = acceleration_ned_m_s2.x();
290 acceleration_ned_m_s2_y = acceleration_ned_m_s2.y();
291 acceleration_ned_m_s2_z = acceleration_ned_m_s2.z();
292 return *this;
293 }
294
300 TrajectorySetpoint & withHorizontalAcceleration(const Eigen::Vector2f & acceleration_ned_m_s2)
301 {
302 acceleration_ned_m_s2_x = acceleration_ned_m_s2.x();
303 acceleration_ned_m_s2_y = acceleration_ned_m_s2.y();
304 return *this;
305 }
306};
307
308
309} /* namespace px4_ros2 */
Definition context.hpp:20
Definition setpoint_base.hpp:20
Setpoint type for trajectory control.
Definition trajectory.hpp:27
void updatePosition(const Eigen::Vector3f &position_ned_m)
Position setpoint update.
void update(const TrajectorySetpoint &setpoint)
Update the setpoint with full flexibility by passing a TrajectorySetpoint.
Definition setpoint_base.hpp:25
Setpoint structure for trajectory control with fine-grained control over individual components.
Definition trajectory.hpp:93
TrajectorySetpoint & withYaw(float yaw_rad)
Set yaw setpoint in NED frame.
Definition trajectory.hpp:214
TrajectorySetpoint & withHorizontalAcceleration(const Eigen::Vector2f &acceleration_ned_m_s2)
Set acceleration setpoint for horizontal axes (x, y) in NED frame.
Definition trajectory.hpp:300
TrajectorySetpoint & withHorizontalVelocity(const Eigen::Vector2f &velocity_ned_m_s)
Set velocity setpoint for horizontal axes (x, y) in NED frame.
Definition trajectory.hpp:275
TrajectorySetpoint & withHorizontalPosition(const Eigen::Vector2f &position_ned_m)
Set position setpoint for horizontal axes (x, y) in NED frame.
Definition trajectory.hpp:250
TrajectorySetpoint & withPositionX(float x_ned_m)
Set position setpoint for x-axis in NED frame.
Definition trajectory.hpp:115
TrajectorySetpoint & withAccelerationY(float y_ned_m_s2)
Set acceleration setpoint for y-axis in NED frame.
Definition trajectory.hpp:192
TrajectorySetpoint & withYawRate(float rate_rad_s)
Set yaw rate setpoint in NED frame.
Definition trajectory.hpp:225
TrajectorySetpoint & withAcceleration(const Eigen::Vector3f &acceleration_ned_m_s2)
Set acceleration setpoint for all axes (x, y, z) in NED frame.
Definition trajectory.hpp:287
TrajectorySetpoint & withVelocityX(float x_ned_m_s)
Set velocity setpoint for x-axis in NED frame.
Definition trajectory.hpp:148
TrajectorySetpoint & withPositionY(float y_ned_m)
Set position setpoint for y-axis in NED frame.
Definition trajectory.hpp:126
TrajectorySetpoint & withVelocityZ(float z_ned_m_s)
Set velocity setpoint for z-axis in NED frame.
Definition trajectory.hpp:170
TrajectorySetpoint & withAccelerationX(float x_ned_m_s2)
Set acceleration setpoint for x-axis in NED frame.
Definition trajectory.hpp:181
TrajectorySetpoint & withPositionZ(float z_ned_m)
Set position setpoint for z-axis in NED frame.
Definition trajectory.hpp:137
TrajectorySetpoint & withVelocity(const Eigen::Vector3f &velocity_ned_m_s)
Set velocity setpoint for all axes (x, y, z) in NED frame.
Definition trajectory.hpp:262
TrajectorySetpoint & withPosition(const Eigen::Vector3f &position_ned_m)
Set position setpoint for all axes (x, y, z) in NED frame.
Definition trajectory.hpp:237
TrajectorySetpoint & withAccelerationZ(float z_ned_m_s2)
Set acceleration setpoint for z-axis in NED frame.
Definition trajectory.hpp:203
TrajectorySetpoint & withVelocityY(float y_ned_m_s)
Set velocity setpoint for y-axis in NED frame.
Definition trajectory.hpp:159