21 sampleIndexRotation = 0;
22 sampleIndexPressure = 0;
23 sampleIndexAcceleration = 0;
24 sampleIndexPressureRate = 0;
33 IceUtil::Time now = IceUtil::Time::now();
34 time_t timer = now.toSeconds();
37 ts = localtime(&timer);
38 strftime(buffer, 80,
"%Y-%m-%d-%H-%M-%S", ts);
39 std::string packageName =
"RobotAPI";
41 std::string dataDir = finder.
getDataDir() +
"/" + packageName +
"/logs/";
42 std::string filename = dataDir + buffer + std::string(
"_data") +
".json";
46 prefix = std::string(buffer);
60 fd = open(portname.c_str(), O_RDWR | O_NOCTTY);
61 struct termios toptions;
64 tcgetattr(fd, &toptions);
67 cfsetispeed(&toptions, B115200);
68 cfsetospeed(&toptions, B115200);
76 tcsetattr(fd, TCSANOW, &toptions);
82 tcflush(fd, TCIFLUSH);
87 if (!arduinoIn.is_open())
90 throw LocalException(
"Cannot open Arduino on ")
98 std::string arduinoLine;
101 ARMARX_INFO <<
"waiting for IMU calibration - this can take some time";
106 while (arduinoLine.find(
"mode") == std::string::npos)
108 getline(arduinoIn, arduinoLine,
'\n');
111 arduinoOut <<
"calibrate";
114 while (arduinoLine.find(
"Calibration Sucessfull") == std::string::npos)
116 getline(arduinoIn, arduinoLine,
'\n');
119 getline(arduinoIn, arduinoLine,
'\n');
120 if (getCalibrationValues(arduinoLine))
130 if (loadCalibration())
164OrientedTactileSensorUnit::run()
166 while (readTask->isRunning())
169 getline(arduinoIn, line,
'\n');
171 IceUtil::Time now = IceUtil::Time::now();
175 float rotationRate = 0;
178 if ((pow(
data.qw, 2) + pow(
data.qx, 2) + pow(
data.qy, 2) + pow(
data.qz, 2)) != 0)
180 RotationRate sampleRotation;
181 sampleRotation.timestamp = now;
184 if (0 < maxSamplesRotation &&
185 samplesRotation.size() <
static_cast<std::size_t
>(maxSamplesRotation))
187 samplesRotation.push_back(sampleRotation);
191 samplesRotation[sampleIndexRotation].timestamp = sampleRotation.timestamp;
192 samplesRotation[sampleIndexRotation].orientation = sampleRotation.orientation;
193 sampleIndexRotation = (sampleIndexRotation + 1) % maxSamplesRotation;
194 RotationRate oldsampleRotation;
195 oldsampleRotation.timestamp = samplesRotation.at(sampleIndexRotation).timestamp;
196 oldsampleRotation.orientation = samplesRotation.at(sampleIndexRotation).orientation;
197 Eigen::AngleAxisf aa(sampleRotation.orientation *
198 oldsampleRotation.orientation.inverse());
202 (sampleRotation.timestamp - oldsampleRotation.timestamp).toSecondsDouble();
206 float pressureRate = 0;
209 samplePressure.pressure =
data.pressure;
210 if (0 < maxSamplesPressure &&
211 samplesPressure.size() <
static_cast<std::size_t
>(maxSamplesPressure))
213 samplesPressure.push_back(samplePressure);
217 samplesPressure[sampleIndexPressure] = samplePressure;
218 sampleIndexPressure = (sampleIndexPressure + 1) % maxSamplesPressure;
220 oldsamplePressure.
timestamp = samplesPressure.at(sampleIndexPressure).timestamp;
221 oldsamplePressure.pressure = samplesPressure.at(sampleIndexPressure).pressure;
223 (samplePressure.pressure - oldsamplePressure.pressure) /
224 (samplePressure.timestamp - oldsamplePressure.timestamp).toSecondsDouble();
228 float accelerationRate = 0;
231 sampleAcceleration.rotationRate = rotationRate;
232 if (0 < maxSamplesAcceleration &&
233 samplesAcceleration.size() <
static_cast<std::size_t
>(maxSamplesAcceleration))
235 samplesAcceleration.push_back(sampleAcceleration);
239 samplesAcceleration[sampleIndexAcceleration] = sampleAcceleration;
240 sampleIndexAcceleration = (sampleIndexAcceleration + 1) % maxSamplesAcceleration;
243 samplesAcceleration.at(sampleIndexAcceleration).timestamp;
244 oldsampleAcceleration.rotationRate =
245 samplesAcceleration.at(sampleIndexAcceleration).rotationRate;
247 (sampleAcceleration.rotationRate - oldsampleAcceleration.rotationRate) /
248 (sampleAcceleration.timestamp - oldsampleAcceleration.timestamp).toSecondsDouble();
250 if (0 < maxSamplesPressure &&
251 pressureRates.size() <
static_cast<std::size_t
>(maxSamplesPressure))
253 pressureRates.push_back(pressureRate);
257 pressureRates[sampleIndexPressureRate] = pressureRate;
258 sampleIndexPressureRate = (sampleIndexPressureRate + 1) % maxSamplesPressure;
260 if (pressureRate > 50)
272 inverseOrientation = orientationQuaternion.inverse();
275 Eigen::Matrix3f quatMatrix = orientationQuaternion.toRotationMatrix();
276 Eigen::Matrix4f quat4Matrix = Eigen::Matrix4f::Identity();
278 quat4Matrix.block(0, 0, 3, 3) = quatMatrix;
280 Eigen::Vector3f linearAcceleration(
data.accelx,
data.accely,
data.accelz);
281 SimpleJsonLoggerEntry e;
283 e.
Add(
"Pressure",
data.pressure);
284 e.
Add(
"PressureRate", pressureRate);
285 e.
Add(
"RotationRate", rotationRate);
286 e.
AddAsArr(
"Orientation", quat4Matrix);
287 e.
AddAsArr(
"Linear Acceleration", linearAcceleration);
310 Eigen::Matrix3f rotY;
320 Eigen::Matrix3f rawOrientation = orientationQuaternion.toRotationMatrix();
322 PosePtr pose =
new Pose(rawOrientation, Eigen::Vector3f(100.0, 200.0, 0.0));
323 if (debugDrawerTopic)
325 debugDrawerTopic->setPoseVisu(
"debugdrawerlayer",
"pose", pose);
328 data.qw = quaternion.w();
329 data.qx = quaternion.x();
330 data.qy = quaternion.y();
331 data.qz = quaternion.z();
332 ARMARX_IMPORTANT <<
"or " << orientationQuaternion.w() <<
" " << orientationQuaternion.x()
333 <<
" " << orientationQuaternion.y() <<
" " << orientationQuaternion.z();
336 topicPrx->reportSensorValues(
data.id,
355OrientedTactileSensorUnit::getValues(std::string line)
358 std::vector<std::string> splitValues =
Split(line,
" ");
359 data.id = stoi(splitValues.at(0));
360 data.pressure = std::stof(splitValues.at(1));
361 data.qw = std::stof(splitValues.at(2));
362 data.qx = std::stof(splitValues.at(3));
363 data.qy = std::stof(splitValues.at(4));
364 data.qz = std::stof(splitValues.at(5));
365 data.accelx = std::stof(splitValues.at(6));
366 data.accely = std::stof(splitValues.at(7));
367 data.accelz = std::stof(splitValues.at(8));
374OrientedTactileSensorUnit::loadCalibration()
377 std::string arduinoLine;
378 while (arduinoLine.find(
"mode") == std::string::npos)
380 getline(arduinoIn, arduinoLine,
'\n');
382 arduinoOut <<
"load";
384 while (arduinoLine.find(
"calibration data") == std::string::npos)
386 getline(arduinoIn, arduinoLine,
'\n');
389 arduinoOut << calibrationStream;
392 while (arduinoLine.find(
"Calibration Sucessfull") == std::string::npos)
394 getline(arduinoIn, arduinoLine,
'\n');
400OrientedTactileSensorUnit::getCalibrationValues(std::string line)
402 std::vector<std::string> splitValues =
Split(line,
" ");
403 calibration.accel_offset_x = stoi(splitValues.at(0));
404 calibration.accel_offset_y = stoi(splitValues.at(1));
405 calibration.accel_offset_z = stoi(splitValues.at(2));
406 calibration.gyro_offset_x = stoi(splitValues.at(3));
407 calibration.gyro_offset_y = stoi(splitValues.at(4));
408 calibration.gyro_offset_z = stoi(splitValues.at(5));
409 calibration.mag_offset_x = stoi(splitValues.at(6));
410 calibration.mag_offset_y = stoi(splitValues.at(7));
411 calibration.mag_offset_z = stoi(splitValues.at(8));
412 calibration.accel_radius = stoi(splitValues.at(9));
413 calibration.mag_radius = stoi(splitValues.at(10));
414 std::string
space =
" ";
415 std::string calibrationStream =
"";
417 calibrationStream +
to_string(calibration.accel_offset_x) +
space +
The CMakePackageFinder class provides an interface to the CMake Package finder capabilities.
std::string getDataDir() const
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
TopicProxyType getTopic(const std::string &name)
Returns a proxy of the specified topic.
void onInitComponent() override
Pure virtual hook for the subclass.
void onConnectComponent() override
Pure virtual hook for the subclass.
PropertyDefinitionsPtr createPropertyDefinitions() override
OrientedTactileSensorUnit()
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
void Add(const std::string &key, const std::string &value)
void AddAsArr(const std::string &key, const Eigen::Vector3f &vec)
Implements a Variant type for timestamps.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Quaternion< float, 0 > Quaternionf
StringVariantContainerBaseMap getValues(const StateParameterMap ¶mMap)
T getValue(nlohmann::json &userConfig, nlohmann::json &defaultConfig, const std::string &entryName)
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
IceInternal::Handle< Pose > PosePtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
const std::string & to_string(const std::string &s)
IceInternal::Handle< TimestampVariant > TimestampVariantPtr