10 int main(
int argc,
char **argv)
12 ROS_INFO(
"Check the num. of states and num. of inputs.");
13 ROS_INFO(
"These can be adjusted in 'controller_msg.msg' and 'plant_msg.msg' files.");
16 ROS_INFO(
"Also check the parameters of the controller at the top of lyap_control/include/controller.h");
58 boost::numeric::ublas::matrix<double> dx_dot_du (
num_inputs, num_states);
71 D[i] = D[i]+( msg.x[j]-
setpoint[j] )*dx_dot_du(i,j);
79 calculate_u(D, open_loop_dx_dt, V_dot_target, dx_dot_du);
111 ROS_ERROR(
"V_dot_target_initial must be negative. Change it in controller_parameters.h.");
117 ROS_ERROR(
"Check your saturation limit definitions. There are too many or too few values in one of the arrays. They must match the # of inputs to the system.");
124 ROS_ERROR(
"The 'low saturation limit' is higher than 'high saturation limit.' Change them in controller_parameters.h.");
130 ROS_ERROR(
"The published setpoint's length does not equal # of states. Check the data which is published by the plant.");
162 dx_dot_du(i,j) = closed_loop_dx_dt[j]-open_loop_dx_dt[j];
196 int largest_D_index = index_norm_inf(D);
203 if ( fabs( D[largest_D_index] + ( sum( element_prod(D,D) ) - pow(D[largest_D_index],2.0) )/D[largest_D_index]) > 0.0001 )
204 u(largest_D_index) = D[largest_D_index]*(V_dot_target-sum(P)) /
205 sum( element_prod(D,D) );
209 if ( i != largest_D_index )
213 u[i] =
u[largest_D_index]*D[i]/D[largest_D_index];
226 dV2_dx[0] = (
x[0]-
setpoint[0])*(0.9+0.1*tanh(
g))+
233 ublas_vector P_star = element_prod(dV2_dx, open_loop_dx_dt);
246 for (
int j=0; j<num_inputs-1; j++)
247 D_star[i] = D_star[i]+dV2_dx[j]*dx_dot_du(i,j);
255 u[0] = (V_dot_target-sum(P_star)) /
256 ( D_star[0] + (sum( element_prod(D_star,D_star) )-pow(D_star[0],2)) / D_star[0] );
266 u[i] =
u[0]*D_star[i]/D_star(0);
278 if ( (boost::math::isnan)(
u[i]) )
static const int num_inputs
void publish(const boost::shared_ptr< M > &message) const
static double V_dot_target_initial
void initial_error_check(const lyap_control::plant_msg &msg)
static const double low_saturation_limit[]
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void chatterCallback(const lyap_control::plant_msg &msg)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
boost::numeric::ublas::vector< double > ublas_vector
lyap_control::controller_msg u_msg
static const double high_saturation_limit[]
ublas_vector x(num_states)
ublas_vector u(num_inputs)
void calculate_V_and_damping(double &V_dot_target)
void calculate_u(ublas_vector &D, ublas_vector &open_loop_dx_dt, const double &V_dot_target, boost::numeric::ublas::matrix< double > &dx_dot_du)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void model_definition(const ublas_vector &x, ublas_vector &dxdt, const double t)
static int first_callback
ublas_vector setpoint(num_states)
static const double switching_threshold
ROSCPP_DECL void shutdown()
int main(int argc, char **argv)
static const double V_dot_target_initial_dB
ROSCPP_DECL void spinOnce()
void calculate_dx_dot_du(boost::numeric::ublas::matrix< double > &dx_dot_du, ublas_vector &open_loop_dx_dt)
static const int num_states