Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I fixed my own problem! I found that I needed to convert float to char* using a function in the standard Arduino library called dtostrf(). Think of it as "Decimal to String Float".

This answer has a better description: http://arduino.stackexchange.com/questions/26832/how-do-i-convert-a-float-into-char

Working code:

void jt_callback(const trajectory_msgs::JointTrajectory &msg) {
  nh.loginfo("msg received");
  // Print points.positions[0]
  char result[8]; // Buffer big enough for 7-character float
  dtostrf(points[0].positions[0], 6, 2, result); // Leave room for too large numbers!
  sprintf(log_msg,"points[0].positions[0] =%s", result);
  nh.loginfo(log_msg);
}

Correct output:

[INFO] [1487353743.896876, 6929.022000]: points[0].positions[0] = 0.10