Changeset 13 for trunk/extremum_seeking/esc_test/src
- Timestamp:
- 08/29/12 16:52:52 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/extremum_seeking/esc_test/src/esc_test.cpp
r11 r13 7 7 void ESCTest::velocityCallback(const std_msgs::Float32MultiArray::ConstPtr &msg) 8 8 { 9 system_->step(msg->data);10 p ublish();9 vel_ = msg->data; 10 pos_.clear(); 11 11 } 12 12 13 13 void ESCTest::positionCallback(const std_msgs::Float32MultiArray::ConstPtr &msg) 14 14 { 15 system_->set(msg->data);16 publish();15 pos_ = msg->data; 16 vel_.clear(); 17 17 } 18 18 … … 39 39 vel_sub_ = nh_.subscribe("vel_ref", 1, &ESCTest::velocityCallback, this); 40 40 pos_sub_ = nh_.subscribe("pos_ref", 1, &ESCTest::positionCallback, this); 41 42 publish();43 41 } 44 42 … … 47 45 ROS_INFO("Spinning"); 48 46 49 ros::spin(); 47 ros::Rate loop_rate(100); 48 while (nh_.ok()) 49 { 50 if (!vel_.empty()) 51 system_->step(vel_); 52 else if (!pos_.empty()) 53 system_->set(pos_); 54 publish(); 55 56 loop_rate.sleep(); 57 ros::spinOnce(); 58 } 50 59 } 51 60 … … 54 63 ros::init(argc, argv, "esc_test"); 55 64 65 ESCFunction *function; 66 67 if (argc > 1 && strcmp(argv[1], "-2") == 0) 68 { 69 std::vector<float> mean, sigma; 70 mean.push_back(0.5); 71 mean.push_back(0.2); 72 sigma.push_back(0.15); 73 sigma.push_back(0.15); 74 function = new Gauss2D(2, -1, mean, sigma); 75 } 76 else 77 function = new Gauss1D(2.5, -1.5, 0.4, 0.27/sqrt(2.0)); 78 56 79 ESCTest test; 57 80 58 test.init(new ESCSystem( new Gauss(-1, 2, 1)));81 test.init(new ESCSystem(function)); 59 82 test.spin(); 60 83
Note: See TracChangeset
for help on using the changeset viewer.