Ignore:
Timestamp:
08/29/12 16:52:52 (12 years ago)
Author:
wcaarls
Message:

Updated extremum_seeking to revision 1017

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/extremum_seeking/esc_test/src/esc_test.cpp

    r11 r13  
    77void ESCTest::velocityCallback(const std_msgs::Float32MultiArray::ConstPtr &msg)
    88{
    9   system_->step(msg->data);
    10   publish();
     9  vel_ = msg->data;
     10  pos_.clear();
    1111}
    1212
    1313void ESCTest::positionCallback(const std_msgs::Float32MultiArray::ConstPtr &msg)
    1414{
    15   system_->set(msg->data);
    16   publish();
     15  pos_ = msg->data;
     16  vel_.clear();
    1717}
    1818
     
    3939  vel_sub_ = nh_.subscribe("vel_ref", 1, &ESCTest::velocityCallback, this);
    4040  pos_sub_ = nh_.subscribe("pos_ref", 1, &ESCTest::positionCallback, this);
    41 
    42   publish(); 
    4341}
    4442
     
    4745  ROS_INFO("Spinning");
    4846
    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  } 
    5059}
    5160
     
    5463  ros::init(argc, argv, "esc_test");
    5564 
     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 
    5679  ESCTest test;
    5780 
    58   test.init(new ESCSystem(new Gauss(-1, 2, 1)));
     81  test.init(new ESCSystem(function));
    5982  test.spin();
    6083 
Note: See TracChangeset for help on using the changeset viewer.