48 #define ACTUATOR_PUBLISH_PERIOD_MS 4 62 ModuleParams(nullptr),
93 _param_speed_imax.get(),
94 _param_gndspeed_max.get());
115 if (manual_updated) {
123 bool pos_sp_triplet_updated;
126 if (pos_sp_triplet_updated) {
137 if (att_sp_updated) {
165 bool setpoint =
true;
189 float mission_throttle = _param_throttle_cruise.get();
192 if (_param_speed_control_mode.get() == 1) {
195 float mission_target_speed = _param_gndspeed_trim.get();
204 const Vector3f vel = R_to_body *
Vector3f(ground_speed(0), ground_speed(1), ground_speed(2));
206 const float x_vel = vel(0);
210 mission_throttle = _param_throttle_speed_scaler.get()
214 mission_throttle =
math::constrain(mission_throttle, _param_throttle_min.get(), _param_throttle_max.get());
228 bool should_idle =
true;
230 if (pos_sp_triplet.
current.
type == position_setpoint_s::SETPOINT_TYPE_LOITER) {
244 }
else if (pos_sp_triplet.
current.
type == position_setpoint_s::SETPOINT_TYPE_POSITION ||
245 pos_sp_triplet.
current.
type == position_setpoint_s::SETPOINT_TYPE_TAKEOFF ||
246 pos_sp_triplet.
current.
type == position_setpoint_s::SETPOINT_TYPE_LAND) {
263 float desired_theta = (0.5f *
M_PI_F) - atan2f(desired_r, _param_wheel_base.get());
264 float control_effort = (desired_theta / _param_max_turn_angle.get()) *
math::sign(
286 const float mission_throttle = _param_throttle_cruise.get();
288 const float desired_speed = desired_velocity.norm();
290 if (desired_speed > 0.01
f) {
293 const Vector3f vel = R_to_body *
Vector3f(current_velocity(0), current_velocity(1), current_velocity(2));
295 const float x_vel = vel(0);
303 Vector3f desired_body_velocity;
306 desired_body_velocity = desired_velocity;
310 desired_body_velocity = R_to_body * desired_velocity;
314 const float desired_theta = atan2f(desired_body_velocity(1), desired_body_velocity(0));
315 float control_effort = desired_theta / _param_max_turn_angle.get();
333 const Eulerf euler_sp = qe;
335 float control_effort = euler_sp(2) / _param_max_turn_angle.get();
340 if (control_throttle >= 0.0
f) {
375 px4_pollfd_struct_t fds[4];
379 fds[0].events = POLLIN;
381 fds[1].events = POLLIN;
383 fds[2].events = POLLIN;
385 fds[3].events = POLLIN;
387 while (!should_exit()) {
390 int pret =
px4_poll(&fds[0], (
sizeof(fds) /
sizeof(fds[0])), 500);
394 warn(
"poll error %d, %d", pret, errno);
411 if (fds[0].revents & POLLIN) {
445 float turn_distance = _param_l1_distance.get();
479 if (fds[3].revents & POLLIN) {
493 if (fds[1].revents & POLLIN) {
509 if (fds[2].revents & POLLIN) {
541 _task_id = px4_task_spawn_cmd(
"rover_pos_ctrl",
543 SCHED_PRIORITY_POSITION_CONTROL,
545 (px4_main_t)&RoverPositionControl::run_trampoline,
549 warn(
"task start failed");
560 PX4_WARN(
"Command 'start' takes no arguments.");
566 if (instance ==
nullptr) {
567 PX4_ERR(
"Failed to instantiate RoverPositionControl object");
581 PX4_WARN(
"%s\n", reason);
584 PRINT_MODULE_DESCRIPTION(
587 Controls the position of a ground rover using an L1 controller. 589 Publishes `actuator_controls_0` messages at a constant 250Hz. 592 Currently, this implementation supports only a few modes: 594 * Full manual: Throttle and yaw controls are passed directly through to the actuators 595 * Auto mission: The rover runs missions 596 * Loiter: The rover will navigate to within the loiter radius, then stop the motors 600 $ rover_pos_control start 601 $ rover_pos_control status 602 $ rover_pos_control stop 606 PRINT_MODULE_USAGE_NAME("rover_pos_control",
"controller");
607 PRINT_MODULE_USAGE_COMMAND(
"start")
608 PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
void control_attitude(const vehicle_attitude_s &att, const vehicle_attitude_setpoint_s &att_sp)
constexpr _Tp constrain(_Tp val, _Tp min_val, _Tp max_val)
__EXPORT void pid_init(PID_t *pid, pid_mode_t mode, float dt_min)
uint8_t _pos_reset_counter
int globallocalconverter_init(double lat_0, double lon_0, float alt_0, uint64_t timestamp)
Initialize the global mapping between global position (spherical) and local position (NED)...
bool flag_control_offboard_enabled
int orb_copy(const struct orb_metadata *meta, int handle, void *buffer)
void control_velocity(const matrix::Vector3f ¤t_velocity, const position_setpoint_triplet_s &pos_sp_triplet)
float nav_bearing()
The current target bearing.
measure the time elapsed performing an event
void set_l1_damping(float damping)
Set the L1 damping factor.
bool flag_control_auto_enabled
Definition of geo / math functions to perform geodesic calculations.
vehicle_local_position_s _local_pos
global vehicle position
__EXPORT int rover_pos_control_main(int argc, char *argv[])
L1 control app start / stop handling function.
float get_distance_to_next_waypoint(double lat_now, double lon_now, double lat_next, double lon_next)
Returns the distance to the next waypoint in meters.
int main(int argc, char **argv)
sensor_combined_s _sensor_combined
int orb_set_interval(int handle, unsigned interval)
int _vehicle_attitude_sub
uORB::Subscription _parameter_update_sub
ECL_L1_Pos_Controller _gnd_control
vehicle_global_position_s _global_pos
global vehicle position
struct position_setpoint_s previous
Type norm_squared() const
bool control_position(const matrix::Vector2f &global_pos, const matrix::Vector3f &ground_speed, const position_setpoint_triplet_s &_pos_sp_triplet)
Control position.
__EXPORT float pid_calculate(PID_t *pid, float sp, float val, float val_dot, float dt)
manual_control_setpoint_s _manual
r/c channel data
actuator_controls_s _act_controls
direct control of actuators
float crosstrack_error()
Get the current crosstrack error.
enum RoverPositionControl::UGV_POSCTRL_MODE UGV_POSCTRL_MODE_OTHER
used to check the mode in the last control loop iteration. Use to check if the last iteration was in ...
int orb_subscribe(const struct orb_metadata *meta)
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
void manual_control_setpoint_poll()
struct position_setpoint_s current
vehicle_attitude_s _vehicle_att
bool publish(const T &data)
Publish the struct.
bool flag_control_velocity_enabled
bool flag_control_manual_enabled
static void parameters_update()
update all parameters
void perf_free(perf_counter_t handle)
Free a counter.
void vehicle_control_mode_poll()
vehicle_control_mode_s _control_mode
control mode
float target_bearing()
Bearing from aircraft to current target.
void vehicle_attitude_poll()
int orb_unsubscribe(int handle)
constexpr T radians(T degrees)
Vector< float, 6 > f(float t, const Matrix< float, 6, 1 > &, const Matrix< float, 3, 1 > &)
static hrt_abstime hrt_elapsed_time(const hrt_abstime *then)
Compute the delta between a timestamp taken in the past and now.
float nav_lateral_acceleration_demand()
Get lateral acceleration demand.
hrt_abstime _control_position_last_called
last call of control_position
void position_setpoint_triplet_poll()
uORB::Publication< position_controller_status_s > _pos_ctrl_status_pub
perf_counter_t _loop_perf
loop performance counter
void perf_end(perf_counter_t handle)
End a performance event.
bool flag_control_attitude_enabled
bool updated()
Check if there is a new update.
void set_l1_period(float period)
Set the L1 period.
position_setpoint_triplet_s _pos_sp_triplet
triplet of mission items
void attitude_setpoint_poll()
SubscriptionData< vehicle_acceleration_s > _vehicle_acceleration_sub
Vector3< float > Vector3f
int _control_mode_sub
control mode subscription
void navigate_waypoints(const matrix::Vector2f &vector_A, const matrix::Vector2f &vector_B, const matrix::Vector2f &vector_curr_position, const matrix::Vector2f &ground_speed)
Navigate between two waypoints.
__EXPORT int pid_set_parameters(PID_t *pid, float kp, float ki, float kd, float integral_limit, float output_limit)
int globallocalconverter_toglobal(float x, float y, float z, double *lat, double *lon, float *alt)
Convert from local position coordinates to global position coordinates using the global reference...
bool flag_control_position_enabled
static int print_usage(const char *reason=nullptr)
void set_l1_roll_limit(float roll_lim_rad)
Set the maximum roll angle output in radians.
static int task_spawn(int argc, char *argv[])
Quaternion< float > Quatf
int orb_check(int handle, bool *updated)
static RoverPositionControl * instantiate(int argc, char *argv[])
uORB::Publication< actuator_controls_s > _actuator_controls_pub
bool globallocalconverter_initialized()
Checks if globallocalconverter was initialized.
uint8_t lat_lon_reset_counter
int _manual_control_sub
notification of manual control updates
bool copy(void *dst)
Copy the struct.
void perf_begin(perf_counter_t handle)
Begin a performance event.
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
static int custom_command(int argc, char *argv[])
vehicle_attitude_setpoint_s _att_sp
attitude setpoint >