36 #include <boost/format.hpp> 37 #include <boost/shared_ptr.hpp> 38 #include <boost/thread/mutex.hpp> 98 std::string param_value;
100 std::stringstream
parser(param_value);
102 while (parser >> value)
103 rslt.push_back(value);
105 bool eof = parser.eof();
108 ROS_ERROR(
"Error parsing '%s/%s' argument to MultiTriggerController.", nh.
getNamespace().c_str(), param.c_str());
117 ROS_DEBUG(
"LOADING TRIGGER CONTROLLER NODE");
124 ROS_DEBUG(
"MultiTriggerController::init starting");
129 ROS_ERROR(
"MultiTriggerController was not given a digital_output parameter.");
136 ROS_ERROR(
"MultiTriggerController could not find digital output named \"%s\".",
146 std::vector<string> topics;
147 std::vector<double> times;
148 std::vector<uint32_t> values;
154 if (times.size() != topics.size() || times.size() != values.size())
155 ROS_ERROR(
"'topics', 'times' and 'values' parameters must have same length in %s. Ignoring initial settings.",
159 for (
unsigned int i = 0; i < times.size(); i++)
161 ethercat_trigger_controllers::MultiWaveformTransition t;
165 config_.transitions.push_back(t);
168 ethercat_trigger_controllers::SetMultiWaveform::Request req;
170 ethercat_trigger_controllers::SetMultiWaveform::Response dummy;
177 ROS_DEBUG(
"MultiTriggerController::init completed successfully.");
183 ethercat_trigger_controllers::SetMultiWaveform::Request &req,
184 ethercat_trigger_controllers::SetMultiWaveform::Response &resp)
186 std::vector<boost::shared_ptr<realtime_tools::RealtimePublisher<std_msgs::Header> > > new_pubs;
187 new_pubs.reserve(
config_.transitions.size());
188 ethercat_trigger_controllers::MultiWaveform &new_config = req.waveform;
190 double prev_time = -1;
192 double new_transition_period = round((now - new_config.zero_offset) / new_config.period);
193 double current_period_start = new_config.zero_offset + new_transition_period * new_config.period;
194 double now_offset = now - current_period_start;
195 unsigned int new_transition_index = 0;
198 if (new_transition_period <= 0)
200 resp.status_message =
"MultiTrigger period must be >0.";
201 resp.success =
false;
204 for (std::vector<ethercat_trigger_controllers::MultiWaveformTransition>::iterator trans = new_config.transitions.begin();
205 trans != new_config.transitions.end() && resp.success; trans++)
207 if (trans->time < now_offset)
208 new_transition_index++;
210 if (trans->time < 0 || trans->time >= new_config.period)
212 resp.status_message = (boost::format(
"MultiTriggerController::setMultiWaveformSrv transition time (%f) must be >= 0 and < period (%f).")%
213 trans->time%new_config.period).str();
214 resp.success =
false;
217 if (prev_time >= trans->time)
219 resp.status_message = (boost::format(
"MultiTriggerController::setMultiWaveformSrv transition times must be in increasing order. %f >= %f")%
220 prev_time%trans->time).str();
221 resp.success =
false;
225 if (new_transition_index == new_config.transitions.size())
227 new_transition_index = 0;
228 new_transition_period++;
231 double new_transition_time = current_period_start + new_config.transitions[new_transition_index].time;
239 for (std::vector<ethercat_trigger_controllers::MultiWaveformTransition>::iterator trans = new_config.transitions.begin();
240 trans != new_config.transitions.end() && resp.success; trans++)
244 if (trans->topic.compare(
"-"))
247 new_pubs.push_back(new_pub);
259 ROS_ERROR(
"%s", resp.status_message.c_str());
std::string digital_output_name_
unsigned int transition_index_
ros::NodeHandle node_handle_
pr2_mechanism_model::RobotState * robot_
std::vector< boost::shared_ptr< realtime_tools::RealtimePublisher< std_msgs::Header > > > pubs_
pr2_hardware_interface::HardwareInterface * hw_
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
DigitalOut * getDigitalOut(const std::string &name) const
boost::mutex config_mutex_
bool init(pr2_mechanism_model::RobotState *robot, ros::NodeHandle &n)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void publish(const boost::shared_ptr< M > &message) const
PLUGINLIB_EXPORT_CLASS(pr2_mechanism_model::PR2BeltCompensatorTransmission, pr2_mechanism_model::Transmission) namespace pr2_mechanism_model
bool getParam(const std::string &key, std::string &s) const
~MultiTriggerController()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
const std::string & getNamespace() const
ros::ServiceServer set_waveform_handle_
pr2_hardware_interface::DigitalOutCommand * digital_out_command_
double transition_period_
static bool parseParamList(ros::NodeHandle nh, std::string param, std::vector< T > &rslt)
DigitalOutCommand command_
bool setMultiWaveformSrv(ethercat_trigger_controllers::SetMultiWaveform::Request &req, ethercat_trigger_controllers::SetMultiWaveform::Response &resp)