Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include <trajmodules/VMObsAvoid.hpp>
00009
00010 #include <telekyb_base/ROS.hpp>
00011
00012
00013 PLUGINLIB_DECLARE_CLASS(tk_trajprocessor, VMObsAvoid, telekyb_traj::VMObsAvoid, TELEKYB_NAMESPACE::TrajectoryModule);
00014
00015 namespace telekyb_traj {
00016
00017 VMObsAvoidOptions::VMObsAvoidOptions()
00018 : OptionContainer("VMObsAvoid")
00019 {
00020 tObsPointsTopicName = addOption<std::string>("tObsPointsTopicName", "Topic Name of Obstacle Points",
00021 "undef", true, true);
00022 }
00023
00024
00025 VMObsAvoid::VMObsAvoid()
00026 : TrajectoryModule("tk_trajprocessor/VMObsAvoid", TrajModulePosType::Velocity, 100),
00027 obsAvoidPotentialAlg(getName())
00028 {
00029
00030 }
00031
00032 void VMObsAvoid::initialize()
00033 {
00034
00035 }
00036
00037 void VMObsAvoid::destroy()
00038 {
00039
00040 }
00041
00042
00043 void VMObsAvoid::willTurnActive()
00044 {
00045 ros::NodeHandle n(ROSModule::Instance().getMainNodeHandle());
00046 lastObstaclePoints.clear();
00047 obsPointSub = n.subscribe(options.tObsPointsTopicName->getValue(), 1, &VMObsAvoid::obsPointCB, this);
00048 }
00049
00050
00051 void VMObsAvoid::didTurnInactive()
00052 {
00053 obsPointSub.shutdown();
00054 }
00055
00056 bool VMObsAvoid::trajectoryStep(const TKState& currentState, TKTrajectory& trajInput)
00057 {
00058 boost::mutex::scoped_lock lastObstaclePointsLock(lastObstaclePointsMutex);
00059 Velocity3D obsVelocity = obsAvoidPotentialAlg.getObstacleVelocity(currentState.position, lastObstaclePoints);
00060
00061
00062 trajInput.velocity += obsVelocity;
00063
00064
00065 return true;
00066 }
00067
00068 void VMObsAvoid::obsPointCB(const telekyb_msgs::StampedPointArray::ConstPtr& obsPointsMsg)
00069 {
00070 boost::mutex::scoped_lock lastObstaclePointsLock(lastObstaclePointsMutex);
00071 lastObstaclePoints.resize(obsPointsMsg->points.size());
00072 for (unsigned int i = 0; i < lastObstaclePoints.size(); ++i) {
00073 lastObstaclePoints[i](0) = obsPointsMsg->points[i].x;
00074 lastObstaclePoints[i](1) = obsPointsMsg->points[i].y;
00075 lastObstaclePoints[i](2) = obsPointsMsg->points[i].z;
00076 }
00077 }
00078
00079 }