46
46
#include < clover/SetRates.h>
47
47
48
48
using std::string;
49
+ using std::isnan;
49
50
using namespace geometry_msgs ;
50
51
using namespace sensor_msgs ;
51
52
using namespace clover ;
@@ -507,25 +508,84 @@ bool serve(enum setpoint_type_t sp_type, float x, float y, float z, float vx, fl
507
508
if (busy)
508
509
throw std::runtime_error (" Busy" );
509
510
510
- ENSURE_FINITE (x);
511
- ENSURE_FINITE (y);
512
- ENSURE_FINITE (z);
513
- ENSURE_FINITE (vx);
514
- ENSURE_FINITE (vy);
515
- ENSURE_FINITE (vz);
516
- ENSURE_FINITE (pitch);
517
- ENSURE_FINITE (roll);
518
- ENSURE_FINITE (pitch_rate);
519
- ENSURE_FINITE (roll_rate);
520
- ENSURE_FINITE (lat);
521
- ENSURE_FINITE (lon);
522
- ENSURE_FINITE (thrust);
523
-
524
511
busy = true ;
525
512
526
513
// Checks
527
514
checkState ();
528
515
516
+ // default frame is local frame
517
+ if (frame_id.empty ())
518
+ frame_id = local_frame;
519
+
520
+ // look up for reference frame
521
+ auto search = reference_frames.find (frame_id);
522
+ const string& reference_frame = search == reference_frames.end () ? frame_id : search->second ;
523
+
524
+ // Serve "partial" commands
525
+
526
+ if (!auto_arm && std::isfinite (yaw) &&
527
+ isnan (x) && isnan (y) && isnan (z) && isnan (vx) && isnan (vy) && isnan (vz) &&
528
+ isnan (pitch) && isnan (roll) && isnan (thrust) &&
529
+ isnan (lat) && isnan (lon)) {
530
+ // change only the yaw
531
+ if (setpoint_type == POSITION || setpoint_type == NAVIGATE || setpoint_type == NAVIGATE_GLOBAL || setpoint_type == VELOCITY) {
532
+ if (!waitTransform (setpoint_position.header .frame_id , frame_id, stamp, transform_timeout))
533
+ throw std::runtime_error (" Can't transform from " + frame_id + " to " + setpoint_position.header .frame_id );
534
+
535
+ message = " Changing yaw only" ;
536
+
537
+ QuaternionStamped q;
538
+ q.header .frame_id = frame_id;
539
+ q.header .stamp = stamp;
540
+ q.quaternion = tf::createQuaternionMsgFromYaw (yaw); // TODO: pitch=0, roll=0 is not totally correct
541
+ setpoint_position.pose .orientation = tf_buffer.transform (q, setpoint_position.header .frame_id ).quaternion ;
542
+ setpoint_yaw_type = YAW;
543
+ goto publish_setpoint;
544
+ } else {
545
+ throw std::runtime_error (" Setting yaw is possible only when position or velocity setpoints active" );
546
+ }
547
+ }
548
+
549
+ if (!auto_arm && std::isfinite (yaw_rate) &&
550
+ isnan (x) && isnan (y) && isnan (z) && isnan (vx) && isnan (vy) && isnan (vz) &&
551
+ isnan (pitch) && isnan (roll) && isnan (yaw) && isnan (thrust) &&
552
+ isnan (lat) && isnan (lon)) {
553
+ // change only the yaw rate
554
+ if (setpoint_type == POSITION || setpoint_type == NAVIGATE || setpoint_type == NAVIGATE_GLOBAL || setpoint_type == VELOCITY) {
555
+ message = " Changing yaw rate only" ;
556
+
557
+ setpoint_yaw_type = YAW_RATE;
558
+ setpoint_yaw_rate = yaw_rate;
559
+ goto publish_setpoint;
560
+ } else {
561
+ throw std::runtime_error (" Setting yaw rate is possible only when position or velocity setpoints active" );
562
+ }
563
+ }
564
+
565
+ // Serve normal commands
566
+
567
+ if (sp_type == NAVIGATE || sp_type == POSITION) {
568
+ ENSURE_FINITE (x);
569
+ ENSURE_FINITE (y);
570
+ ENSURE_FINITE (z);
571
+ } else if (sp_type == NAVIGATE_GLOBAL) {
572
+ ENSURE_FINITE (lat);
573
+ ENSURE_FINITE (lon);
574
+ ENSURE_FINITE (z);
575
+ } else if (sp_type == VELOCITY) {
576
+ ENSURE_FINITE (vx);
577
+ ENSURE_FINITE (vy);
578
+ ENSURE_FINITE (vz);
579
+ } else if (sp_type == ATTITUDE) {
580
+ ENSURE_FINITE (pitch);
581
+ ENSURE_FINITE (roll);
582
+ ENSURE_FINITE (thrust);
583
+ } else if (sp_type == RATES) {
584
+ ENSURE_FINITE (pitch_rate);
585
+ ENSURE_FINITE (roll_rate);
586
+ ENSURE_FINITE (thrust);
587
+ }
588
+
529
589
if (sp_type == NAVIGATE || sp_type == NAVIGATE_GLOBAL) {
530
590
if (TIMEOUT (local_position, local_position_timeout))
531
591
throw std::runtime_error (" No local position, check settings" );
@@ -550,14 +610,6 @@ bool serve(enum setpoint_type_t sp_type, float x, float y, float z, float vx, fl
550
610
throw std::runtime_error (" No global position" );
551
611
}
552
612
553
- // default frame is local frame
554
- if (frame_id.empty ())
555
- frame_id = local_frame;
556
-
557
- // look up for reference frame
558
- auto search = reference_frames.find (frame_id);
559
- const string& reference_frame = search == reference_frames.end () ? frame_id : search->second ;
560
-
561
613
if (sp_type == NAVIGATE || sp_type == NAVIGATE_GLOBAL || sp_type == POSITION || sp_type == VELOCITY || sp_type == ATTITUDE) {
562
614
// make sure transform from frame_id to reference frame available
563
615
if (!waitTransform (reference_frame, frame_id, stamp, transform_timeout))
@@ -625,7 +677,7 @@ bool serve(enum setpoint_type_t sp_type, float x, float y, float z, float vx, fl
625
677
} else {
626
678
setpoint_yaw_type = YAW;
627
679
setpoint_yaw_rate = 0 ;
628
- ps.pose .orientation = tf::createQuaternionMsgFromRollPitchYaw (roll, pitch, yaw);
680
+ ps.pose .orientation = tf::createQuaternionMsgFromYaw ( yaw);
629
681
}
630
682
631
683
tf_buffer.transform (ps, setpoint_position, reference_frame);
@@ -653,6 +705,7 @@ bool serve(enum setpoint_type_t sp_type, float x, float y, float z, float vx, fl
653
705
654
706
wait_armed = auto_arm;
655
707
708
+ publish_setpoint:
656
709
publish (stamp); // calculate initial transformed messages first
657
710
setpoint_timer.start ();
658
711
@@ -693,27 +746,27 @@ bool serve(enum setpoint_type_t sp_type, float x, float y, float z, float vx, fl
693
746
}
694
747
695
748
bool navigate (Navigate::Request& req, Navigate::Response& res) {
696
- return serve (NAVIGATE, req.x , req.y , req.z , 0 , 0 , 0 , 0 , 0 , req.yaw , 0 , 0 , req.yaw_rate , 0 , 0 , 0 , req.speed , req.frame_id , req.auto_arm , res.success , res.message );
749
+ return serve (NAVIGATE, req.x , req.y , req.z , NAN, NAN, NAN, NAN, NAN , req.yaw , NAN, NAN , req.yaw_rate , NAN, NAN, NAN , req.speed , req.frame_id , req.auto_arm , res.success , res.message );
697
750
}
698
751
699
752
bool navigateGlobal (NavigateGlobal::Request& req, NavigateGlobal::Response& res) {
700
- return serve (NAVIGATE_GLOBAL, 0 , 0 , req.z , 0 , 0 , 0 , 0 , 0 , req.yaw , 0 , 0 , req.yaw_rate , req.lat , req.lon , 0 , req.speed , req.frame_id , req.auto_arm , res.success , res.message );
753
+ return serve (NAVIGATE_GLOBAL, NAN, NAN , req.z , NAN, NAN, NAN, NAN, NAN , req.yaw , NAN, NAN , req.yaw_rate , req.lat , req.lon , NAN , req.speed , req.frame_id , req.auto_arm , res.success , res.message );
701
754
}
702
755
703
756
bool setPosition (SetPosition::Request& req, SetPosition::Response& res) {
704
- return serve (POSITION, req.x , req.y , req.z , 0 , 0 , 0 , 0 , 0 , req.yaw , 0 , 0 , req.yaw_rate , 0 , 0 , 0 , 0 , req.frame_id , req.auto_arm , res.success , res.message );
757
+ return serve (POSITION, req.x , req.y , req.z , NAN, NAN, NAN, NAN, NAN , req.yaw , NAN, NAN , req.yaw_rate , NAN, NAN, NAN, NAN , req.frame_id , req.auto_arm , res.success , res.message );
705
758
}
706
759
707
760
bool setVelocity (SetVelocity::Request& req, SetVelocity::Response& res) {
708
- return serve (VELOCITY, 0 , 0 , 0 , req.vx , req.vy , req.vz , 0 , 0 , req.yaw , 0 , 0 , req.yaw_rate , 0 , 0 , 0 , 0 , req.frame_id , req.auto_arm , res.success , res.message );
761
+ return serve (VELOCITY, NAN, NAN, NAN , req.vx , req.vy , req.vz , NAN, NAN , req.yaw , NAN, NAN , req.yaw_rate , NAN, NAN, NAN, NAN , req.frame_id , req.auto_arm , res.success , res.message );
709
762
}
710
763
711
764
bool setAttitude (SetAttitude::Request& req, SetAttitude::Response& res) {
712
- return serve (ATTITUDE, 0 , 0 , 0 , 0 , 0 , 0 , req.pitch , req.roll , req.yaw , 0 , 0 , 0 , 0 , 0 , req.thrust , 0 , req.frame_id , req.auto_arm , res.success , res.message );
765
+ return serve (ATTITUDE, NAN, NAN, NAN, NAN, NAN, NAN , req.pitch , req.roll , req.yaw , NAN, NAN, NAN, NAN, NAN , req.thrust , NAN , req.frame_id , req.auto_arm , res.success , res.message );
713
766
}
714
767
715
768
bool setRates (SetRates::Request& req, SetRates::Response& res) {
716
- return serve (RATES, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , req.pitch_rate , req.roll_rate , req.yaw_rate , 0 , 0 , req.thrust , 0 , " " , req.auto_arm , res.success , res.message );
769
+ return serve (RATES, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN , req.pitch_rate , req.roll_rate , req.yaw_rate , NAN, NAN , req.thrust , NAN , " " , req.auto_arm , res.success , res.message );
717
770
}
718
771
719
772
bool land (std_srvs::Trigger::Request& req, std_srvs::Trigger::Response& res)
0 commit comments