49 tracking_offset_ = 0 ;
53 LaserScannerTrajController::~LaserScannerTrajController()
66 if (!n.
getParam(
"joint", joint_name))
68 ROS_ERROR(
"LaserScannerTrajController: joint_name param not defined (namespace: %s)", n.
getNamespace().c_str()) ;
76 ROS_ERROR(
"LaserScannerTrajController: Could not find joint \"%s\" in robot model (namespace: %s)", joint_name.c_str(), n.
getNamespace().c_str()) ;
81 ROS_ERROR(
"LaserScannerTrajController: Joint \"%s\" has no limits specified (namespace: %s)", joint_name.c_str(), n.
getNamespace().c_str()) ;
88 ROS_ERROR(
"LaserScannerTrajController: Could not start because joint [%s] isn't calibrated (namespace: %s)", joint_name.c_str(), n.
getNamespace().c_str());
95 ROS_ERROR(
"LaserTiltController: Error initializing pid gains (namespace: %s)", n.
getNamespace().c_str());
105 ROS_ERROR(
"LaserTiltController: Error initializing filter chain");
112 ROS_ERROR(
"max velocity param not defined");
118 ROS_ERROR(
"max acceleration param not defined");
124 pr2_msgs::PeriodicCmd
cmd ;
125 cmd.profile =
"linear" ;
127 cmd.amplitude = 0.0 ;
173 sampled_point.
q_.resize(1) ;
174 sampled_point.
qdot_.resize(1) ;
177 result =
traj_.
sample(sampled_point, profile_time) ;
195 double filtered_d_error;
203 filtered_d_error, dt) ;
232 vector<double> max_rates ;
233 max_rates.push_back(max_rate) ;
234 vector<double> max_accs ;
235 max_accs.push_back(max_acc) ;
257 if (cmd.profile ==
"linear" ||
258 cmd.profile ==
"blended_linear")
260 double high_pt = cmd.amplitude + cmd.offset ;
261 double low_pt = -cmd.amplitude + cmd.offset ;
267 if (low_pt < soft_limit_low)
269 ROS_WARN(
"Lower setpoint (%.3f) is below the soft limit (%.3f). Truncating command", low_pt, soft_limit_low) ;
270 low_pt = soft_limit_low ;
273 if (high_pt > soft_limit_high)
275 ROS_WARN(
"Upper setpoint (%.3f) is above the soft limit (%.3f). Truncating command", high_pt, soft_limit_high) ;
276 high_pt = soft_limit_high ;
279 std::vector<trajectory::Trajectory::TPoint> tpoints ;
285 cur_point.
q_[0] = low_pt ;
286 cur_point.
time_ = 0.0 ;
287 tpoints.push_back(cur_point) ;
289 cur_point.
q_[0] = high_pt ;
290 cur_point.
time_ = cmd.period/2.0 ;
291 tpoints.push_back(cur_point) ;
293 cur_point.
q_[0] = low_pt ;
294 cur_point.
time_ = cmd.period ;
295 tpoints.push_back(cur_point) ;
298 ROS_ERROR(
"Failed to set tilt laser scanner trajectory.") ;
308 ROS_WARN(
"Unknown Periodic Trajectory Type. Not setting command.") ;
315 if (traj_cmd.profile ==
"linear" ||
316 traj_cmd.profile ==
"blended_linear")
318 const unsigned int N = traj_cmd.position.size() ;
319 if (traj_cmd.time_from_start.size() != N)
321 ROS_ERROR(
"# Times and # Pos must match! pos.size()=%u times.size()=%zu", N, traj_cmd.time_from_start.size()) ;
326 std::vector<trajectory::Trajectory::TPoint> tpoints ;
327 for (
unsigned int i=0; i<N; i++)
331 cur_point.
q_[0] = traj_cmd.position[i] ;
332 cur_point.
time_ = traj_cmd.time_from_start[i].toSec() ;
333 tpoints.push_back(cur_point) ;
340 if (traj_cmd.max_velocity > 0)
341 cur_max_rate = traj_cmd.max_velocity ;
342 if (traj_cmd.max_acceleration > 0)
343 cur_max_acc = traj_cmd.max_acceleration ;
345 if (!
setTrajectory(tpoints, cur_max_rate, cur_max_acc, traj_cmd.profile))
347 ROS_ERROR(
"Failed to set tilt laser scanner trajectory.") ;
358 ROS_WARN(
"Unknown Periodic Trajectory Type. Not setting command.") ;
457 ROS_ERROR(
"Error Loading LaserScannerTrajController Params") ;
473 ROS_ERROR(
"LaserScannerTrajController shouldn't ever execute this line... could be a bug elsewhere");
487 pr2_msgs::SetPeriodicCmd::Response &res)
489 ROS_INFO(
"LaserScannerTrajControllerNode: set periodic command");
508 pr2_msgs::SetLaserTrajCmd::Response &res)
510 ROS_INFO(
"LaserScannerTrajControllerNode: set traj command");
trajectory::Trajectory traj_
PLUGINLIB_EXPORT_CLASS(my_controller_ns::MyControllerClass, pr2_controller_interface::Controller)
pr2_msgs::LaserScannerSignal m_scanner_signal_
Stores the message that we want to send at the end of each sweep, and halfway through each sweep...
~LaserScannerTrajControllerNode()
control_toolbox::Pid pid_controller_
filters::FilterChain< double > d_error_filter_chain_
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::ServiceServer serve_set_periodic_cmd_
double getTotalTime()
Get the total time for the trajectory.
pr2_mechanism_model::RobotState * robot_
int getCurProfileSegment()
Returns the current trajectory segment we're executing in our current profile.
void setPeriodicCmd(const pr2_msgs::PeriodicCmdConstPtr &cmd)
std::string service_prefix_
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
boost::shared_ptr< const urdf::Joint > joint_
bool init(pr2_mechanism_model::RobotState *robot, ros::NodeHandle &n)
bool init(pr2_mechanism_model::RobotState *robot, ros::NodeHandle &n)
ros::Subscriber sub_set_periodic_cmd_
double getProfileDuration()
Returns the length (in seconds) of our current profile.
LaserScannerTrajController c_
pr2_mechanism_model::JointState * joint_state_
ros::ServiceServer serve_set_Traj_cmd_
bool setPeriodicCmd(const pr2_msgs::PeriodicCmd &cmd)
void setTrajCmd(const pr2_msgs::LaserTrajCmdConstPtr &traj_cmd)
pr2_mechanism_model::RobotState * robot_
bool need_to_send_msg_
Tracks whether we still need to send out the m_scanner_signal_ message.
const std::string & getNamespace() const
int prev_profile_segment_
The segment in the current profile when update() was last called.
JointState * getJointState(const std::string &name)
bool setTrajSrv(pr2_msgs::SetLaserTrajCmd::Request &req, pr2_msgs::SetLaserTrajCmd::Response &res)
def shortest_angular_distance_with_limits(from_angle, to_angle, left_limit, right_limit)
double getCurProfileTime()
Returns what time we're currently at in the profile being executed.
bool getParam(const std::string &key, std::string &s) const
bool setPeriodicSrv(pr2_msgs::SetPeriodicCmd::Request &req, pr2_msgs::SetPeriodicCmd::Response &res)
bool update(const T &data_in, T &data_out)
bool configure(std::string param_name, ros::NodeHandle node=ros::NodeHandle())
LaserScannerTrajControllerNode()
int sample(TPoint &tp, double time)
Sample the trajectory at a certain point in time.
ros::Time traj_start_time_
bool setTrajCmd(const pr2_msgs::LaserTrajCmd &traj_cmd)
int findTrajectorySegment(double time)
finds the trajectory segment corresponding to a particular time
realtime_tools::RealtimePublisher< pr2_msgs::LaserScannerSignal > * publisher_
Publishes the m_scanner_signal msg from the update() realtime loop.
std::vector< double > qdot_
int setMaxAcc(std::vector< double > max_acc)
ros::Subscriber sub_set_traj_cmd_
void setInterpolationMethod(std::string interp_method)
Set the interpolation method.
bool setTrajectory(const std::vector< trajectory::Trajectory::TPoint > &traj_points, double max_rate, double max_acc, std::string interp)
int setMaxRates(std::vector< double > max_rate)
set the max rates (velocities)
int setTrajectory(const std::vector< TPoint > &tp)
Set the trajectory using a vector of trajectory points.