24 #include <geometry_msgs/Point.h> 25 #include <geometry_msgs/PoseStamped.h> 26 #include <geometry_msgs/TwistStamped.h> 102 nh_sp.
param<std::string>(
"mode", mode_,
"position");
114 nh_sp.
param<std::string>(
"shape", shape_,
"square");
116 if (mode_ ==
"position")
118 else if (mode_ ==
"velocity")
120 else if (mode_ ==
"acceleration")
123 ROS_ERROR_NAMED(
"sitl_test",
"Control mode: wrong/unexistant control mode name %s", mode_.c_str());
127 if (shape_ ==
"square")
129 else if (shape_ ==
"circle")
131 else if (shape_ ==
"eight")
133 else if (shape_ ==
"ellipse")
136 ROS_ERROR_NAMED(
"sitl_test",
"Path shape: wrong/unexistant path shape name %s", shape_.c_str());
143 void spin(
int argc,
char *argv[]) {
147 ROS_INFO(
"SITL Test: Offboard control test running!");
150 ROS_INFO(
"Position control mode selected.");
153 ROS_INFO(
"Velocity control mode selected.");
156 ROS_INFO(
"Acceleration control mode selected.");
157 ROS_ERROR_NAMED(
"sitl_test",
"Control mode: acceleration control mode not supported in PX4 current Firmware.");
165 ROS_INFO(
"Test option: square-shaped path...");
169 ROS_INFO(
"Test option: circle-shaped path...");
173 ROS_INFO(
"Test option: eight-shaped path...");
177 ROS_INFO(
"Test option: ellipse-shaped path...");
211 geometry_msgs::TwistStamped
vs;
224 return Eigen::Vector3d(tr_x * 2.0
f, tr_y * 2.0f, tr_z * 1.0f);
269 uint8_t pos_target = 1;
277 switch (pos_target) {
297 if (pos_target == 6) {
327 Eigen::Vector3d(5.0f, 0.0f, 1.0f), current, last_time), vs.twist.linear);
329 tf::vectorEigenToMsg(Eigen::Vector3d(5.0
f - current.x(), -current.y(), 1.0f - current.z()), vs.twist.linear);
340 for (
int theta = 0; theta <= 360; theta++) {
387 Eigen::Vector3d(0.0f, 0.0f, 1.0f), current, last_time), vs.twist.linear);
389 tf::vectorEigenToMsg(Eigen::Vector3d(-current.x(), -current.y(), 1.0f - current.z()), vs.twist.linear);
400 for (
int theta = -180; theta <= 180; theta++) {
447 Eigen::Vector3d(0.0f, 0.0f, 2.5f), current, last_time), vs.twist.linear);
449 tf::vectorEigenToMsg(Eigen::Vector3d(-current.x(), -current.y(), 2.5f - current.z()), vs.twist.linear);
460 for (
int theta = 0; theta <= 360; theta++) {
498 Eigen::Vector3d
dest;
501 double err_th = threshold[rand() % threshold.size()];
503 ROS_DEBUG(
"Next setpoint: accepted error threshold: %1.3f", err_th);
509 distance =
sqrt((dest - current).
x() * (dest - current).
x() +
510 (dest - current).
y() * (dest - current).
y() +
511 (dest - current).
z() * (dest - current).
z());
513 if (distance <= err_th)
517 local_pos_sp_pub.
publish(target);
540 std::random_device rd;
541 std::mt19937 gen(rd());
542 std::array<double, 100> th_values;
544 std::normal_distribution<double> th(0.1
f,0.05
f);
546 for (
auto &value : th_values) {
SitlTest node implementation class.
void publish(const boost::shared_ptr< M > &message) const
void setup_yawrate_pid(double p_gain, double i_gain, double d_gain, double i_max, double i_min, const ros::NodeHandle &node)
Sets up the PID values for computation of the yaw rate effort.
pidcontroller::PIDController pid
std::array< double, 100 > threshold
geometry_msgs::TwistStamped vs
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
geometry_msgs::PoseStamped localpos
Eigen::Vector3d pos_setpoint(int tr_x, int tr_y, int tr_z)
Defines single position setpoint.
ros::Subscriber local_pos_sub
control_mode
Offboard controller tester.
void setup_linvel_pid(double p_gain, double i_gain, double d_gain, double i_max, double i_min, const ros::NodeHandle &node)
Sets up the PID values for computation of the linear velocities effort.
static double from_degrees(double degrees)
void vectorEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Vector3 &m)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
std::array< double, 100 > threshold_definition()
Gaussian noise generator for accepted position threshold.
void pointMsgToEigen(const geometry_msgs::Point &m, Eigen::Vector3d &e)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
TFSIMD_FORCE_INLINE const tfScalar & z() const
void pointEigenToMsg(const Eigen::Vector3d &e, geometry_msgs::Point &m)
void spin(int argc, char *argv[])
ros::Publisher local_pos_sp_pub
ros::Publisher vel_sp_pub
geometry_msgs::PoseStamped ps
void local_pos_cb(const geometry_msgs::PoseStampedConstPtr &msg)
void wait_and_move(geometry_msgs::PoseStamped target)
Defines the accepted threshold to the destination/target position before moving to the next setpoint...
Eigen::Vector3d ellipse_shape(int angle)
Defines ellipse path.
#define ROS_ERROR_NAMED(name,...)
ROSCPP_DECL void shutdown()
Eigen::Vector3d eight_shape(int angle)
Defines Gerono lemniscate path.
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
void ellipse_path_motion(ros::Rate loop_rate, control_mode mode)
Ellipse path motion routine.
void eight_path_motion(ros::Rate loop_rate, control_mode mode)
Eight path motion routine.
ROSCPP_DECL void spinOnce()
Eigen::Vector3d compute_linvel_effort(Eigen::Vector3d goal, Eigen::Vector3d current, ros::Time last_time)
Computes the linear velocity effort to apply to each axis.
Eigen::Vector3d circle_shape(int angle)
Defines circle path.
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
void square_path_motion(ros::Rate loop_rate, control_mode mode)
Square path motion routine.
void circle_path_motion(ros::Rate loop_rate, control_mode mode)
Circle path motion routine.