Go to the documentation of this file.00001 #include "tibi_dabo_laser_2d_to_3d_alg_node.h"
00002
00003 TibiDaboLaser2dTo3dAlgNode::TibiDaboLaser2dTo3dAlgNode(void) :
00004 algorithm_base::IriBaseAlgorithm<TibiDaboLaser2dTo3dAlgorithm>(),
00005 servo_angle_client_("servo_angle", true)
00006 {
00007
00008 this->loop_rate_ = 20;
00009
00010
00011 this->vertical_laser_pan_publisher_ = this->public_node_handle_.advertise<sensor_msgs::JointState>("vertical_laser_pan", 100);
00012 this->pointcloud_publisher_ = this->public_node_handle_.advertise<sensor_msgs::PointCloud>("pointcloud", 100);
00013
00014 this->JointState_msg_.name.resize(1);
00015 this->JointState_msg_.name[0] = "base_link2vertical_laser";
00016 this->JointState_msg_.position.resize(1);
00017
00018
00019
00020
00021
00022
00023 assemble_scans_client_ = this->public_node_handle_.serviceClient<laser_assembler::AssembleScans>("assemble_scans");
00024
00025
00026
00027
00028
00029 this->public_node_handle_.getParam("scan_vel", scan_vel);
00030 this->public_node_handle_.getParam("min_angle", angle_min);
00031 this->public_node_handle_.getParam("max_angle", angle_max);
00032
00033 angle=0.0;
00034 angle_margin=3.0;
00035 previous_time = ros::Time::now();
00036 minimum_time_between_scans = ros::Duration(1/900.0*scan_vel*scan_vel-7.0/60.0*scan_vel+3.5);
00037
00038
00039 this->servo_angle_goal_.trajectory.joint_names.resize(1);
00040 this->servo_angle_goal_.trajectory.points.resize(1);
00041 this->servo_angle_goal_.trajectory.points[0].positions.resize(1);
00042 this->servo_angle_goal_.trajectory.points[0].velocities.resize(1);
00043
00044 this->servo_angle_goal_.trajectory.joint_names[0]="vertical_laser_servo";
00045 this->servo_angle_goal_.trajectory.points[0].positions[0]=angle_min-angle_margin;
00046 this->servo_angle_goal_.trajectory.points[0].velocities[0]=scan_vel;
00047
00048 servo_angleMakeActionRequest();
00049 servo_going_right=false;
00050
00051 }
00052
00053 TibiDaboLaser2dTo3dAlgNode::~TibiDaboLaser2dTo3dAlgNode(void)
00054 {
00055
00056 }
00057
00058 void TibiDaboLaser2dTo3dAlgNode::mainNodeThread(void)
00059 {
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 if((angle>angle_max || angle<angle_min) && (ros::Time::now()-previous_time>minimum_time_between_scans)){
00071
00072 assemble_scans_srv_.request.begin = previous_time;
00073 assemble_scans_srv_.request.end = ros::Time::now();
00074 previous_time = ros::Time::now();
00075
00076
00077 if (assemble_scans_client_.call(assemble_scans_srv_))
00078 {
00079
00080
00081 this->pointcloud_publisher_.publish(assemble_scans_srv_.response.cloud);
00082 }
00083 else
00084 {
00085 ROS_ERROR("TibiDaboLaser2dTo3dAlgNode:: Failed to Call Server on topic assemble_scans ");
00086 }
00087
00088
00089 if(angle>angle_max){
00090 this->servo_angle_goal_.trajectory.points[0].positions[0]=angle_min-angle_margin;
00091 servo_going_right=false;
00092 }else if(angle<angle_min){
00093 this->servo_angle_goal_.trajectory.points[0].positions[0]=angle_max+angle_margin;
00094 servo_going_right=true;
00095 }
00096
00097 this->servo_angle_goal_.trajectory.points[0].velocities[0]=scan_vel;
00098
00099 servo_angleMakeActionRequest();
00100 }else if(ros::Time::now()-previous_time>minimum_time_between_scans){}
00101
00102
00103
00104
00105
00106
00107
00108
00109 }
00110
00111
00112
00113
00114
00115
00116 void TibiDaboLaser2dTo3dAlgNode::servo_angleDone(const actionlib::SimpleClientGoalState& state, const control_msgs::FollowJointTrajectoryResultConstPtr& result)
00117 {
00118 if( state.toString().compare("SUCCEEDED") == 0 )
00119 ROS_INFO("TibiDaboLaser2dTo3dAlgNode::servo_angleDone: Goal Achieved!");
00120 else
00121 ROS_INFO("TibiDaboLaser2dTo3dAlgNode::servo_angleDone: %s", state.toString().c_str());
00122
00123
00124 }
00125
00126 void TibiDaboLaser2dTo3dAlgNode::servo_angleActive()
00127 {
00128
00129 }
00130
00131 void TibiDaboLaser2dTo3dAlgNode::servo_angleFeedback(const control_msgs::FollowJointTrajectoryFeedbackConstPtr& feedback)
00132 {
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 double correction=-scan_vel/10.0;
00148
00149 angle=feedback->actual.positions[0];
00150 if(servo_going_right) angle=angle+correction;
00151
00152
00153
00154 this->JointState_msg_.header.stamp = ros::Time::now();
00155 this->JointState_msg_.position[0]=angle*TO_RAD;
00156 this->vertical_laser_pan_publisher_.publish(this->JointState_msg_);
00157
00158 if(servo_going_right) angle=angle-correction;
00159
00160
00161
00162 }
00163
00164
00165 void TibiDaboLaser2dTo3dAlgNode::servo_angleMakeActionRequest()
00166 {
00167
00168
00169
00170
00171 servo_angle_client_.waitForServer();
00172
00173
00174
00175
00176 servo_angle_client_.sendGoal(servo_angle_goal_,
00177 boost::bind(&TibiDaboLaser2dTo3dAlgNode::servo_angleDone, this, _1, _2),
00178 boost::bind(&TibiDaboLaser2dTo3dAlgNode::servo_angleActive, this),
00179 boost::bind(&TibiDaboLaser2dTo3dAlgNode::servo_angleFeedback, this, _1));
00180
00181 }
00182
00183 void TibiDaboLaser2dTo3dAlgNode::node_config_update(Config &config, uint32_t level)
00184 {
00185 this->alg_.lock();
00186
00187 scan_vel=config.scan_velocity;
00188 minimum_time_between_scans = ros::Duration(1/900.0*scan_vel*scan_vel-7.0/60.0*scan_vel+3.5);
00189 angle_min=config.min_angle;
00190 angle_max=config.max_angle;
00191
00192 this->alg_.unlock();
00193 }
00194
00195 void TibiDaboLaser2dTo3dAlgNode::addNodeDiagnostics(void)
00196 {
00197 }
00198
00199
00200 int main(int argc,char *argv[])
00201 {
00202 return algorithm_base::main<TibiDaboLaser2dTo3dAlgNode>(argc, argv, "tibi_dabo_laser_2d_to_3d_alg_node");
00203 }