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