Skip to content

Commit f8bdc25

Browse files
committed
improve bias estimator indoor, bug fixes in arming locks
*add enable/disable handlers for estimator *map lock and mode switch service calls made only at events *allow estimator to recover gracefully from on/off events
1 parent 09813f0 commit f8bdc25

File tree

6 files changed

+45
-23
lines changed

6 files changed

+45
-23
lines changed

autopilot_handler/apm_handler/src/mavros_translate.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,29 @@ void mavrosStateCallback( const mavros_msgs::State::ConstPtr &msg )
109109
{
110110
vehicle_armed_ = true;
111111
lockreq.request.data = true;
112+
map_lock.call( lockreq );
112113
}
113114
else if( msg->armed == false && vehicle_armed_ )
114115
{
115116
vehicle_armed_ = false;
116117
lockreq.request.data = false;
118+
map_lock.call( lockreq );
117119
}
118-
map_lock.call( lockreq );
119120

120121
/* call bias compensation service when switching in/out of computer */
121122
std_srvs::SetBool biasreq;
122123
if( msg->mode == "CMODE(25)" && !in_comp_mode_ )
123124
{
124125
in_comp_mode_ = true;
125126
biasreq.request.data = true;
127+
bias_comp.call( biasreq );
126128
}
127129
else if( msg->mode != "CMODE(25)" && in_comp_mode_ )
128130
{
129131
in_comp_mode_ = false;
130132
biasreq.request.data = false;
133+
bias_comp.call( biasreq );
131134
}
132-
bias_comp.call( biasreq );
133135
}
134136

135137

freyja_controller.launch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<param name="controller_rate" type="int" value="45" />
4545
<param name="total_mass" type="double" value="$(arg total_mass)"/>
4646
<param name="use_stricter_gains" type="bool" value="false" />
47-
<param name="estimator_rate" type="int" value="10" />
47+
<param name="estimator_rate" type="int" value="50" />
4848
<param name="bias_compensation" type="string" value="$(arg bias_compensation)" />
4949
<param name="mass_estimation" type="bool" value="true" />
5050
<param name="mass_correction" type="bool" value="false" />

lqg_controller/include/bias_estimator.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class BiasEstimator
5454

5555
/* parameters */
5656
int estimator_rate_, estimator_period_us_;
57+
bool estimator_off_;
5758

5859
/* prevent state propagation when other callbacks are happening */
5960
std::mutex state_prop_mutex_;
@@ -96,11 +97,16 @@ class BiasEstimator
9697
void getEstimatedBiases( Eigen::Matrix<double, 3, 1> & );
9798

9899
/* set and reset accessors */
99-
inline void markEnabled() { t_estimator_on_ = ClockTime::now(); }
100-
inline void clearBiases()
100+
inline void enable()
101+
{
102+
t_estimator_on_ = ClockTime::now();
103+
estimator_off_ = false;
104+
}
105+
inline void disable()
101106
{
102107
best_estimate_.tail<3>() << 0.0, 0.0, 0.0;
103108
estimator_output_shaping_ = 0.0;
109+
estimator_off_ = true;
104110
}
105111

106112
/* Time constant calc */

lqg_controller/include/lqr_control_bias.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class LQRController
6868
/* Bias estimator reference object */
6969
BiasEstimator &bias_est_;
7070
bool bias_compensation_req_;
71+
bool bias_compensation_off_;
7172
Eigen::Matrix<double, 3, 1> f_biases_;
7273
std::thread bias_handler_thread_;
7374

lqg_controller/src/bias_estimator.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ BiasEstimator::BiasEstimator() : nh_(), priv_nh_("~")
4242
4343
Use thread libraries instead:
4444
*/
45-
45+
estimator_off_ = false;
4646
state_propagation_alive_ = true;
4747
n_stprops_since_update_ = 0;
4848
last_prop_t_ = std::chrono::high_resolution_clock::now();
@@ -80,10 +80,10 @@ void BiasEstimator::initEstimatorSystem()
8080

8181
/* Numbers pulled out of a magical hat only available to the deserving few */
8282
proc_noise_Q_ << 0.1*IDEN3x3, ZERO3x3, ZERO3x3,
83-
ZERO3x3, 0.1*IDEN3x3, ZERO3x3,
84-
ZERO3x3, ZERO3x3, 0.5*IDEN3x3;
85-
meas_noise_R_ << 0.25*IDEN3x3, ZERO3x3,
86-
ZERO3x3, 0.5*IDEN3x3;
83+
ZERO3x3, 0.2*IDEN3x3, ZERO3x3,
84+
ZERO3x3, ZERO3x3, 0.8*IDEN3x3;
85+
meas_noise_R_ << 0.2*IDEN3x3, ZERO3x3,
86+
ZERO3x3, 0.3*IDEN3x3;
8787

8888
meas_matrix_C_ << IDEN3x3, ZERO3x3, ZERO3x3,
8989
ZERO3x3, IDEN3x3, ZERO3x3;
@@ -131,17 +131,22 @@ void BiasEstimator::state_propagation( )
131131
{
132132
/* don't use stale ctrl_input_u_ for some reason */
133133
n_stprops_since_update_++;
134-
if( n_stprops_since_update_ > 3 )
135-
ctrl_input_u_ << 0.0, 0.0, 0.0;
136-
137-
/* propagate state forward */
138-
best_estimate_ = sys_A_ * best_estimate_ +
139-
sys_B_ * (ctrl_input_u_.cwiseProduct(input_shaping));
140-
state_cov_P_ = sys_A_*state_cov_P_*sys_A_t_ + proc_noise_Q_;
141-
142-
/* only clip estimated bias accelerations */
143-
best_estimate_.block<3,1>(6,0) = BIAS_LIM_ABS.cwiseMin(
134+
if( estimator_off_ || n_stprops_since_update_ > 3 )
135+
{
136+
ctrl_input_u_ << 0.0, 0.0, 0.0; // clear ctrl until further update
137+
best_estimate_ = best_estimate_; // do not propagate
138+
}
139+
else
140+
{
141+
/* propagate state forward */
142+
best_estimate_ = sys_A_ * best_estimate_ +
143+
sys_B_ * (ctrl_input_u_.cwiseProduct(input_shaping));
144+
state_cov_P_ = sys_A_*state_cov_P_*sys_A_t_ + proc_noise_Q_;
145+
146+
/* only clip estimated bias accelerations */
147+
best_estimate_.block<3,1>(6,0) = BIAS_LIM_ABS.cwiseMin(
144148
best_estimate_.block<3,1>(6,0).cwiseMax(-BIAS_LIM_ABS) );
149+
}
145150

146151
/* fill state information: this will be unrolled by gcc */
147152
for( int idx=0; idx < nStates; idx++ )

lqg_controller/src/lqr_control_bias.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ LQRController::LQRController(BiasEstimator &b) : nh_(),
6464
else if( _bcomp == "auto" || _bcomp == "off" )
6565
bias_compensation_req_ = false; // off, or on by service call
6666

67+
bias_compensation_off_ = (_bcomp == "off")? true : false; // always off
68+
6769
f_biases_ << 0.0, 0.0, 0.0;
6870

6971

@@ -112,16 +114,22 @@ void LQRController::initLqrSystem()
112114

113115
bool LQRController::biasEnableServer( BoolServReq& rq, BoolServRsp& rp )
114116
{
117+
if( bias_compensation_off_ )
118+
{
119+
ROS_WARN( "LQR: Bias compensation remains off throughout." );
120+
return false; // service unsuccessful
121+
}
122+
115123
bias_compensation_req_ = rq.data;
116124
if( bias_compensation_req_ )
117125
{
118126
ROS_WARN( "LQR: Bias compensation active!" );
119-
bias_est_.markEnabled();
127+
bias_est_.enable();
120128
}
121129
else
122130
{
123131
ROS_WARN( "LQR: Bias compensation inactive!" );
124-
bias_est_.clearBiases();
132+
bias_est_.disable();
125133
}
126134
return true; // service successful
127135
}
@@ -158,7 +166,7 @@ void LQRController::stateCallback( const freyja_msgs::CurrentState::ConstPtr &ms
158166
rsmtx.lock();
159167
reduced_state_.head<6>() = current_state.head<6>() - reference_state_.head<6>();
160168
/* yaw-error is done differently */
161-
reduced_state_(6) = calcYawError( reduced_state_(6), reference_state_(6) );
169+
reduced_state_(6) = calcYawError( current_state_(6), reference_state_(6) );
162170
rsmtx.unlock();
163171
}
164172

0 commit comments

Comments
 (0)