From bbbb67f88e4340c875aae56d0d6d1bf70a626d81 Mon Sep 17 00:00:00 2001 From: jkerpe Date: Fri, 6 Oct 2023 10:25:15 +0200 Subject: [PATCH] corrected proto file --- lib/HALSim/IMU.cpp | 22 +++++++++---------- lib/HALSim/IMU.h | 6 +++--- lib/RemoteControl/App.cpp | 41 ++++++++++++++++++------------------ lib/RemoteControl/App.h | 11 ++++++---- webots/protos/Zumo32U4.proto | 8 +------ 5 files changed, 43 insertions(+), 45 deletions(-) diff --git a/lib/HALSim/IMU.cpp b/lib/HALSim/IMU.cpp index 6f467e2c..730fb9f8 100644 --- a/lib/HALSim/IMU.cpp +++ b/lib/HALSim/IMU.cpp @@ -27,7 +27,7 @@ * @brief IMU implementation * @author Juliane Kerpe * - * @addtogroup HALInterfaces + * @addtogroup HALSim * * @{ */ @@ -66,20 +66,20 @@ void IMU::init() { for (uint8_t axisIndex = 0; axisIndex < NUMBER_OF_AXIS; ++axisIndex) { - - m_accelerationValues[axisIndex] = 0.0; - m_gyroValue = 0.0; - + m_accelerationValues[axisIndex] = 0.0; } + m_gyroValue = 0.0; m_accelerometer->enable(m_samplingPeriod); m_gyro->enable(m_samplingPeriod); - std::cout << "accel an"<< std::endl; + //std::cout << "IMU.cpp: Turned on IMU."<< std::endl; } void IMU::calibrate() { + // to do: implement m_sensorCalibStarted = true; + m_sensorCalibSuccessful = true; } @@ -93,9 +93,8 @@ const double* IMU::getAccelerometerValues() m_accelerationValues[axisIndex] = accelerationValues[axisIndex]; } } - //if (abs(m_accelerationValues[0])>0.1 || abs(m_accelerationValues[1])>0.1){ - std::cout<<"Accelerometer.cpp: ACCEL: x = " << m_accelerationValues[0]<< "; y = "< axisIdx) - { - Util::doubleToByteArray(&payload[axisIdx * sizeof(double)], sizeof(double), - accelerationValues[axisIdx]); + uint8_t payload[numberOfValues * sizeof(double)]; - ++axisIdx; - } + const double* accelerationValues = imu.getAccelerometerValues(); + const double gyrovalue = imu.getGyroValue(); + + /** First index: acceleration value in x-direction --> index 0 + * Second index: acceleration value in y-direction --> index 1 + * Third index: turning rate around z-axis --> index 2 + */ + Util::doubleToByteArray(&payload[0 * sizeof(double)], sizeof(double), accelerationValues[0]); + Util::doubleToByteArray(&payload[1 * sizeof(double)], sizeof(double), accelerationValues[1]); + Util::doubleToByteArray(&payload[2 * sizeof(double)], sizeof(double), gyrovalue); (void)m_smpServer.sendData(m_smpChannelIdAccelerometer, payload, sizeof(payload)); } diff --git a/lib/RemoteControl/App.h b/lib/RemoteControl/App.h index 9f839420..f25b38ba 100644 --- a/lib/RemoteControl/App.h +++ b/lib/RemoteControl/App.h @@ -112,8 +112,8 @@ class App /** SerialMuxProt channel name for sending line sensors data. */ static const char* CH_NAME_LINE_SENSORS; - /** SerialMuxProt channel name for sending line sensors data. */ - static const char* CH_NAME_ACCELEROMETER; + /** SerialMuxProt channel name for sending IMU data. */ + static const char* CH_NAME_IMU; /** The system state machine. */ StateMachine m_systemStateMachine; @@ -158,9 +158,12 @@ class App void sendLineSensorsData() const; /** - * Send acceleration data via SerialMuxProt. + * Send IMU data via SerialMuxProt. + * First index: acceleration value in x-direction --> index 0 + * Second index: acceleration value in y-direction --> index 1 + * Third index: turning rate around z-axis --> index 2 */ - void sendAccelerometerData() const; + void sendIMUData() const; }; /****************************************************************************** diff --git a/webots/protos/Zumo32U4.proto b/webots/protos/Zumo32U4.proto index 786b3249..1548fedd 100644 --- a/webots/protos/Zumo32U4.proto +++ b/webots/protos/Zumo32U4.proto @@ -446,16 +446,10 @@ PROTO Zumo32U4 [ children [ Accelerometer { name "accelerometer" - lookupTable [ - 0 0 0 - 0.1 0.1 0 - 1 1 0 - 2 2 0 - ] xAxis TRUE yAxis TRUE zAxis TRUE - resolution -1 + resolution 0.01 } Gyro { name "gyro"