1+ // April/2019, ETHZ, Jaeyoung Lim, [email protected] 2+
3+ #include " controller_benchmark/controller_benchmark.h"
4+
5+ // Constructor
6+ ControllerEvaluator::ControllerEvaluator (const ros::NodeHandle& nh, const ros::NodeHandle& nh_private):
7+ nh_(nh),
8+ nh_private_(nh_private) {
9+
10+ mavposeSub_ = nh_.subscribe (" /mavros/local_position/pose" , 1 , &ControllerEvaluator::mavposeCallback, this ,ros::TransportHints ().tcpNoDelay ());
11+ mavtwistSub_ = nh_.subscribe (" /mavros/local_position/velocity_local" , 1 , &ControllerEvaluator::mavtwistCallback, this ,ros::TransportHints ().tcpNoDelay ());
12+ gzmavposeSub_ = nh_.subscribe (" /gazebo/model_states" , 1 , &ControllerEvaluator::gzmavposeCallback, this , ros::TransportHints ().tcpNoDelay ());
13+
14+ error_measurer_.resize (3 );
15+ }
16+ ControllerEvaluator::~ControllerEvaluator () {
17+ // Destructor
18+ }
19+
20+ void ControllerEvaluator::mavposeCallback (const geometry_msgs::PoseStamped& msg){
21+ mavPos_ (0 ) = msg.pose .position .x ;
22+ mavPos_ (1 ) = msg.pose .position .y ;
23+ mavPos_ (2 ) = msg.pose .position .z ;
24+ mavAtt_ (0 ) = msg.pose .orientation .w ;
25+ mavAtt_ (1 ) = msg.pose .orientation .x ;
26+ mavAtt_ (2 ) = msg.pose .orientation .y ;
27+ mavAtt_ (3 ) = msg.pose .orientation .z ;
28+
29+ error_pos_ = mavPos_ - gt_mavPos_;
30+ error_vel_ = mavVel_ - gt_mavVel_;
31+
32+ for (int i = 0 ; i < 3 ; i++){
33+ error_measurer_[i].Add (error_pos_ (i));
34+ double error;
35+ error_measurer_[i].GetMeanError (error);
36+ }
37+ }
38+
39+ void ControllerEvaluator::mavtwistCallback (const geometry_msgs::TwistStamped& msg){
40+
41+ mavVel_ (0 ) = msg.twist .linear .x ;
42+ mavVel_ (1 ) = msg.twist .linear .y ;
43+ mavVel_ (2 ) = msg.twist .linear .z ;
44+ mavRate_ (0 ) = msg.twist .angular .x ;
45+ mavRate_ (1 ) = msg.twist .angular .y ;
46+ mavRate_ (2 ) = msg.twist .angular .z ;
47+
48+ }
49+
50+ void ControllerEvaluator::gzmavposeCallback (const gazebo_msgs::ModelStates& msg){
51+ for (int i = 0 ; i < msg.pose .size (); i++){
52+ if (msg.name [i] == mav_name_){
53+ gt_mavPos_ (0 ) = msg.pose [i].position .x ;
54+ gt_mavPos_ (1 ) = msg.pose [i].position .y ;
55+ gt_mavPos_ (2 ) = msg.pose [i].position .z ;
56+ gt_mavAtt_ (0 ) = msg.pose [i].orientation .w ;
57+ gt_mavAtt_ (1 ) = msg.pose [i].orientation .x ;
58+ gt_mavAtt_ (2 ) = msg.pose [i].orientation .y ;
59+ gt_mavAtt_ (3 ) = msg.pose [i].orientation .z ;
60+ gt_mavVel_ (0 ) = msg.twist [i].linear .x ;
61+ gt_mavVel_ (1 ) = msg.twist [i].linear .y ;
62+ gt_mavVel_ (2 ) = msg.twist [i].linear .z ;
63+ gt_mavRate_ (0 ) = msg.twist [i].angular .x ;
64+ gt_mavRate_ (1 ) = msg.twist [i].angular .y ;
65+ gt_mavRate_ (2 ) = msg.twist [i].angular .z ;
66+ break ;
67+ }
68+ }
69+ }
0 commit comments