28 #include <ArmarXCore/interface/components/EmergencyStopInterface.h>
30 #include <RobotAPI/interface/units/LaserScannerUnit.h>
32 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
33 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
34 #include <MemoryX/interface/memorytypes/MemorySegments.h>
40 #include <RobotComponents/interface/components/LaserScannerSelfLocalisation.h>
42 #include <Eigen/Eigen>
66 std::shared_ptr<std::mutex>
mutex;
69 std::vector<ExtractedEdge>
edges;
92 defineOptionalProperty<std::string>(
"ReportTopicName",
"LaserScannerSelfLocalisationTopic",
"The name of the report topic.");
93 defineOptionalProperty<std::string>(
"RobotStateComponentName",
"RobotStateComponent",
"The name of the RobotStateComponent. Used to get local transformation of laser scanners");
94 defineOptionalProperty<std::string>(
"PlatformName",
"Platform",
"Name of the platform to use. This property is used to listen to the platform topic");
95 defineOptionalProperty<std::string>(
"LaserScannerUnitName",
"LaserScannerSimulation",
"Name of the laser scanner unit to use.");
96 defineOptionalProperty<std::string>(
"WorkingMemoryName",
"WorkingMemory",
"Name of the WorkingMemory that should be used");
97 defineOptionalProperty<std::string>(
"LongtermMemoryName",
"LongtermMemory",
"Name of the LongtermMemory component");
98 defineOptionalProperty<bool>(
"UpdateWorkingMemory",
true,
"Update the working memory with the corrected position (disable in simulation)");
99 defineOptionalProperty<std::string>(
"MapFilename",
"RobotComponents/maps/building-5020-kitchen.json",
"Floor map (2D) used for global localisation");
100 defineOptionalProperty<std::string>(
"AgentName",
"",
"Name of the agent instance. If empty, the robot name of the RobotStateComponent will be used");
101 defineOptionalProperty<std::string>(
"EmergencyStopMasterName",
"EmergencyStopMaster",
"The name used to register as an EmergencyStopMaster");
102 defineOptionalProperty<std::string>(
"DebugObserverName",
"DebugObserver",
"Name of the topic the DebugObserver listens on");
104 defineOptionalProperty<int>(
"UpdatePeriodInMs", 5,
"Update period used for the map localisation");
105 defineOptionalProperty<int>(
"UpdatePeriodWorkingMemoryInMs", 30,
"Update period used for updating the working memory");
106 defineOptionalProperty<int>(
"UpdatePeriodLongtermMemoryInMs", 30,
"Update period used for updating the longterm memory");
107 defineOptionalProperty<float>(
"RobotPositionZ", 0.0f,
"The z-coordinate of the reported postion. Laser scanners can only self localize in x,y.");
109 defineOptionalProperty<float>(
"MaximalLaserScannerDelay", 0.1,
"If no new sensor values have been reported for this amound of seconds, we emit a soft emergency stop");
113 defineOptionalProperty<float>(
"MatchingMaxDistance", 300.0f,
"Maximal distance in mm up to which points are matched against edges of the map",
PropertyDefinitionBase::eModifiable);
114 defineOptionalProperty<float>(
"MatchingMinPoints", 0.01f,
"Minimum percentage of points which need to be matched (range [0, 1]). If less points are matched no global correction is applied.",
PropertyDefinitionBase::eModifiable);
115 defineOptionalProperty<float>(
"MatchingCorrectionFactor", 0.01f,
"This factor is used to apply the calculated map correction (range [0, 1])",
PropertyDefinitionBase::eModifiable);
116 defineOptionalProperty<float>(
"EdgeMaxDistance", 600.0f,
"Maximum distance between adjacent points up to which they are merged into one edge [mm]",
PropertyDefinitionBase::eModifiable);
117 defineOptionalProperty<float>(
"EdgeMaxDeltaAngle", 0.10472f,
"Maximum angle delta up to which adjacent points are merged into one edge [rad]",
PropertyDefinitionBase::eModifiable);
118 defineOptionalProperty<float>(
"EdgePointAddingThreshold", 10.0f,
"Maximum least square error up to which points are added to an edge (extension at the front and back)",
PropertyDefinitionBase::eModifiable);
131 defineOptionalProperty<bool>(
"RecordData",
false,
"If true, data is logged. Can be changed online. When set to false online, data is written to file. Otherwise on disconnect.",
PropertyDefinitionBase::eModifiable);
133 defineOptionalProperty<std::string>(
"PlatformRectangleMin",
"0, 0",
"Ignores points within the platform rectangle (this is the min x/y point)");
134 defineOptionalProperty<std::string>(
"PlatformRectangleMax",
"0, 0",
"Ignores points within the platform rectangle (this is the max x/y point)");
160 virtual public armarx::LaserScannerSelfLocalisationInterface
170 return "LaserScannerSelfLocalisation";
202 LineSegment2DSeq
getMap(
const Ice::Current&)
override;
205 void reportSensorValues(
const std::string& device,
const std::string& name,
const LaserScan& scan,
206 const TimestampBasePtr& timestamp,
const Ice::Current&)
override;
216 void updateLocalisation();
220 void resetKalmanFilter(
const Eigen::Vector3f& pose);
221 Eigen::Vector3f filterPose(
const Eigen::Vector3f& pose);
224 std::string reportTopicName;
225 std::string robotStateComponentName;
226 std::string platformName;
227 std::string laserScannerUnitName;
228 std::string workingMemoryName;
229 std::string longtermMemoryName;
230 std::string mapFilename;
231 std::string agentName;
232 std::string robotRootFrame;
234 std::string emergencyStopMasterName;
235 std::string debugObserverName;
236 float workingMemoryUpdateFrequency;
237 float longtermMemoryUpdateFrequency;
238 float robotPositionZ = 0.0f;
239 float maximalLaserScannerDelay = 0.1f;
241 std::mutex propertyMutex;
242 int propSmoothFrameSize;
243 int propSmoothMergeDistance;
244 float propMatchingMaxDistance;
245 float propMatchingMinPoints;
246 float propMatchingCorrectionFactor;
247 float propEdgeMaxDistance;
248 float propEdgeMaxDeltaAngle;
249 float propEdgePointAddingThreshold;
251 int propEdgeMinPoints;
252 bool propReportPoints;
253 bool propReportEdges;
254 bool propUseOdometry;
255 bool propUseMapCorrection;
256 float propSensorStdDev;
257 float propVelSensorStdDev;
258 std::string propLoggingFilePath;
259 bool propRecordData =
false;
261 std::atomic<bool> useOdometry;
263 std::vector<LineSegment2Df> map;
266 LaserScannerUnitInterfacePrx laserScannerUnit;
267 LaserScannerSelfLocalisationListenerPrx reportTopic;
268 PlatformUnitListenerPrx platformUnitTopic;
270 GlobalRobotPoseLocalizationListenerPrx globalRobotPoseTopic;
273 memoryx::WorkingMemoryInterfacePrx workingMemory;
274 memoryx::AgentInstancesSegmentBasePrx agentsMemory;
276 bool updateWorkingMemory =
false;
277 memoryx::LongtermMemoryInterfacePrx longtermMemory;
278 memoryx::PersistentEntitySegmentBasePrx selfLocalisationSegment;
279 std::string poseEntityId;
281 std::vector<LaserScanData> scanData;
283 std::mutex setPoseMutex;
284 std::optional<Eigen::Vector3f> setPose;
286 std::mutex odometryMutex;
287 std::vector<ReportedVelocity> reportedVelocities;
288 Eigen::Vector3f lastVelocity;
291 Eigen::Vector3f estimatedPose;
293 Eigen::Vector2f platformRectMin{0, 0};
294 Eigen::Vector2f platformRectMax{0, 0};
300 std::mutex kalmanMutex;
303 struct LaserScannerFileLoggingData
305 std::mutex loggingMutex;
306 std::string filePath;
308 std::map<IceUtil::Time, std::vector<LaserScanData>> scanDataHistory;
310 std::unique_ptr<LaserScannerFileLoggingData> laserScannerFileLoggingData;