OrientedTactileSensorUnit.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <RobotAPI/interface/units/UnitInterface.h>
5 #include <RobotAPI/interface/units/OrientedTactileSensorUnit.h>
8 #include <netinet/in.h>
9 #include <iostream>
10 #include <fstream>
11 #include <stdio.h>
12 #include <Eigen/Dense>
14 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
15 
16 namespace armarx
17 {
20  {
21  public:
24  {
25  defineOptionalProperty<std::string>(
26  "SerialInterfaceDevice",
27  "/dev/ttyACM0",
28  "The serial device the arduino is connected to.");
29 
30  defineOptionalProperty<std::string>(
31  "TopicName",
32  "OrientedTactileSensorValues",
33  "Name of the topic on which the sensor values are provided");
34 
35  defineOptionalProperty<std::string>(
36  "CalibrationData",
37  "65524 3 12 65534 65534 1 1208 119 58726 1000 943 ",
38  "Sensor Register Data to calibrate the sensor");
39 
40  defineOptionalProperty<std::string>(
41  "SamplesRotation",
42  "20",
43  "number of orientation values to differentiate");
44 
45  defineOptionalProperty<std::string>(
46  "SamplesPressure",
47  "10",
48  "number of pressure values to differentiate");
49 
50  defineOptionalProperty<std::string>(
51  "SamplesAcceleration",
52  "20",
53  "number of pressure values to differentiate");
54 
55  defineOptionalProperty<bool>(
56  "logData",
57  "false",
58  "log data from sensor");
59  defineOptionalProperty<bool>(
60  "calibrateSensor",
61  "false"
62  "Set true to calibrate the sensor and get calibration data and false to use existent calibration data");
63  defineOptionalProperty<std::string>("DebugDrawerTopicName", "DebugDrawerUpdates", "Name of the debug drawer topic that should be used");
64  }
65  };
66 
67  /**
68  * @class OrientedTactileSensorUnit
69  * @brief ArmarX wrapper for an arduino due with one BNO055 IMU and one BMP280 pressure sensor
70  *
71  */
73  virtual public armarx::Component
74  //TODO: needs interface to send calibration data
75  {
76  public:
78 
79  std::string getDefaultName() const override
80  {
81  return "OrientedTactileSensorUnit";
82  }
83 
84  struct SensorData
85  {
86  int id;
87  float pressure;
88  float qw, qx, qy, qz;
89  float accelx, accely, accelz;
90  };
91 
93  {
95  };
96 
97  struct PressureRate
98  {
100  float pressure;
101  };
102 
104  {
107  };
108 
110  {
113  };
114  struct LinAccRate
115  {
117  float accx, accy, accz;
118  };
119 
120  protected:
121  void onInitComponent() override;
122  void onConnectComponent() override;
123 
125 
126  private:
127  std::ifstream arduinoIn;
128  std::ofstream arduinoOut;
130  OrientedTactileSensorUnitListenerPrx topicPrx;
131  OrientedTactileSensorUnitInterfacePrx interfacePrx;
132 
133  void run();
134  SensorData getValues(std::string line);
135  bool getCalibrationValues(std::string line);
136  bool loadCalibration();
137  int fd;
138  CalibrationData calibration;
139 
140  Eigen::Quaternionf inverseOrientation;
141  std::vector<RotationRate> samplesRotation;
142  std::vector<PressureRate> samplesPressure;
143  std::vector<AccelerationRate> samplesAcceleration;
144  std::vector<float> pressureRates;
145  //Eigen::AngleAxisf aa;
146  int maxSamplesRotation;
147  int sampleIndexRotation;
148  int maxSamplesPressure;
149  int sampleIndexPressure;
150  int maxSamplesAcceleration;
151  int sampleIndexAcceleration;
152  int sampleIndexPressureRate;
153  float sumPressureRates;
154  Eigen::Matrix3f sumOrientation;
155  bool first;
156  int i = 0;
157  DebugDrawerInterfacePrx debugDrawerTopic;
158  SimpleJsonLoggerPtr logger;
159  std::string prefix;
160  };
161 }
armarx::OrientedTactileSensorUnit::SensorData::accelz
float accelz
Definition: OrientedTactileSensorUnit.h:89
armarx::OrientedTactileSensorUnit::CalibrationData::gyro_offset_y
int gyro_offset_y
Definition: OrientedTactileSensorUnit.h:94
armarx::OrientedTactileSensorUnitPropertyDefinitions
Definition: OrientedTactileSensorUnit.h:18
armarx::OrientedTactileSensorUnit::RotationRate
Definition: OrientedTactileSensorUnit.h:103
armarx::OrientedTactileSensorUnit::LinAccRate::accx
float accx
Definition: OrientedTactileSensorUnit.h:117
armarx::OrientedTactileSensorUnit::CalibrationData::accel_offset_x
int accel_offset_x
Definition: OrientedTactileSensorUnit.h:94
armarx::OrientedTactileSensorUnit::AccelerationRate::rotationRate
float rotationRate
Definition: OrientedTactileSensorUnit.h:112
armarx::OrientedTactileSensorUnit::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: OrientedTactileSensorUnit.cpp:147
armarx::OrientedTactileSensorUnit::AccelerationRate::timestamp
IceUtil::Time timestamp
Definition: OrientedTactileSensorUnit.h:111
armarx::OrientedTactileSensorUnit::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: OrientedTactileSensorUnit.cpp:23
armarx::OrientedTactileSensorUnit::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: OrientedTactileSensorUnit.cpp:140
SimpleJsonLogger.h
armarx::OrientedTactileSensorUnit::OrientedTactileSensorUnit
OrientedTactileSensorUnit()
Definition: OrientedTactileSensorUnit.cpp:14
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
PeriodicTask.h
armarx::OrientedTactileSensorUnit::SensorData::qy
float qy
Definition: OrientedTactileSensorUnit.h:88
armarx::OrientedTactileSensorUnit::RotationRate::timestamp
IceUtil::Time timestamp
Definition: OrientedTactileSensorUnit.h:105
armarx::OrientedTactileSensorUnit
ArmarX wrapper for an arduino due with one BNO055 IMU and one BMP280 pressure sensor.
Definition: OrientedTactileSensorUnit.h:72
RunningTask.h
armarx::SimpleJsonLoggerPtr
std::shared_ptr< SimpleJsonLogger > SimpleJsonLoggerPtr
Definition: SimpleJsonLogger.h:40
armarx::OrientedTactileSensorUnit::CalibrationData::mag_radius
int mag_radius
Definition: OrientedTactileSensorUnit.h:94
armarx::OrientedTactileSensorUnit::CalibrationData::gyro_offset_x
int gyro_offset_x
Definition: OrientedTactileSensorUnit.h:94
armarx::OrientedTactileSensorUnit::CalibrationData::mag_offset_z
int mag_offset_z
Definition: OrientedTactileSensorUnit.h:94
armarx::OrientedTactileSensorUnit::SensorData::qx
float qx
Definition: OrientedTactileSensorUnit.h:88
armarx::OrientedTactileSensorUnit::PressureRate::pressure
float pressure
Definition: OrientedTactileSensorUnit.h:100
armarx::OrientedTactileSensorUnit::CalibrationData::mag_offset_x
int mag_offset_x
Definition: OrientedTactileSensorUnit.h:94
armarx::OrientedTactileSensorUnit::SensorData::qw
float qw
Definition: OrientedTactileSensorUnit.h:88
armarx::OrientedTactileSensorUnit::LinAccRate::accz
float accz
Definition: OrientedTactileSensorUnit.h:117
armarx::OrientedTactileSensorUnit::AccelerationRate
Definition: OrientedTactileSensorUnit.h:109
armarx::OrientedTactileSensorUnit::SensorData::id
int id
Definition: OrientedTactileSensorUnit.h:86
armarx::OrientedTactileSensorUnit::CalibrationData::accel_offset_z
int accel_offset_z
Definition: OrientedTactileSensorUnit.h:94
armarx::OrientedTactileSensorUnit::LinAccRate
Definition: OrientedTactileSensorUnit.h:114
armarx::OrientedTactileSensorUnit::SensorData::accelx
float accelx
Definition: OrientedTactileSensorUnit.h:89
armarx::OrientedTactileSensorUnit::SensorData::pressure
float pressure
Definition: OrientedTactileSensorUnit.h:87
armarx::OrientedTactileSensorUnit::CalibrationData::gyro_offset_z
int gyro_offset_z
Definition: OrientedTactileSensorUnit.h:94
armarx::OrientedTactileSensorUnit::CalibrationData::mag_offset_y
int mag_offset_y
Definition: OrientedTactileSensorUnit.h:94
armarx::OrientedTactileSensorUnit::SensorData::qz
float qz
Definition: OrientedTactileSensorUnit.h:88
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::OrientedTactileSensorUnit::PressureRate::timestamp
IceUtil::Time timestamp
Definition: OrientedTactileSensorUnit.h:99
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::OrientedTactileSensorUnit::RotationRate::orientation
Eigen::Quaternionf orientation
Definition: OrientedTactileSensorUnit.h:106
armarx::OrientedTactileSensorUnit::CalibrationData::accel_offset_y
int accel_offset_y
Definition: OrientedTactileSensorUnit.h:94
armarx::OrientedTactileSensorUnit::CalibrationData::accel_radius
int accel_radius
Definition: OrientedTactileSensorUnit.h:94
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::Quaternion< float, 0 >
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::DebugDrawerInterface >
armarx::OrientedTactileSensorUnit::PressureRate
Definition: OrientedTactileSensorUnit.h:97
armarx::OrientedTactileSensorUnit::LinAccRate::accy
float accy
Definition: OrientedTactileSensorUnit.h:117
armarx::OrientedTactileSensorUnit::SensorData::accely
float accely
Definition: OrientedTactileSensorUnit.h:89
armarx::OrientedTactileSensorUnitPropertyDefinitions::OrientedTactileSensorUnitPropertyDefinitions
OrientedTactileSensorUnitPropertyDefinitions(std::string prefix)
Definition: OrientedTactileSensorUnit.h:22
armarx::OrientedTactileSensorUnit::LinAccRate::timestamp
IceUtil::Time timestamp
Definition: OrientedTactileSensorUnit.h:116
armarx::OrientedTactileSensorUnit::SensorData
Definition: OrientedTactileSensorUnit.h:84
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::OrientedTactileSensorUnit::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: OrientedTactileSensorUnit.h:79
armarx::OrientedTactileSensorUnit::CalibrationData
Definition: OrientedTactileSensorUnit.h:92