Skip to content

Commit

Permalink
Fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
martinaxgloria committed Jan 18, 2024
1 parent f84f45e commit 03c32b2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 41 deletions.
18 changes: 8 additions & 10 deletions src/imu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
cmake_minimum_required(VERSION 3.5)
project(imu)
if(NOT DEFINED CMAKE_MINIMUM_REQUIRED_VERSION)
cmake_minimum_required(VERSION 3.5)
endif()

This comment has been minimized.

Copy link
@traversaro

traversaro Jan 18, 2024

Member

I think we can remove this. There is no project and find_package call in this script, so this CMakeLists.txt will never be called on its own, and always added via add_subdirectory by an higher folder, so it is not really useful to have this code.

This comment has been minimized.

Copy link
@traversaro

traversaro Jan 18, 2024

Member

This comment has been minimized.

Copy link
@martinaxgloria

martinaxgloria Jan 18, 2024

Author Contributor

Ok, I will remove it and the change will be added in the next PR. Thanks a lot!

This comment has been minimized.

Copy link
@traversaro

traversaro Jan 18, 2024

Member

Thanks!

This comment has been minimized.

Copy link
@traversaro

traversaro Jan 18, 2024

Member

Ah, I see that also that is just everywhere in the repo, now I get it why you put it.

This comment has been minimized.

Copy link
@traversaro

traversaro Jan 18, 2024

Member

And actually I was the one approving its use: #45 . Ok, now I get more about this to understand why it does not make sense.


add_definitions(-D_USE_MATH_DEFINES)

include_directories(${CMAKE_SOURCE_DIR}
${RobotTestingFramework_INCLUDE_DIRS})

robottestingframework_add_plugin(${PROJECT_NAME} HEADERS ${PROJECT_NAME}.h
SOURCES ${PROJECT_NAME}.cpp)
robottestingframework_add_plugin(imu HEADERS imu.h
SOURCES imu.cpp)

# add required libraries
target_link_libraries(${PROJECT_NAME} RobotTestingFramework::RTF
target_link_libraries(imu RobotTestingFramework::RTF
RobotTestingFramework::RTF_dll
YARP::YARP_robottestingframework
iDynTree::idyntree-high-level
iDynTree::idyntree-estimation)
# set the installation options
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}
install(TARGETS imu
EXPORT imu
COMPONENT runtime
LIBRARY DESTINATION lib)
42 changes: 18 additions & 24 deletions src/imu/imu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <yarp/os/Property.h>
#include <yarp/os/Stamp.h>
#include <yarp/os/ResourceFinder.h>

#include "imu.h"

Expand All @@ -27,19 +28,21 @@ bool Imu::setup(yarp::os::Property& property) {

robotName = property.find("robot").asString(); // robot name
portName = property.find("port").asString(); // name of the port from which the data are streamed
modelPath = property.find("model").asString(); // urdf model path
frameName = property.find("frame").asString(); // frame on which the sensor is attached
sensorName = property.find("sensor").asString(); // sensor name within urdf
modelName = property.find("model").asString(); // urdf model path
yarp::os::ResourceFinder &rf = yarp::os::ResourceFinder::getResourceFinderSingleton();
std::string modelAbsolutePath = rf.findFileByName(modelName);

ROBOTTESTINGFRAMEWORK_TEST_REPORT("Running IMU test on "+robotName+"...");

yarp::os::Property MASclientOptions;
MASclientOptions.put("device", "multipleanalogsensorsclient");
MASclientOptions.put("remote", portName);
MASclientOptions.put("local", "/imuTest/"+portName);
MASclientDriver = new yarp::dev::PolyDriver(MASclientOptions);


ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(MASclientDriver.open(MASclientOptions), "Unable to open the MAS client driver");
yarp::os::Property controlBoardOptions;
controlBoardOptions.put("device", "remotecontrolboardremapper");
yarp::os::Bottle axesNames;
Expand Down Expand Up @@ -70,15 +73,15 @@ bool Imu::setup(yarp::os::Property& property) {
controlBoardOptions.put("remoteControlBoards", remoteControlBoards.get(0));
controlBoardOptions.put("localPortPrefix", "/test");

controlBoardDriver = new yarp::dev::PolyDriver(controlBoardOptions);
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(MASclientDriver->isValid(), "Device driver cannot be opened");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(MASclientDriver->view(iorientation), "Unable to open orientation interface");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver->isValid(), "Device driver cannot be opened");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver->view(ipos), "Unable to open position control interface");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver->view(ienc), "Unable to open encoder interface");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver->view(iaxes), "Unable to open axes interface");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver->view(ilim), "Unable to open limits interface");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.open(controlBoardOptions), "Unable to open the controlBoard driver");

ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(MASclientDriver.isValid(), "Device driver cannot be opened");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(MASclientDriver.view(iorientation), "Unable to open orientation interface");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.isValid(), "Device driver cannot be opened");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.view(ipos), "Unable to open position control interface");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.view(ienc), "Unable to open encoder interface");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.view(iaxes), "Unable to open axes interface");
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(controlBoardDriver.view(ilim), "Unable to open limits interface");

outputPort.open("/test-imu/out");
ROBOTTESTINGFRAMEWORK_TEST_REPORT("Opening port "+outputPort.getName()+"...");
Expand All @@ -93,7 +96,7 @@ bool Imu::setup(yarp::os::Property& property) {
axis.push_back(axisName);
}

ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(model.loadReducedModelFromFile(modelPath.c_str(), axis), Asserter::format("Cannot load model %s", modelPath.c_str()));
ROBOTTESTINGFRAMEWORK_ASSERT_ERROR_IF_FALSE(model.loadReducedModelFromFile(modelAbsolutePath.c_str(), axis), Asserter::format("Cannot load model from %s", modelAbsolutePath.c_str()));
kinDynComp.loadRobotModel(model.model());

iDynTree::Vector3 baseLinkOrientationRad;
Expand Down Expand Up @@ -136,17 +139,8 @@ void Imu::tearDown() {
outputPort.interrupt();
outputPort.close();

if(MASclientDriver)
{
delete MASclientDriver;
MASclientDriver = 0;
}

if(controlBoardDriver)
{
delete controlBoardDriver;
controlBoardDriver = 0;
}
controlBoardDriver.close();
MASclientDriver.close();
}

void Imu::run() {
Expand Down
12 changes: 6 additions & 6 deletions src/imu/imu.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _IMU_H_
#define _IMU_H_
#ifndef IMU_H
#define IMU_H

#include <yarp/dev/PolyDriver.h>
#include <yarp/dev/MultipleAnalogSensorsInterfaces.h>
Expand All @@ -24,12 +24,12 @@ class Imu : public yarp::robottestingframework::TestCase {
private:
std::string robotName;
std::string portName;
std::string modelPath;
std::string modelName;
std::string frameName;
std::string sensorName;

yarp::dev::PolyDriver *MASclientDriver;
yarp::dev::PolyDriver *controlBoardDriver;
yarp::dev::PolyDriver MASclientDriver;
yarp::dev::PolyDriver controlBoardDriver;
yarp::dev::IOrientationSensors* iorientation;
yarp::dev::IPositionControl* ipos;
yarp::dev::IEncoders* ienc;
Expand Down Expand Up @@ -59,4 +59,4 @@ class Imu : public yarp::robottestingframework::TestCase {
bool moveJoint(int ax, double pos);
};

#endif //_IMU_H_
#endif //IMU_H
2 changes: 1 addition & 1 deletion suites/contexts/icub/test_imu.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
robot ${robotname}
model /path/to/your/robot/model.urdf
model model.urdf
port /${robotname}/head/inertials
sensor head_imu_0
frame head_imu_0

0 comments on commit 03c32b2

Please sign in to comment.