diff --git a/scenarios/OrientedTactileSensor/OrientedTactileSensor.scx b/scenarios/OrientedTactileSensor/OrientedTactileSensor.scx index 3d823be1c87cb0e97ffdc4ba4549a6fd5998fc75..33ed762a12a90ccfd774aec3d31e0d519de79dac 100644 --- a/scenarios/OrientedTactileSensor/OrientedTactileSensor.scx +++ b/scenarios/OrientedTactileSensor/OrientedTactileSensor.scx @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<scenario name="OrientedTactileSensor" lastChange="2017-03-09.19:07:21" creation="2017-02-27.01:48:55 PM" globalConfigName="./config/global.cfg" package="RobotAPI"> +<scenario name="OrientedTactileSensor" lastChange="2017-03-13.15:08:19" creation="2017-02-27.01:48:55 PM" globalConfigName="./config/global.cfg" package="RobotAPI"> <application name="OrientedTactileSensorUnitApp" instance="" package="RobotAPI"/> <application name="OrientedTactileSensorUnitObserverApp" instance="" package="RobotAPI"/> </scenario> diff --git a/scenarios/OrientedTactileSensor/config/OrientedTactileSensorUnitApp.cfg b/scenarios/OrientedTactileSensor/config/OrientedTactileSensorUnitApp.cfg index 14eba70f342c50478b72cb1ecb5b23f280aab6f4..1ec6764f36d51be5c6b8501bb6ef5e5046114c79 100644 --- a/scenarios/OrientedTactileSensor/config/OrientedTactileSensorUnitApp.cfg +++ b/scenarios/OrientedTactileSensor/config/OrientedTactileSensorUnitApp.cfg @@ -130,12 +130,12 @@ ArmarX.OrientedTactileSensorUnit.SamplesPressure = 20 ArmarX.OrientedTactileSensorUnit.SamplesRotation = 20 -# ArmarX.OrientedTactileSensorUnit.SerialInterfaceDevice: Custom Property +# ArmarX.OrientedTactileSensorUnit.SerialInterfaceDevice: The serial device the arduino is connected to. # Attributes: -# - Default: ::NOT_DEFINED:: +# - Default: /dev/ttyACM0 # - Case sensitivity: no # - Required: no -ArmarX.OrientedTactileSensorUnit.SerialInterfaceDevice = /dev/ttyACM3 +ArmarX.OrientedTactileSensorUnit.SerialInterfaceDevice = /dev/ttyACM0 # ArmarX.OrientedTactileSensorUnit.TopicName: Name of the topic on which the sensor values are provided diff --git a/source/RobotAPI/components/units/OrientedTactileSensorUnitObserver.cpp b/source/RobotAPI/components/units/OrientedTactileSensorUnitObserver.cpp index 906e90f79bb7593b36e23e985357c78076fc2512..7762139ad1d7ac849a06f111ecccd5982fe8bf7e 100644 --- a/source/RobotAPI/components/units/OrientedTactileSensorUnitObserver.cpp +++ b/source/RobotAPI/components/units/OrientedTactileSensorUnitObserver.cpp @@ -74,7 +74,7 @@ void OrientedTactileSensorUnitObserver::reportSensorValues(int id, float pressur offerOrUpdateDataField(channelName, "pressure", Variant(pressure), "current pressure"); QuaternionPtr orientationQuaternion = new Quaternion(qw, qx, qy, qz); - offerOrUpdateDataField(channelName, "orientation", orientationQuaternion, "current oriantation"); + offerOrUpdateDataField(channelName, "orientation", orientationQuaternion, "current orientation"); offerOrUpdateDataField(channelName, "rotationRate", Variant(rotationRate), "current rotationRate"); offerOrUpdateDataField(channelName, "pressureRate", Variant(pressureRate), "current pressureRate"); offerOrUpdateDataField(channelName, "accelerationRate", Variant(accelerationRate), "current accelerationRate"); diff --git a/source/RobotAPI/drivers/OrientedTactileSensor/OrientedTactileSensorUnit.cpp b/source/RobotAPI/drivers/OrientedTactileSensor/OrientedTactileSensorUnit.cpp index 858081e665f71f979fbfd9a27406f1922c936c52..d6a9429636e30a8fe95c1276da97f9ab915a3203 100644 --- a/source/RobotAPI/drivers/OrientedTactileSensor/OrientedTactileSensorUnit.cpp +++ b/source/RobotAPI/drivers/OrientedTactileSensor/OrientedTactileSensorUnit.cpp @@ -27,9 +27,10 @@ void OrientedTactileSensorUnit::onInitComponent() //open serial port std::string portname = getProperty<std::string>("SerialInterfaceDevice").getValue(); - arduino.open(getProperty<std::string>("SerialInterfaceDevice").getValue(), std::ios::in); + arduinoIn.open(getProperty<std::string>("SerialInterfaceDevice").getValue(), std::ios::in); + arduinoOut.open(getProperty<std::string>("SerialInterfaceDevice").getValue(), std::ios::out); - fd = open(portname.c_str(), O_RDONLY | O_NOCTTY); + fd = open(portname.c_str(), O_RDWR | O_NOCTTY); struct termios toptions; /* Get currently set options for the tty */ @@ -55,7 +56,7 @@ void OrientedTactileSensorUnit::onInitComponent() ARMARX_INFO << "opening device " << getProperty<std::string>("SerialInterfaceDevice").getValue(); - if (!arduino.is_open()) + if (!arduinoIn.is_open()) { throw LocalException("Cannot open Arduino on ") << getProperty<std::string>("SerialInterfaceDevice").getValue(); @@ -74,22 +75,18 @@ void OrientedTactileSensorUnit::onInitComponent() while (arduinoLine.find("mode") == std::string::npos) { - getline(arduino, arduinoLine, '\n'); + getline(arduinoIn, arduinoLine, '\n'); } - arduino.close(); - arduino.open(getProperty<std::string>("SerialInterfaceDevice").getValue(), std::ios::out); - arduino << "calibrate"; - arduino.flush(); - arduino.close(); + arduinoOut << "calibrate"; + arduinoOut.flush(); - arduino.open(getProperty<std::string>("SerialInterfaceDevice").getValue(), std::ios::in); while (arduinoLine.find("Calibration Sucessfull") == std::string::npos) { - getline(arduino, arduinoLine, '\n'); + getline(arduinoIn, arduinoLine, '\n'); ARMARX_INFO << arduinoLine; } - getline(arduino, arduinoLine, '\n'); + getline(arduinoIn, arduinoLine, '\n'); if (getCalibrationValues(arduinoLine)) { ARMARX_IMPORTANT << "calibrated sensor"; @@ -126,7 +123,7 @@ void OrientedTactileSensorUnit::run() while (readTask->isRunning()) { std::string line; - getline(arduino, line, '\n'); + getline(arduinoIn, line, '\n'); SensorData data = getValues(line.c_str()); IceUtil::Time now = IceUtil::Time::now(); TimestampVariantPtr nowTimestamp = new TimestampVariant(now); @@ -227,44 +224,24 @@ OrientedTactileSensorUnit::SensorData OrientedTactileSensorUnit::getValues(std:: std::string space = " "; bool OrientedTactileSensorUnit::loadCalibration() { - ARMARX_INFO << "loadCalibration started"; std::string calibrationStream = getProperty<std::string>("CalibrationData").getValue(); std::string arduinoLine; while (arduinoLine.find("mode") == std::string::npos) { - getline(arduino, arduinoLine, '\n'); - ARMARX_INFO << "ARDUINO: '" << arduinoLine << "'"; + getline(arduinoIn, arduinoLine, '\n'); } - arduino.close(); - - ARMARX_INFO << "opening arduino out mode"; - arduino.open(getProperty<std::string>("SerialInterfaceDevice").getValue(), std::ios::out); - arduino << "load"; - arduino.flush(); - arduino.close(); - - ARMARX_INFO << "opening arduino in mode"; - arduino.open(getProperty<std::string>("SerialInterfaceDevice").getValue(), std::ios::in); + arduinoOut << "load"; + arduinoOut.flush(); while (arduinoLine.find("calibration data") == std::string::npos) { - getline(arduino, arduinoLine, '\n'); - ARMARX_INFO << "ARDUINO: '" << arduinoLine << "'"; + getline(arduinoIn, arduinoLine, '\n'); } - arduino.close(); - - ARMARX_INFO << "opening arduino out mode"; - arduino.open(getProperty<std::string>("SerialInterfaceDevice").getValue(), std::ios::out); - arduino << calibrationStream; - arduino.flush(); - arduino.close(); - - ARMARX_INFO << "opening arduino in mode"; - arduino.open(getProperty<std::string>("SerialInterfaceDevice").getValue(), std::ios::in); + arduinoOut << calibrationStream; + arduinoOut.flush(); while (arduinoLine.find("Calibration Sucessfull") == std::string::npos) { - getline(arduino, arduinoLine, '\n'); - ARMARX_INFO << "ARDUINO: '" << arduinoLine << "'"; + getline(arduinoIn, arduinoLine, '\n'); } return true; } diff --git a/source/RobotAPI/drivers/OrientedTactileSensor/OrientedTactileSensorUnit.h b/source/RobotAPI/drivers/OrientedTactileSensor/OrientedTactileSensorUnit.h index 38aade6a48c0be4e9742ad789dcaf05413410f53..e0d0c79493e23fc02ed381e08d1d37c707e68697 100644 --- a/source/RobotAPI/drivers/OrientedTactileSensor/OrientedTactileSensorUnit.h +++ b/source/RobotAPI/drivers/OrientedTactileSensor/OrientedTactileSensorUnit.h @@ -119,7 +119,8 @@ namespace armarx virtual PropertyDefinitionsPtr createPropertyDefinitions(); private: - std::fstream arduino; + std::ifstream arduinoIn; + std::ofstream arduinoOut; RunningTask<OrientedTactileSensorUnit>::pointer_type readTask; OrientedTactileSensorUnitListenerPrx topicPrx; OrientedTactileSensorUnitInterfacePrx interfacePrx;