139 const double freq = 1.0 / (
event.current_real -
event.last_real).toSec();
141 "Updating at " << freq <<
" hz, total: " 159 std::cout <<
"Writing data to file " << std::endl;
163 std::cout <<
"No controller states populated" << std::endl;
167 std::ofstream output_file;
171 output_file <<
"timestamp,";
172 for (std::size_t j = 0; j <
states_[0].joint_names.size(); ++j)
174 output_file <<
states_[0].joint_names[j] <<
"_desired_pos," <<
states_[0].joint_names[j] <<
"_desired_vel," 175 <<
states_[0].joint_names[j] <<
"_actual_pos," <<
states_[0].joint_names[j] <<
"_actual_vel," 176 <<
states_[0].joint_names[j] <<
"_error_pos," <<
states_[0].joint_names[j] <<
"_error_vel,";
178 output_file << std::endl;
186 for (std::size_t i = 0; i <
states_.size(); ++i)
189 output_file <<
timestamps_[i].toSec() - start_time <<
",";
192 for (std::size_t j = 0; j <
states_[i].joint_names.size(); ++j)
195 output_file <<
states_[i].desired.positions[j] <<
"," <<
states_[i].desired.velocities[j] <<
"," 196 <<
states_[i].actual.positions[j] <<
"," <<
states_[i].actual.velocities[j] <<
"," 197 <<
states_[i].error.positions[j] <<
"," <<
states_[i].error.velocities[j] <<
",";
200 output_file << std::endl;
203 std::cout <<
"Wrote to file: " <<
file_name_ << std::endl;
224 while (num_existing_subscribers == 0)
230 << wait_time <<
" seconds.");
247 <<
" seconds to connect to a subscriber. " 249 << num_existing_subscribers <<
" total subsribers");
std::string getTopic() const
#define ROS_DEBUG_STREAM_NAMED(name, args)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
~ControllerToCSV()
Destructor.
void stopRecording()
End recording.
bool writeToFile()
Send all resulting data to file.
uint32_t getNumPublishers() const
#define ROS_INFO_STREAM_NAMED(name, args)
void stateCB(const control_msgs::JointTrajectoryControllerState::ConstPtr &state)
Callback from ROS message.
void update(const ros::TimerEvent &e)
Recieve data from controller via ROS message.
bool recordAll()
Whether to record at a specific frequency, or record all incoming data.
control_msgs::JointTrajectoryControllerState current_state_
ros::Subscriber state_sub_
#define ROS_WARN_STREAM_THROTTLE_NAMED(period, name, args)
std::vector< ros::Time > timestamps_
ros::Timer non_realtime_loop_
std::vector< control_msgs::JointTrajectoryControllerState > states_
bool waitForSubscriber(const ros::Subscriber &sub, const double &wait_time=10.0)
Check if topic has been connected to successfully.
void shutdownIfError(const std::string &parent_name, std::size_t error_count)
#define ROS_INFO_STREAM_THROTTLE_NAMED(period, name, args)
void startRecording(const std::string &file_name)
Start the data collection.
ROSCPP_DECL void spinOnce()
bool get(const std::string &parent_name, const ros::NodeHandle &nh, const std::string ¶m_name, bool &value)
ControllerToCSV(const std::string &topic)
Constructor.
#define ROS_WARN_STREAM_NAMED(name, args)