Skip to content

Commit a1bc09a

Browse files
rover: seperate speed control
1 parent e81c62c commit a1bc09a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+381
-401
lines changed

msg/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ set(msg_files
181181
RoverPositionSetpoint.msg
182182
RoverRateSetpoint.msg
183183
RoverRateStatus.msg
184+
RoverSpeedSetpoint.msg
185+
RoverSpeedStatus.msg
184186
RoverSteeringSetpoint.msg
185187
RoverThrottleSetpoint.msg
186-
RoverVelocitySetpoint.msg
187-
RoverVelocityStatus.msg
188188
Rpm.msg
189189
RtlStatus.msg
190190
RtlTimeEstimate.msg

msg/RoverSpeedSetpoint.msg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Rover Speed Setpoint
2+
3+
uint64 timestamp # [us] Time since system start
4+
float32 speed_body_x # [m/s] [@range -inf (Backwards), inf (Forwards)] [@frame Body] Speed setpoint in body x direction
5+
float32 speed_body_y # [m/s] [@range -inf (Left), inf (Right)] [@frame Body] [@invalid NaN If not mecanum] Mecanum only: Speed setpoint in body y direction
File renamed without changes.

msg/RoverVelocitySetpoint.msg

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

src/modules/logger/logged_topics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ void LoggedTopics::add_default_topics()
111111
add_optional_topic("rover_position_setpoint", 100);
112112
add_optional_topic("rover_rate_setpoint", 100);
113113
add_optional_topic("rover_rate_status", 100);
114+
add_optional_topic("rover_speed_setpoint", 100);
115+
add_optional_topic("rover_speed_status", 100);
114116
add_optional_topic("rover_steering_setpoint", 100);
115117
add_optional_topic("rover_throttle_setpoint", 100);
116-
add_optional_topic("rover_velocity_setpoint", 100);
117-
add_optional_topic("rover_velocity_status", 100);
118118
add_topic("rtl_time_estimate", 1000);
119119
add_topic("rtl_status", 2000);
120120
add_optional_topic("sensor_airflow", 100);

src/modules/rover_ackermann/AckermannDriveModes/AckermannManualMode/AckermannManualMode.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ AckermannManualMode::AckermannManualMode(ModuleParams *parent) : ModuleParams(pa
4242
_rover_steering_setpoint_pub.advertise();
4343
_rover_rate_setpoint_pub.advertise();
4444
_rover_attitude_setpoint_pub.advertise();
45-
_rover_velocity_setpoint_pub.advertise();
45+
_rover_speed_setpoint_pub.advertise();
4646
_rover_position_setpoint_pub.advertise();
4747
}
4848

@@ -164,12 +164,10 @@ void AckermannManualMode::position()
164164
_pos_ctl_course_direction = Vector2f(NAN, NAN);
165165

166166
// Speed control
167-
rover_velocity_setpoint_s rover_velocity_setpoint{};
168-
rover_velocity_setpoint.timestamp = hrt_absolute_time();
169-
rover_velocity_setpoint.speed = speed_setpoint;
170-
rover_velocity_setpoint.bearing = NAN;
171-
rover_velocity_setpoint.yaw = NAN;
172-
_rover_velocity_setpoint_pub.publish(rover_velocity_setpoint);
167+
rover_speed_setpoint_s rover_speed_setpoint{};
168+
rover_speed_setpoint.timestamp = hrt_absolute_time();
169+
rover_speed_setpoint.speed_body_x = speed_setpoint;
170+
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
173171

174172
// Rate control
175173
rover_rate_setpoint_s rover_rate_setpoint{};

src/modules/rover_ackermann/AckermannDriveModes/AckermannManualMode/AckermannManualMode.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#include <uORB/topics/rover_steering_setpoint.h>
5252
#include <uORB/topics/rover_rate_setpoint.h>
5353
#include <uORB/topics/rover_attitude_setpoint.h>
54-
#include <uORB/topics/rover_velocity_setpoint.h>
54+
#include <uORB/topics/rover_speed_setpoint.h>
5555
#include <uORB/topics/rover_position_setpoint.h>
5656

5757
/**
@@ -83,7 +83,7 @@ class AckermannManualMode : public ModuleParams
8383
void stab();
8484

8585
/**
86-
* @brief Generate and publish roverVelocitySetpoint from manualControlSetpoint.
86+
* @brief Generate and publish roverSpeedSetpoint/roverRateSetpoint or roverPositionSetpoint from manualControlSetpoint.
8787
*/
8888
void position();
8989

@@ -109,7 +109,7 @@ class AckermannManualMode : public ModuleParams
109109
uORB::Publication<rover_steering_setpoint_s> _rover_steering_setpoint_pub{ORB_ID(rover_steering_setpoint)};
110110
uORB::Publication<rover_rate_setpoint_s> _rover_rate_setpoint_pub{ORB_ID(rover_rate_setpoint)};
111111
uORB::Publication<rover_attitude_setpoint_s> _rover_attitude_setpoint_pub{ORB_ID(rover_attitude_setpoint)};
112-
uORB::Publication<rover_velocity_setpoint_s> _rover_velocity_setpoint_pub{ORB_ID(rover_velocity_setpoint)};
112+
uORB::Publication<rover_speed_setpoint_s> _rover_speed_setpoint_pub{ORB_ID(rover_speed_setpoint)};
113113
uORB::Publication<rover_position_setpoint_s> _rover_position_setpoint_pub{ORB_ID(rover_position_setpoint)};
114114

115115
// Variables

src/modules/rover_ackermann/AckermannDriveModes/AckermannOffboardMode/AckermannOffboardMode.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ using namespace time_literals;
3838
AckermannOffboardMode::AckermannOffboardMode(ModuleParams *parent) : ModuleParams(parent)
3939
{
4040
updateParams();
41-
_rover_velocity_setpoint_pub.advertise();
41+
_rover_speed_setpoint_pub.advertise();
4242
_rover_position_setpoint_pub.advertise();
43+
_rover_attitude_setpoint_pub.advertise();
4344
}
4445

4546
void AckermannOffboardMode::updateParams()
@@ -69,11 +70,13 @@ void AckermannOffboardMode::offboardControl()
6970

7071
} else if (offboard_control_mode.velocity) {
7172
const Vector2f velocity_ned(trajectory_setpoint.velocity[0], trajectory_setpoint.velocity[1]);
72-
rover_velocity_setpoint_s rover_velocity_setpoint{};
73-
rover_velocity_setpoint.timestamp = hrt_absolute_time();
74-
rover_velocity_setpoint.speed = velocity_ned.norm();
75-
rover_velocity_setpoint.bearing = atan2f(velocity_ned(1), velocity_ned(0));
76-
_rover_velocity_setpoint_pub.publish(rover_velocity_setpoint);
77-
73+
rover_speed_setpoint_s rover_speed_setpoint{};
74+
rover_speed_setpoint.timestamp = hrt_absolute_time();
75+
rover_speed_setpoint.speed_body_x = velocity_ned.norm();
76+
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
77+
rover_attitude_setpoint_s rover_attitude_setpoint{};
78+
rover_attitude_setpoint.timestamp = hrt_absolute_time();
79+
rover_attitude_setpoint.yaw_setpoint = atan2f(velocity_ned(1), velocity_ned(0));
80+
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
7881
}
7982
}

src/modules/rover_ackermann/AckermannDriveModes/AckermannOffboardMode/AckermannOffboardMode.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
// uORB includes
4444
#include <uORB/Subscription.hpp>
4545
#include <uORB/Publication.hpp>
46-
#include <uORB/topics/rover_velocity_setpoint.h>
46+
#include <uORB/topics/rover_speed_setpoint.h>
47+
#include <uORB/topics/rover_attitude_setpoint.h>
4748
#include <uORB/topics/rover_position_setpoint.h>
4849
#include <uORB/topics/offboard_control_mode.h>
4950
#include <uORB/topics/trajectory_setpoint.h>
@@ -80,6 +81,7 @@ class AckermannOffboardMode : public ModuleParams
8081
uORB::Subscription _offboard_control_mode_sub{ORB_ID(offboard_control_mode)};
8182

8283
// uORB publications
83-
uORB::Publication<rover_velocity_setpoint_s> _rover_velocity_setpoint_pub{ORB_ID(rover_velocity_setpoint)};
84+
uORB::Publication<rover_speed_setpoint_s> _rover_speed_setpoint_pub{ORB_ID(rover_speed_setpoint)};
8485
uORB::Publication<rover_position_setpoint_s> _rover_position_setpoint_pub{ORB_ID(rover_position_setpoint)};
86+
uORB::Publication<rover_attitude_setpoint_s> _rover_attitude_setpoint_pub{ORB_ID(rover_attitude_setpoint)};
8587
};

src/modules/rover_ackermann/AckermannPosControl/AckermannPosControl.cpp

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ using namespace time_literals;
3838
AckermannPosControl::AckermannPosControl(ModuleParams *parent) : ModuleParams(parent)
3939
{
4040
_pure_pursuit_status_pub.advertise();
41-
_rover_velocity_setpoint_pub.advertise();
41+
_rover_speed_setpoint_pub.advertise();
42+
_rover_attitude_setpoint_pub.advertise();
4243

4344
updateParams();
4445
}
@@ -47,6 +48,7 @@ void AckermannPosControl::updateParams()
4748
{
4849
ModuleParams::updateParams();
4950
_max_yaw_rate = _param_ro_yaw_rate_limit.get() * M_DEG_TO_RAD_F;
51+
_min_speed = _param_ra_wheel_base.get() * _max_yaw_rate / tanf(_param_ra_max_str_ang.get());
5052

5153
}
5254

@@ -82,20 +84,36 @@ void AckermannPosControl::updatePosControl()
8284
const float bearing_setpoint = PurePursuit::calcTargetBearing(pure_pursuit_status, _param_pp_lookahd_gain.get(),
8385
_param_pp_lookahd_max.get(), _param_pp_lookahd_min.get(), target_waypoint_ned, _start_ned,
8486
_curr_pos_ned, fabsf(speed_setpoint));
87+
88+
if (_param_ro_speed_red.get() > FLT_EPSILON) {
89+
const float course_error = fabsf(matrix::wrap_pi(bearing_setpoint - _vehicle_yaw));
90+
const float speed_reduction = math::constrain(_param_ro_speed_red.get() * math::interpolate(course_error,
91+
0.f, M_PI_F, 0.f, 1.f), 0.f, 1.f);
92+
const float max_speed = math::constrain(_param_ro_max_thr_speed.get() * (1.f - speed_reduction), _min_speed,
93+
_param_ro_max_thr_speed.get());
94+
speed_setpoint = math::constrain(speed_setpoint, -max_speed, max_speed);
95+
}
96+
8597
_pure_pursuit_status_pub.publish(pure_pursuit_status);
86-
rover_velocity_setpoint_s rover_velocity_setpoint{};
87-
rover_velocity_setpoint.timestamp = timestamp;
88-
rover_velocity_setpoint.speed = speed_setpoint;
89-
rover_velocity_setpoint.bearing = speed_setpoint > -FLT_EPSILON ? bearing_setpoint : matrix::wrap_pi(
98+
rover_speed_setpoint_s rover_speed_setpoint{};
99+
rover_speed_setpoint.timestamp = timestamp;
100+
rover_speed_setpoint.speed_body_x = speed_setpoint;
101+
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
102+
rover_attitude_setpoint_s rover_attitude_setpoint{};
103+
rover_attitude_setpoint.timestamp = timestamp;
104+
rover_attitude_setpoint.yaw_setpoint = speed_setpoint > -FLT_EPSILON ? bearing_setpoint : matrix::wrap_pi(
90105
bearing_setpoint + M_PI_F);
91-
_rover_velocity_setpoint_pub.publish(rover_velocity_setpoint);
106+
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
92107

93108
} else {
94-
rover_velocity_setpoint_s rover_velocity_setpoint{};
95-
rover_velocity_setpoint.timestamp = timestamp;
96-
rover_velocity_setpoint.speed = 0.f;
97-
rover_velocity_setpoint.bearing = _vehicle_yaw;
98-
_rover_velocity_setpoint_pub.publish(rover_velocity_setpoint);
109+
rover_speed_setpoint_s rover_speed_setpoint{};
110+
rover_speed_setpoint.timestamp = timestamp;
111+
rover_speed_setpoint.speed_body_x = 0.f;
112+
_rover_speed_setpoint_pub.publish(rover_speed_setpoint);
113+
rover_attitude_setpoint_s rover_attitude_setpoint{};
114+
rover_attitude_setpoint.timestamp = timestamp;
115+
rover_attitude_setpoint.yaw_setpoint = _vehicle_yaw;
116+
_rover_attitude_setpoint_pub.publish(rover_attitude_setpoint);
99117
}
100118
}
101119
}

0 commit comments

Comments
 (0)