@@ -244,33 +244,31 @@ void WaypointGenerator::reachGoalAltitudeFirst() {
244
244
output_.goto_position .z = pose_.pose .position .z + pose_to_wp.z ;
245
245
}
246
246
247
- // smooth trajectory by liming the maximim accelleration possible
248
- void WaypointGenerator::smoothWaypoint () {
249
- ros::Time time = ros::Time::now ();
250
- ros::Duration time_diff = time - last_t_smooth_;
251
- double dt = time_diff.toSec () > 0.0 ? time_diff.toSec () : 0.004 ;
252
- last_t_smooth_ = time ;
247
+ void WaypointGenerator::smoothWaypoint (double dt) {
253
248
254
- Eigen::Vector2f vel_xy (curr_vel_.twist .linear .x , curr_vel_.twist .linear .y );
255
- Eigen::Vector2f vel_waypt_xy (
249
+ Eigen::Vector2f vel_cur_xy (curr_vel_.twist .linear .x , curr_vel_.twist .linear .y );
250
+ Eigen::Vector2f vel_sp_xy (
256
251
(output_.adapted_goto_position .x - last_position_waypoint_.pose .position .x ) / dt,
257
252
(output_.adapted_goto_position .y - last_position_waypoint_.pose .position .y ) / dt);
258
- Eigen::Vector2f vel_waypt_xy_prev (
259
- (last_position_waypoint_.pose .position .x -
260
- last_last_position_waypoint_.pose .position .x ) /
261
- dt,
262
- (last_position_waypoint_.pose .position .y -
263
- last_last_position_waypoint_.pose .position .y ) /
264
- dt);
265
- Eigen::Vector2f acc_waypt_xy ((vel_waypt_xy - vel_waypt_xy_prev) / dt);
266
-
267
- if (acc_waypt_xy.norm () > (acc_waypt_xy.norm () / 2 .0f )) {
268
- vel_xy = (acc_waypt_xy.norm () / 2 .0f ) * acc_waypt_xy.normalized () * dt +
269
- vel_waypt_xy_prev;
253
+
254
+ Eigen::Vector2f accel_diff = (vel_sp_xy - vel_cur_xy) / dt;
255
+ Eigen::Vector2f accel_cur = (vel_cur_xy - last_velocity_) / dt;
256
+ Eigen::Vector2f jerk_diff = (accel_diff - accel_cur) / dt;
257
+ float max_jerk = max_jerk_limit_param_;
258
+
259
+ // velocity-dependent max jerk
260
+ if (min_jerk_limit_param_ > 0 .001f ) {
261
+ max_jerk *= vel_cur_xy.norm ();
262
+ if (max_jerk < min_jerk_limit_param_) max_jerk = min_jerk_limit_param_;
263
+ }
264
+
265
+ if (jerk_diff.squaredNorm () > max_jerk * max_jerk && max_jerk > 0 .001f ) {
266
+ jerk_diff = max_jerk * jerk_diff.normalized ();
267
+ vel_sp_xy = (jerk_diff * dt + accel_cur) * dt + vel_cur_xy;
270
268
}
271
269
272
- output_.smoothed_goto_position .x = last_position_waypoint_.pose .position .x + vel_xy (0 ) * dt;
273
- output_.smoothed_goto_position .y = last_position_waypoint_.pose .position .y + vel_xy (1 ) * dt;
270
+ output_.smoothed_goto_position .x = last_position_waypoint_.pose .position .x + vel_sp_xy (0 ) * dt;
271
+ output_.smoothed_goto_position .y = last_position_waypoint_.pose .position .y + vel_sp_xy (1 ) * dt;
274
272
output_.smoothed_goto_position .z = output_.adapted_goto_position .z ;
275
273
276
274
ROS_DEBUG (" [WG] Smoothed waypoint: [%f %f %f]." , output_.smoothed_goto_position .x ,
@@ -354,11 +352,12 @@ void WaypointGenerator::adaptSpeed() {
354
352
// create the message that is sent to the UAV
355
353
void WaypointGenerator::getPathMsg () {
356
354
output_.path .header .frame_id = " /world" ;
357
- last_last_position_waypoint_ = last_position_waypoint_;
358
- last_position_waypoint_ = output_.position_waypoint ;
359
- last_yaw_ = curr_yaw_;
360
355
output_.adapted_goto_position = output_.goto_position ;
361
356
357
+ const ros::Time now = ros::Time::now ();
358
+ ros::Duration time_diff = now - last_time_;
359
+ double dt = time_diff.toSec () > 0.0 ? time_diff.toSec () : 0.004 ;
360
+
362
361
// If avoid sphere is used, project waypoint on sphere
363
362
if (planner_info_.use_avoid_sphere && planner_info_.avoid_sphere_age < 100 &&
364
363
planner_info_.reach_altitude && !reached_goal_) {
@@ -387,11 +386,7 @@ void WaypointGenerator::getPathMsg() {
387
386
ROS_DEBUG (" [WG] pose altitude func: [%f %f %f]." , pose_.pose .position .x ,
388
387
pose_.pose .position .y , pose_.pose .position .z );
389
388
} else {
390
- if (!only_yawed_ && !reached_goal_) {
391
- smoothWaypoint ();
392
- new_yaw_ = nextYaw (pose_, output_.smoothed_goto_position );
393
- ;
394
- }
389
+ smoothWaypoint (dt);
395
390
}
396
391
397
392
// change waypoint if drone is at goal or above
@@ -431,10 +426,10 @@ void WaypointGenerator::getPathMsg() {
431
426
transformPositionToVelocityWaypoint ();
432
427
433
428
output_.path .poses .push_back (output_.position_waypoint );
434
- curr_yaw_ = new_yaw_;
435
- last_last_position_waypoint_ = last_position_waypoint_;
436
429
last_position_waypoint_ = output_.position_waypoint ;
437
430
last_yaw_ = curr_yaw_;
431
+ last_velocity_ = Eigen::Vector2f (curr_vel_.twist .linear .x , curr_vel_.twist .linear .y );
432
+ last_time_ = now;
438
433
}
439
434
440
435
void WaypointGenerator::getWaypoints (waypointResult &output) {
0 commit comments