6 #define ROS_TDIFF(t) (t.toSec() - timeInit.toSec()) 35 MAX_ROBOTS, NUM_LANDMARKS, PLAYING_ROBOTS,
39 pf = boost::shared_ptr<PFPublisher>(
44 timeInit = ros::Time::now();
45 ROS_INFO(
"Init time set to %f", timeInit.toSec());
49 if (PLAYING_ROBOTS[rn])
62 pf->init(CUSTOM_PARTICLE_INIT, POS_INIT);
70 if (!readParam<std::string>(
nh_,
"/LANDMARKS_CONFIG", filename))
75 ROS_ERROR_COND(landmarks.empty(),
"Couldn't open file \"%s\"",
79 "Read a number of landmarks different from the specified in " 83 for (std::vector<Landmark>::iterator it = landmarks.begin();
84 it != landmarks.end(); ++it)
86 ROS_INFO(
"A fixed landmark with ID %d at position {x=%.2f, y=%.2f} \twas " 88 it->serial, it->x, it->y);
94 for (std::vector<Robot_ptr>::iterator it =
robots_.begin();
97 if (
false == (*it)->hasStarted())
105 timeStarted_ = ros::Time::now();
107 ROS_INFO(
"OMNI%d has started %.2fs after the initial time", robotNumber_ + 1,
113 : parent_(parent), pf_(pf), started_(false), robotNumber_(robotNumber)
115 std::string robotNamespace(
"/omni" +
116 boost::lexical_cast<std::string>(robotNumber + 1));
120 robotNamespace +
"/odometry", 10,
123 sBall_ = nh.subscribe<read_omni_dataset::BallData>(
124 robotNamespace +
"/orangeball3Dposition", 10,
127 sLandmark_ = nh.subscribe<read_omni_dataset::LRMLandmarksData>(
128 robotNamespace +
"/landmarkspositions", 10,
131 ROS_INFO(
"Created robot OMNI%d", robotNumber + 1);
143 odomStruct.
x = odometry->pose.pose.position.x;
144 odomStruct.
y = odometry->pose.pose.position.y;
145 odomStruct.
theta = tf2::getYaw(odometry->pose.pose.orientation);
172 obs.
d = Eigen::Vector2d(obs.
x, obs.
y).norm();
173 obs.
r = Eigen::Vector3d(obs.
x, obs.
y, obs.
z).norm();
174 obs.
phi = atan2(target->y, target->x);
177 const double cos2p = pow(cos(obs.
phi), 2);
178 const double sin2p = pow(sin(obs.
phi), 2);
179 const double d2 = pow(obs.
d, 2);
180 const double r2 = pow(obs.
r, 2);
183 static const float ballRadius = 0.1;
184 static const float ballr2 = pow(ballRadius, 2);
185 obs.
covDD = K3 * (r2 * sin2p / (2 * ballr2)) +
186 K4 * (r2 * sin2p / (2 * (r2 - ballr2))) +
187 K3 * K4 * (r2 * cos2p / (4 * ballr2 * (r2 - ballr2)));
188 obs.
covPP = K5 / (r2 - ballr2 * sin2p);
220 const read_omni_dataset::LRMLandmarksData::ConstPtr& landmarkData)
227 heuristicsFound[i] = landmarkData->found[i];
229 float distances[NUM_LANDMARKS];
235 pow((pow(landmarkData->x[i], 2) + pow(landmarkData->y[i], 2)), 0.5);
239 if (USE_CUSTOM_VALUES)
242 if (landmarkData->found[8] && !landmarkData->found[9])
243 heuristicsFound[7] =
false;
246 if (!landmarkData->found[8] && landmarkData->found[9])
247 heuristicsFound[6] =
false;
250 if (landmarkData->found[8] && landmarkData->found[9])
253 if (distances[9] < distances[8])
254 heuristicsFound[6] =
false;
257 if (distances[8] < distances[9])
258 heuristicsFound[7] =
false;
265 heuristicsThresh[4] = 6.5;
266 heuristicsThresh[5] = 6.5;
267 heuristicsThresh[8] = 6.5;
268 heuristicsThresh[9] = 6.5;
273 heuristicsThresh[4] = 6.5;
274 heuristicsThresh[5] = 6.5;
275 heuristicsThresh[8] = 6.5;
276 heuristicsThresh[9] = 6.5;
281 heuristicsThresh[4] = 6.5;
282 heuristicsThresh[5] = 6.5;
283 heuristicsThresh[8] = 6.5;
284 heuristicsThresh[9] = 6.5;
289 heuristicsThresh[4] = 3.5;
290 heuristicsThresh[5] = 3.5;
291 heuristicsThresh[8] = 3.5;
292 heuristicsThresh[9] = 3.5;
298 if (distances[i] > heuristicsThresh[i])
299 heuristicsFound[i] =
false;
308 if (
false == heuristicsFound[i])
315 obs.
x = landmarkData->x[i];
316 obs.
y = landmarkData->y[i];
317 obs.
d = sqrt(obs.
x * obs.
x + obs.
y * obs.
y);
326 obs.
phi = atan2(obs.
y, obs.
x);
328 (K1 * fabs(1.0 - (landmarkData->AreaLandMarkActualinPixels[i] /
329 landmarkData->AreaLandMarkExpectedinPixels[i]))) *
331 obs.
covPP = NUM_LANDMARKS * K2 * (1 / (obs.
d + 1));
333 pow(sin(obs.
phi), 2) *
336 pow(cos(obs.
phi), 2) *
340 landmarkData->header.stamp);
350 int main(
int argc,
char* argv[])
356 std::cout <<
"Usage: pfuclt_omni_dataset --debug [true|FALSE] --publish [TRUE|false]" << std::endl;
359 if (!strcmp(argv[2],
"true"))
361 if (ros::console::set_logger_level(ROSCONSOLE_DEFAULT_NAME,
362 ros::console::levels::Debug))
364 ros::console::notifyLoggerLevelsChanged();
377 if (!strcmp(argv[4],
"true"))
387 ROS_INFO_STREAM(
"DEBUG set to " << std::boolalpha <<
DEBUG <<
" and PUBLISH set to " << std::boolalpha <<
PUBLISH);
389 ros::init(argc, argv,
"pfuclt_omni_dataset");
390 ros::NodeHandle nh(
"~");
394 readParam<float>(nh,
"ROB_HT",
ROB_HT);
397 readParam<float>(nh,
"LANDMARK_COV/K1",
K1);
398 readParam<float>(nh,
"LANDMARK_COV/K2",
K2);
399 readParam<float>(nh,
"LANDMARK_COV/K3",
K3);
400 readParam<float>(nh,
"LANDMARK_COV/K4",
K4);
401 readParam<float>(nh,
"LANDMARK_COV/K5",
K5);
403 readParam<double>(nh,
"POS_INIT",
POS_INIT);
405 readParam<int>(nh,
"MY_ID",
MY_ID);
412 ROS_ERROR(
"CUSTOM_PARTICLE_INIT given but not of correct size - should " 413 "have %d numbers and has %d",
417 ROS_INFO(
"Waiting for /clock");
418 ros::Time::waitForValid();
419 ROS_INFO(
"/clock message received");
425 ROS_WARN(
"OMNI2 not present in dataset.");
void tryInitializeParticles()
tryInitializeParticles - checks if every robot is started, and if so, will initiate the particle filt...
boost::shared_ptr< Robot > Robot_ptr
int main(int argc, char *argv[])
void initializeFixedLandmarks()
initializeFixedLandmarks - will get a filename from the parameter server, and use its information to ...
#define HEURISTICS_THRESH_DEFAULT
std::vector< Landmark > landmarks
std::vector< double > POS_INIT
void updateTargetIterationTime(ros::Time tRos)
updateTargetIterationTime - the main robot should call this method after the target callback ...
#define STATES_PER_TARGET
RobotFactory(ros::NodeHandle &nh)
bool isInitialized()
isInitialized - simple interface to access private member initialized_
The PFPublisher class - implements publishing for the ParticleFilter class using ROS.
std::vector< double > CUSTOM_PARTICLE_INIT
std::vector< bool > PLAYING_ROBOTS
void odometryCallback(const nav_msgs::Odometry::ConstPtr &)
odometryCallback - event-driven function which should be called when new odometry data is received ...
void saveTargetObservation(const uint robotNumber, const TargetObservation obs, ros::Time stamp)
saveTargetObservation - saves the target observation to a buffer of observations
The RobotFactory class - Creates and keeps information on the robot running the algorithm and its tea...
void landmarkDataCallback(const read_omni_dataset::LRMLandmarksData::ConstPtr &)
landmarkDataCallback - event-driven function which should be called when new landmark data is receive...
std::vector< Landmark > getLandmarks(const char *filename)
getLandmarks - read landmark configuration from CSV file
bool areAllRobotsActive()
areAllTeammatesActive - uses each robot's public methods to check if they have started yet ...
boost::shared_ptr< ParticleFilter > pf
The PFinitData struct - provides encapsulation to the initial data necessary to construct a ParticleF...
The Robot class - Has the common variables and methods of all robots, and is the base class of any sp...
void saveAllTargetMeasurementsDone(const uint robotNumber)
saveAllTargetMeasurementsDone - call this function when all target measurements have been performed b...
ros::Subscriber sLandmark_
void saveLandmarkObservation(const uint robotNumber, const uint landmarkNumber, const LandmarkObservation obs, ros::Time stamp)
saveLandmarkObservation - saves the landmark observation to a buffer of observations ...
Robot(ros::NodeHandle &nh, RobotFactory *parent, ParticleFilter *pf, uint robotNumber)
Robot - constructor, creates a new Robot instance.
void targetCallback(const read_omni_dataset::BallData::ConstPtr &)
targetCallBack - event-driven function which should be called when new target data is received ...
struct pfuclt_omni_dataset::odometry_s Odometry
void predict(const uint robotNumber, const Odometry odom, const ros::Time stamp)
predict - prediction step in the particle filter set with the received odometry
void startNow()
startNow - starts the robot
void saveAllLandmarkMeasurementsDone(const uint robotNumber)
saveAllLandmarkMeasurementsDone - call this function when all landmark measurements have been perform...
std::vector< Robot_ptr > robots_