Go to the documentation of this file.00001
00002
00003
00004
00005 #include "lyap_control/second_order_plant.h"
00006
00007
00008 int main(int argc, char **argv)
00009 {
00010 ros::init(argc, argv, "plant");
00011
00012 ros::NodeHandle plant_node;
00013
00014
00015 lyap_control::plant_msg msg;
00016
00017
00018 for (int i=0; i<num_states; i++)
00019 {
00020 msg.x[i] = x_IC[i];
00021 msg.setpoint[i] = setpoint[i];
00022 }
00023 msg.t = t_IC;
00024
00025
00026 ros::Publisher chatter_pub = plant_node.advertise<lyap_control::plant_msg>("state", 1);
00027
00028
00029 ros::Subscriber sub = plant_node.subscribe("control_effort", 1, chatterCallback );
00030
00031 double x_dot [num_states] = {0.0, 0.0};
00032
00033 ros::Rate loop_rate(1/delta_t);
00034
00035 ROS_INFO("Waiting 3s for rqt_plot to load.");
00036 ros::Duration d(3.0);
00037 d.sleep();
00038
00039 while (ros::ok())
00040 {
00041 ROS_INFO("x1: %f x2: %f", msg.x[0], msg.x[1]);
00042
00043 chatter_pub.publish(msg);
00044
00045
00046 x_dot[0] = 0.1*msg.x[0]+u[0];
00047 x_dot[1] = 2.0*msg.x[1]+u[1];
00048
00049 msg.x[0] = msg.x[0]+x_dot[0]*delta_t;
00050 msg.x[1] = msg.x[1]+x_dot[1]*delta_t;
00051
00052 msg.t = msg.t+delta_t;
00053
00054 ros::spinOnce();
00055
00056 loop_rate.sleep();
00057 }
00058
00059 return 0;
00060 }
00061
00062
00063 void chatterCallback(const lyap_control::controller_msg& u_msg)
00064 {
00065
00066
00067
00068 for (int i=0; i< num_inputs; i++)
00069 u[i] = u_msg.u[i];
00070 }