0

I am trying to run a ROS node which subscribes data from a node and then calculates the PID controller output and publishes it on another topic.But I get a Bus, core dumped error after every 10 cycles...I am not sure why...Here is the code for reference:

namespace youbot {

PidController::PidController(double P, double I, double D, double I1, double I2) :
p_gain_(P), i_gain_(I), d_gain_(D), i_max_(I1), i_min_(I2)
{

   p_error_last_ = 0.0;
   p_error_ = 0.0;
   d_error_ = 0.0;

   i_error_ = 0.0;
   cmd_ = 0.0;
   last_i_error = 0.0;
}

double PidController::updatePid(double error, boost::posix_time::time_duration dt)
{
    double p_term, d_term, i_term;
    p_error_ = error; //this is pError = pState-pTarget
    double deltatime = (double)dt.total_microseconds()/1000.0; //in milli seconds


   if (deltatime == 0.0 || isnan(error) || isinf(error))
      return 0.0;
   p_term = p_gain_ * p_error_;
   i_error_ = last_i_error + deltatime * p_error_;
   last_i_error = deltatime * p_error_;
   i_term = i_gain_ * i_error_;
   if (i_term > i_max_)
   {  
     i_term = i_max_;
     i_error_=i_term/i_gain_;
   }
   else if (i_term < i_min_)
   {
     i_term = i_min_;
     i_error_=i_term/i_gain_;
   }


  if (deltatime != 0)
  {
     d_error_ = (p_error_ - p_error_last_) / deltatime;
     p_error_last_ = p_error_;
  }
  d_term = d_gain_ * d_error_;
  cmd_ = -p_term - i_term - d_term;

  p_error_, i_error_, p_term, i_term, deltatime, cmd_);

  return cmd_;
}
}

using namespace std;
using namespace youbot;

double currentPos[3];
void arrayCallback(const geometry_msgs::Point::ConstPtr& cord);
double calculateControllerOutput(double pos, double targetPos);


int main(int argc, char **argv)
{

ros::init(argc, argv, "coordinateSubscriber");
ros::NodeHandle n;
ros::Subscriber sub3 = n.subscribe("position", 100, arrayCallback);
ros::spin();

return 0;
}

I'm not able to guess which part is causing the error.Any help will be appreciated..Thanks !

Jonas
  • 121,568
  • 97
  • 310
  • 388
Preity
  • 63
  • 2
  • 4
  • There must be something missing. The second last line of updatePid has a syntax error. Do you have sn idea where exactly the crash occurs? – PMF Nov 09 '13 at 20:53
  • Oh..thats just a typing error...that line is supposed to be ignored..I meant to remove it. – Preity Nov 09 '13 at 21:59
  • I am not sure y is it occuring...and it occurs only after I subscribe for a couple of secs. – Preity Nov 09 '13 at 22:01
  • I'm not sure, but I don't think the error happens in the code you posted. A Bus error means there's some problem with memory alignment (see http://stackoverflow.com/questions/212466/what-is-a-bus-error), which can only happen when you do some pointer magic, which I don't see in this code. What hardware is this? Because on x86, bus errors are very rare. – PMF Nov 10 '13 at 10:14

0 Answers0