diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ae9310..171783f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,170 +1,169 @@ PROJECT(libOncilla C CXX) CMAKE_MINIMUM_REQUIRED(VERSION 2.6) SET(LIBNAME "oncilla") SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE) SET(LIBONCILLA_CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # CMake module path and modules FIND_PACKAGE(RSC REQUIRED) SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${RSC_CMAKE_MODULE_PATH}") MESSAGE(STATUS "RSC version: ${RSC_VERSION}") INCLUDE(CheckIncludeFileCXX) INCLUDE(InstallFilesRecursive) INCLUDE(EnableCoverageReport) INCLUDE(EnableSlocCount) INCLUDE(GenerateDoxygen) INCLUDE(GenerateCppcheck) FIND_PACKAGE(PkgConfig REQUIRED) SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # --- user options --- OPTION(BUILD_TESTS "Decide whether unit-tests are built" ON) OPTION(BUILD_EXAMPLES "Decide whether the examples are built" ON) OPTION(BUILD_DOCS "Decide whether the docygen documentation is built" OFF) # Dependencies FIND_PACKAGE(Threads REQUIRED) MESSAGE(STATUS "Threading library: ${CMAKE_THREAD_LIBS_INIT}") set(OLD_CXX_FLAGS ${CMAKE_CXX_FLAGS}) FIND_PACKAGE(NemoMath REQUIRED) MESSAGE(STATUS "NemoMath version: ${NemoMath_VERSION}") set(CMAKE_CXX_FLAGS ${OLD_CXX_FLAGS}) FIND_PACKAGE(RCI REQUIRED) MESSAGE(STATUS "RCI version: ${RCI_VERSION}") # --- global definitions --- SET(LIBONCILLA_NAME "${LIBNAME}") SET(DRIVER_TEST_NAME "${PROJECT_NAME}Tests") SET(DTO_TEST_NAME "${DRIVER_TEST_NAME}DTO") SET(LIBONCILLA_VERSION_MAJOR 0) SET(LIBONCILLA_VERSION_MINOR 2) SET(LIBONCILLA_VERSION_PATCH 0) SET(LIBONCILLA_VERSION_STRING "${LIBONCILLA_VERSION_MAJOR}.${LIBONCILLA_VERSION_MINOR}.${LIBONCILLA_VERSION_PATCH}") SET(LIBONCILLA_CMAKE_MODULE_PATH "share/cmake/Modules") SET(GTEST_DIR ${PROJECT_SOURCE_DIR}/3rdparty/gtest-1.5.0) SET(GTEST_INCLUDE_DIR ${GTEST_DIR}/include) SET(GMOCK_DIR ${PROJECT_SOURCE_DIR}/3rdparty/gmock-1.5.0) SET(GMOCK_INCLUDE_DIR ${GMOCK_DIR}/include) SET(GMOCK_LIBRARY_NAME "gmock") SET(OUTPUT_PATH ${PROJECT_BINARY_DIR}/build) SET(ARCHIVE_OUTPUT_PATH ${OUTPUT_PATH}) SET(LIBRARY_OUTPUT_PATH ${OUTPUT_PATH}) SET(EXECUTABLE_OUTPUT_PATH ${OUTPUT_PATH}) # --- dependency handling --- IF(BUILD_DOCS) FIND_PACKAGE(Doxygen) ENDIF() # Includes INCLUDE_DIRECTORIES(BEFORE src ${PROJECT_BINARY_DIR}/src) message(STATUS ${RSC_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(SYSTEM ${RCI_INCLUDE_DIRS} ${RSC_INCLUDE_DIRS} ${NemoMath_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${LIBRARIES_INCLUDE_DIRS}) #INCLUDE_DIRECTORIES(BEFORE SYSTEM ${PROTOBUF_INCLUDE_DIR} ${RST_INCLUDE_DIRS}) LINK_DIRECTORIES(${RCI_LIBRARY_DIR} ${LIBRARIES_LIBRARY_DIRS}) ADD_DEFINITIONS(${NEMOMATH_DEFINITIONS}) ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(cmake) IF(BUILD_TESTS) ADD_SUBDIRECTORY(test) - #ADD_SUBDIRECTORY(3rdparty) ENDIF() #IF(BUILD_EXAMPLES) # ADD_SUBDIRECTORY(examples) #ENDIF() # --- cmake config file --- SET(LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) IF(CMAKE_LINK_LIBRARY_SUFFIX) SET(LIB_SUFFIX ${CMAKE_LINK_LIBRARY_SUFFIX}) ENDIF() # --- pkgconfig file --- CONFIGURE_FILE(lib${LIBONCILLA_NAME}.pc.in ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBONCILLA_NAME}.pc @ONLY) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${LIBONCILLA_NAME}.pc DESTINATION lib/pkgconfig) # --- cmake config file --- SET(LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) IF(CMAKE_LINK_LIBRARY_SUFFIX) SET(LIB_SUFFIX ${CMAKE_LINK_LIBRARY_SUFFIX}) ENDIF() CONFIGURE_FILE(${CMAKE_PROJECT_NAME}Config.cmake.in ${CMAKE_PROJECT_NAME}Config.cmake @ONLY) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}Config.cmake DESTINATION share/lib${LIBNAME}) # --- documentation generation --- IF(BUILD_DOCS) IF(DOXYGEN_FOUND) SET(API_DIR "${CMAKE_BINARY_DIR}/doc") SET(SOURCE_DIR "${CMAKE_SOURCE_DIR}/src") SET(DOXYFILE "${CMAKE_BINARY_DIR}/Doxyfile") SET(WARNFILE "${CMAKE_BINARY_DIR}/doxygen-warn.log") CONFIGURE_FILE(Doxyfile.in ${DOXYFILE}) ADD_CUSTOM_COMMAND(OUTPUT ${API_DIR} DEPENDS ${DOXYFILE} COMMAND ${DOXYGEN_EXECUTABLE} ARGS ${DOXYFILE} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) ADD_CUSTOM_TARGET(doc DEPENDS ${API_DIR}) INSTALL(CODE "execute_process(COMMAND ${CMAKE_BUILD_TOOL} doc)") INSTALL(DIRECTORY ${API_DIR} DESTINATION share/lib${LIBNAME}) ENDIF() ENDIF(BUILD_DOCS) # --- coverage --- IF(BUILD_TESTS) ENABLE_COVERAGE_REPORT(TARGETS ${LIBONCILLA_NAME} TESTS ${DTO_TEST_NAME} ${INTEGRATED_TEST_NAME} FILTER "*3rdparty*" "*test/*") ENDIF(BUILD_TESTS) # --- sloccount --- ENABLE_SLOCCOUNT(FOLDERS src test examples) # --- cppcheck --- GENERATE_CPPCHECK(SOURCES src test examples "${CMAKE_CURRENT_BINARY_DIR}/src" "${CMAKE_CURRENT_BINARY_DIR}/test" "${CMAKE_CURRENT_BINARY_DIR}/examples" ENABLE_IDS style) # --- package --- INCLUDE(CheckLSBTypes) SET(CPACK_PACKAGE_VERSION_MAJOR ${LIBONCILLA_VERSION_MAJOR}) SET(CPACK_PACKAGE_VERSION_MINOR ${LIBONCILLA_VERSION_MINOR}) SET(CPACK_PACKAGE_VERSION_PATCH ${LIBONCILLA_VERSION_PATCH}) SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") SET(CPACK_PACKAGE_FILE_NAME ${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}_${LSB_CODENAME}_${LSB_PROCESSOR_ARCH}) SET(CPACK_GENERATOR "TGZ") SET(CPACK_PACKAGE_VENDOR "CoR-Lab Bielefeld University") IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") SET(CPACK_GENERATOR "${CPACK_GENERATOR};DEB") SET(CPACK_DEBIAN_PACKAGE_NAME "amarsi-liboncilla") SET(CPACK_DEBIAN_PACKAGE_VERSION ${LIBONCILLA_VERSION_MAJOR}.${LIBONCILLA_VERSION_MINOR}.${LIBONCILLA_VERSION_PATCH}) SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Arne Nordmann (anordman@cor-lab.uni-bielefeld.de)") SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION "AMARSi RCI representations of the AMARSi quadruped robot 'Oncilla'.") SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") SET(CPACK_DEBIAN_PACKAGE_SECTION "devel") SET(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) SET(CPACK_DEBIAN_PACKAGE_DEPENDS "amarsi-rci-all") SET(CPACK_DEBIAN_PACKAGE_SUGGESTS "cmake, cmake-data, doxygen, lcov, cppcheck, sloccount") ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") INCLUDE(CPack) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7c7598a..2a46fe5 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,41 +1,20 @@ -#INCLUDE_DIRECTORIES(BEFORE ${PROJECT_BINARY_DIR}/src) - set(SOURCES_LIST ) foreach(file ${SOURCES}) set(SOURCES_LIST "${SOURCES_LIST} ${file}") endforeach(file) -#LINK_DIRECTORIES(${PROJECT_BINARY_DIR}/src/${LIBNAME} ${CMAKE_INSTALL_PREFIX}/lib ${CMAKE_INSTALL_PREFIX}) - -SET(EXAMPLE1 "OncillaKneeOscillator") -ADD_EXECUTABLE(${EXAMPLE1} oscillator.cpp) SET(EXAMPLE2 "OncillaWalkOneLeg") ADD_EXECUTABLE(${EXAMPLE2} walkOneLeg.cpp) -SET(EXAMPLE3 "OncillaWalkFourLegs") -ADD_EXECUTABLE(${EXAMPLE3} walkFourLegs.cpp) -SET(EXAMPLE4 "OncillaAnglesPlot") -ADD_EXECUTABLE(${EXAMPLE4} anglesplot.cpp) -SET(EXAMPLE5 "OncillaPlotCollectedAngles") -ADD_EXECUTABLE(${EXAMPLE5} anglesstatusallplot.cpp) -SET(EXAMPLE6 "OncillaWalkFourLegs2") -ADD_EXECUTABLE(${EXAMPLE6} walkFourLegs2.cpp) - -include_directories(${WEBOTS_INCLUDE_CPP_DIR} ${PROJECT_SOURCE_DIR}/src) -target_link_libraries(${EXAMPLE1} ${LIBNAME}) target_link_libraries(${EXAMPLE2} ${LIBNAME}) -target_link_libraries(${EXAMPLE3} ${LIBNAME}) -target_link_libraries(${EXAMPLE4} ${LIBNAME}) -target_link_libraries(${EXAMPLE5} ${LIBNAME}) -target_link_libraries(${EXAMPLE6} ${LIBNAME}) if(MY_LINK_FLAGS) set(LINK_PROPERTIES LINK_FLAGS ${MY_LINK_FLAGS}) elseif(MY_LINK_FLAGS) set(LINK_PROPERTIES ) endif(MY_LINK_FLAGS) INSTALL(TARGETS ${EXAMPLE1} ${EXAMPLE2} ${EXAMPLE3} ${EXAMPLE4} ${EXAMPLE5} ${EXAMPLE6} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) diff --git a/examples/anglesplot.cpp b/examples/anglesplot.cpp deleted file mode 100644 index 729d0f5..0000000 --- a/examples/anglesplot.cpp +++ /dev/null @@ -1,139 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include -#include - -using namespace std; -using namespace boost; -namespace po = boost::program_options; - -using namespace rsc; -using namespace rsc::logging; - -using namespace rsb; -using namespace rsb::converter; -using namespace rst::converter::rci; - -using namespace cca; -using namespace cca::rci; -using namespace cca::rci::driver; - -static std::string lfhipscope = "/oncilla/status/nodes/angles/lfhip/"; -static std::string rfhipscope = "/oncilla/status/nodes/angles/rfhip/"; -static std::string lhhipscope = "/oncilla/status/nodes/angles/lhhip/"; -static std::string rhhipscope = "/oncilla/status/nodes/angles/rhhip/"; - -static std::string lfkneescope = "/oncilla/status/nodes/angles/lfknee/"; -static std::string rfkneescope = "/oncilla/status/nodes/angles/rfknee/"; -static std::string lhkneescope = "/oncilla/status/nodes/angles/lhknee/"; -static std::string rhkneescope = "/oncilla/status/nodes/angles/rhknee/"; - -static JointAnglesPtr lfhip = JointAngles::fromValue(0.0); -static JointAnglesPtr rfhip = JointAngles::fromValue(0.0); -static JointAnglesPtr lhhip = JointAngles::fromValue(0.0); -static JointAnglesPtr rhhip = JointAngles::fromValue(0.0); - -static JointAnglesPtr lfknee = JointAngles::fromValue(0.0); -static JointAnglesPtr rfknee = JointAngles::fromValue(0.0); -static JointAnglesPtr lhknee = JointAngles::fromValue(0.0); -static JointAnglesPtr rhknee = JointAngles::fromValue(0.0); - -static unsigned int ecount = 0; - -void inputCallback(EventPtr event) { - // ++ecount; - // if (ecount > 20) { - - JointAnglesPtr input = boost::static_pointer_cast( - event->getData()); - std::string eventstr = event->getScopePtr()->toString(); - if (eventstr.compare(lfhipscope) == 0) { - lfhip = input; - } else if (eventstr.compare(rfhipscope) == 0) { - rfhip = input; - } else if (eventstr.compare(lhhipscope) == 0) { - lhhip = input; - } else if (eventstr.compare(rhhipscope) == 0) { - rhhip = input; - } else if (eventstr.compare(lfkneescope) == 0) { - lfknee = input; - } else if (eventstr.compare(rfkneescope) == 0) { - rfknee = input; - } else if (eventstr.compare(lhkneescope) == 0) { - lhknee = input; - } else if (eventstr.compare(rhkneescope) == 0) { - rhknee = input; - } - - std::cout << "Angles<"; - std::cout.precision(3); - std::cout << lfhip->asDouble(0) << ", "; - std::cout << rfhip->asDouble(0) << ", "; - std::cout << lhhip->asDouble(0) << ", "; - std::cout << rhhip->asDouble(0) << "><"; - std::cout << lfknee->asDouble(0) << ", "; - std::cout << rfknee->asDouble(0) << ", "; - std::cout << lhknee->asDouble(0) << ", "; - std::cout << rhknee->asDouble(0) << ">"; - std::cout << std::endl; - - // ecount = 0; - // } -} - -int main() { - - /** - * Register converters for Joint Angles - */ - boost::shared_ptr converter( - new JointAnglesConverter()); - stringConverterRepository()->registerConverter(converter); - - // Participant configuration - rsb::ParticipantConfig config = - Factory::getInstance().getDefaultParticipantConfig(); - ParticipantConfig::Transport inprocess = config.getTransport("inprocess"); - inprocess.setEnabled(false); - config.addTransport(inprocess); - ParticipantConfig::Transport spread = config.getTransport("spread"); - spread.setEnabled(true); - config.addTransport(spread); - - LoggerFactory::getInstance().reconfigure(Logger::LEVEL_ERROR); - - /** - * Listening to JointAngles - */ - ListenerPtr listener = Factory::getInstance().createListener(Scope( - "/oncilla/status/nodes/angles"), config); - listener->addHandler(HandlerPtr(new EventFunctionHandler(bind( - &inputCallback, _1)))); - - std::cout << "Now listening to joint angles ..." << std::endl; - while (true) { - sleep(1); - } - - return EXIT_SUCCESS; -} diff --git a/examples/anglesstatusallplot.cpp b/examples/anglesstatusallplot.cpp deleted file mode 100644 index 57b71bf..0000000 --- a/examples/anglesstatusallplot.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include - -using namespace std; -using namespace boost; -namespace po = boost::program_options; - -using namespace rsc; -using namespace rsc::logging; - -using namespace rsb; -using namespace rsb::converter; -using namespace rst::converter::rci; - -using namespace cca; -using namespace cca::rci; -using namespace cca::rci::driver; - -nemo::RealVector angles(nemo::dim(8), 0.0); -static JointAnglesPtr angls = JointAnglesPtr(new JointAngles(angles)); - -void inputCallback(EventPtr event) { - - JointAnglesPtr input = boost::static_pointer_cast( - event->getData()); - - std::cout << *input << std::endl; -} - -int main() { - - /** - * Register converters for Joint Angles - */ - boost::shared_ptr converter( - new JointAnglesConverter()); - stringConverterRepository()->registerConverter(converter); - - LoggerFactory::getInstance().reconfigure(Logger::LEVEL_ERROR); - - // Participant configuration - rsb::ParticipantConfig config = - Factory::getInstance().getDefaultParticipantConfig(); - ParticipantConfig::Transport inprocess = config.getTransport("inprocess"); - inprocess.setEnabled(false); - config.addTransport(inprocess); - ParticipantConfig::Transport spread = config.getTransport("spread"); - spread.setEnabled(true); - config.addTransport(spread); - - /** - * Listening to JointAngles - */ - ListenerPtr listener = Factory::getInstance().createListener( - Scope("/oncilla/status/nodes/angles/all"), config); - listener->addHandler( - HandlerPtr(new EventFunctionHandler(bind(&inputCallback, _1)))); - - std::cout << "Now listening to joint angles ..." << std::endl; - while (true) { - sleep(1); - } - - return EXIT_SUCCESS; -} diff --git a/examples/oscillator.cpp b/examples/oscillator.cpp deleted file mode 100644 index 2415e79..0000000 --- a/examples/oscillator.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include - -using namespace std; -using namespace boost; -namespace po = boost::program_options; - -using namespace rsc; -using namespace rsc::logging; - -using namespace rsb; -using namespace rsb::converter; -using namespace rst::converter::rci; - -using namespace cca; -using namespace cca::rci; -using namespace cca::rci::driver; - -int main(int ac, char **av) { - double amplitude = 1.0; - double offset = 0.0; - unsigned int frequency = 1; - - LoggerFactory::getInstance().reconfigure(Logger::LEVEL_ERROR); - - // Declare the supported options. - po::options_description desc("Allowed options"); - desc.add_options()("help", "Produce help message")("frequency", - po::value(), "Frequency of oscillation in Hertz")("amplitude", - po::value(), "Amplitude of the sine")("offset", - po::value(), "Offset to the output value"); - po::variables_map vm; - po::store(po::parse_command_line(ac, av, desc), vm); - po::notify(vm); - if (vm.count("help")) { - cout << desc << "\n"; - return 1; - } - if (vm.count("frequency")) { - frequency = vm["frequency"].as (); - } - cout << "Frequency set to " << frequency << " Hertz.\n"; - if (vm.count("amplitude")) { - amplitude = vm["amplitude"].as (); - } - cout << "Amplitude set to " << amplitude << ".\n"; - if (vm.count("offset")) { - offset = vm["offset"].as (); - } - cout << "Offset set to " << offset << ".\n"; - - /** - * Register converters for Joint Angles - */ - boost::shared_ptr converter( - new JointAnglesConverter()); - stringConverterRepository()->registerConverter(converter); - - // Participant configuration - rsb::ParticipantConfig config = - Factory::getInstance().getDefaultParticipantConfig(); - ParticipantConfig::Transport inprocess = config.getTransport("inprocess"); - inprocess.setEnabled(false); - config.addTransport(inprocess); - ParticipantConfig::Transport spread = config.getTransport("spread"); - spread.setEnabled(true); - config.addTransport(spread); - - /** - * Setup the main beat - */ - GlobalBeatPtr heartbeat; - heartbeat = GlobalBeat::create(50); - - CCANodePtr oscillator = SimpleOscillator::create( - "Knee Oscillator", frequency, amplitude, offset); - oscillator->configureOutputPort(0, - PortConfiguration::REMOTE("/oncilla/command/nodes/angles/lhknee")); - - heartbeat->registerReceiver(oscillator); - - std::cout << "Oscillating between " << (offset - amplitude) << " and " - << (offset + amplitude) << " with " << frequency << " Hertz ..." - << std::endl; - heartbeat->run(); - - return EXIT_SUCCESS; -} diff --git a/examples/walkFourLegs.cpp b/examples/walkFourLegs.cpp deleted file mode 100644 index 195fcc2..0000000 --- a/examples/walkFourLegs.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include -#include -#include - -using namespace std; -using namespace boost; -using namespace boost::program_options; - -using namespace rsc; -using namespace rsc::logging; - -using namespace rsb; -using namespace rsb::converter; -using namespace rst::converter::rci; - -using namespace cca; -using namespace cca::rci; -using namespace cca::rci::driver; - -/** - * This example needs AMARSi controller "cca" - */ -int main(int ac, char **av) { - double cycletime = 50; - double amplitude = 0.5; - double offset = 0.0; - double frequency = 1; - - LoggerFactory::getInstance().reconfigure(Logger::LEVEL_ERROR); - - /** - * Command line handling - */ - options_description desc("Allowed options"); - desc.add_options()("help", "Produce help message")("frequency", - value (), "Frequency of oscillation in Hertz")("amplitude", - value (), "Amplitude of the sine")("offset", - value (), "Offset to the output value"); - variables_map vm; - store(parse_command_line(ac, av, desc), vm); - notify(vm); - if (vm.count("help")) { - cout << desc << "\n"; - return 1; - } - if (vm.count("frequency")) { - frequency = vm["frequency"].as (); - } - cout << "Frequency set to " << frequency << " Hertz.\n"; - if (vm.count("amplitude")) { - amplitude = vm["amplitude"].as (); - } - cout << "Amplitude set to " << amplitude << ".\n"; - if (vm.count("offset")) { - offset = vm["offset"].as (); - } - cout << "Offset set to " << offset << ".\n"; - - /** - * Register converters for Joint Angles - */ - boost::shared_ptr converter( - new JointAnglesConverter()); - stringConverterRepository()->registerConverter(converter); - - /** - * Setup the two oscillators - */ - CCANodePtr oscillator1 = SimpleOscillator::create( - "Oscillator 1", 2 * frequency, amplitude, offset); - oscillator1->configureOutputPort(0, - PortConfiguration::LOCAL("/oscillate/1")); - - CCANodePtr oscillator2 = SimpleOscillator::create( - "Oscillator 2", frequency, amplitude, offset, 0.5); - oscillator2->configureOutputPort(0, - PortConfiguration::LOCAL("/oscillate/2")); - - /** - * Set up two junctions - */ - CCANodePtr junction1 = Junction::create(4); - junction1->setProcessingStrategy(RestlessProcessing::create()); - CCANodePtr junction2 = Junction::create(4); - junction2->setProcessingStrategy(RestlessProcessing::create()); - - /** - * Connect oscillators to junction - */ - junction1->configureInputPort(0, PortConfiguration::LOCAL("/oscillate/1")); - junction1->configureOutputPort(0, - PortConfiguration::REMOTE("/oncilla/command/nodes/angles/lfhip")); - junction1->configureOutputPort(1, - PortConfiguration::REMOTE("/oncilla/command/nodes/angles/lhhip")); - junction1->configureOutputPort(2, - PortConfiguration::REMOTE("/oncilla/command/nodes/angles/lfknee")); - junction1->configureOutputPort(3, - PortConfiguration::REMOTE("/oncilla/command/nodes/angles/lhknee")); - - junction2->configureInputPort(0, PortConfiguration::LOCAL("/oscillate/2")); - junction2->configureOutputPort(0, - PortConfiguration::REMOTE("/oncilla/command/nodes/angles/rfhip")); - junction2->configureOutputPort(1, - PortConfiguration::REMOTE("/oncilla/command/nodes/angles/rhhip")); - junction2->configureOutputPort(2, - PortConfiguration::REMOTE("/oncilla/command/nodes/angles/rfknee")); - junction2->configureOutputPort(3, - PortConfiguration::REMOTE("/oncilla/command/nodes/angles/rhknee")); - - /** - * Setup and run main beat - */ - GlobalBeatPtr heartbeat; - heartbeat = GlobalBeat::create(cycletime); - heartbeat->registerReceiver(oscillator1); - heartbeat->registerReceiver(oscillator2); - std::cout << std::endl << "Two oscillators oscillating between " << (offset - - amplitude) << " and " << (offset + amplitude) << " with " - << frequency << " Hertz ..." << std::endl; - heartbeat->run(); - - return EXIT_SUCCESS; -} diff --git a/examples/walkFourLegs2.cpp b/examples/walkFourLegs2.cpp deleted file mode 100644 index c927286..0000000 --- a/examples/walkFourLegs2.cpp +++ /dev/null @@ -1,178 +0,0 @@ -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -using namespace std; -using namespace boost; -using namespace boost::program_options; - -using namespace rsc; -using namespace rsc::logging; - -using namespace rsb; -using namespace rsb::converter; -using namespace rst::converter::rci; - -using namespace cca; -using namespace cca::rci; -using namespace cca::rci::driver; - -/** - * This example needs AMARSi controller "cca2" - */ -int main(int ac, char **av) { - double cycletime = 10; - double amplitude = 0.5; - double offset = 0.0; - double frequency = 1; - - LoggerFactory::getInstance().reconfigure(Logger::LEVEL_ERROR); - - /** - * Command line handling - */ - options_description desc("Allowed options"); - desc.add_options()("help", "Produce help message")("frequency", - value (), "Frequency of oscillation in Hertz")("amplitude", - value (), "Amplitude of the sine")("offset", - value (), "Offset to the output value"); - variables_map vm; - store(parse_command_line(ac, av, desc), vm); - notify(vm); - if (vm.count("help")) { - cout << desc << "\n"; - return 1; - } - if (vm.count("frequency")) { - frequency = vm["frequency"].as (); - } - cout << "Frequency set to " << frequency << " Hertz.\n"; - if (vm.count("amplitude")) { - amplitude = vm["amplitude"].as (); - } - cout << "Amplitude set to " << amplitude << ".\n"; - if (vm.count("offset")) { - offset = vm["offset"].as (); - } - cout << "Offset set to " << offset << ".\n"; - - /** - * Setup main beat - */ - GlobalBeatPtr heartbeat; - heartbeat = GlobalBeat::create(cycletime); - - /** - * Setup the two oscillators - */ - CCANodePtr oscillator1 = SimpleOscillator::create( - "Oscillator 1", 2 * frequency, amplitude, offset); - oscillator1->configureOutputPort(0, - PortConfiguration::LOCAL("/oscillate/1")); - oscillator1->setProcessingStrategy(TimedProcessing::create(1)); - heartbeat->registerReceiver(oscillator1); - - CCANodePtr oscillator2 = SimpleOscillator::create( - "Oscillator 2", frequency, amplitude, offset, 0.5); - oscillator2->configureOutputPort(0, - PortConfiguration::LOCAL("/oscillate/2")); - oscillator2->setProcessingStrategy(TimedProcessing::create(1)); - heartbeat->registerReceiver(oscillator2); - - /** - * Set up two junctions - */ - CCANodePtr junction1 = Junction::create(4); - junction1->setProcessingStrategy(RestlessProcessing::create()); - CCANodePtr junction2 = Junction::create(4); - junction2->setProcessingStrategy(RestlessProcessing::create()); - - /** - * Register converters for Joint Angles - */ - boost::shared_ptr converter( - new JointAnglesConverter()); - stringConverterRepository()->registerConverter(converter); - - /** - * Connect oscillators to junction - */ - junction1->configureInputPort(0, PortConfiguration::LOCAL("/oscillate/1")); - junction1->configureOutputPort(0, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/lfhip")); - junction1->configureOutputPort(1, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/lhhip")); - junction1->configureOutputPort(2, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/rfknee")); - junction1->configureOutputPort(3, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/rhknee")); - - junction2->configureInputPort(0, PortConfiguration::LOCAL("/oscillate/2")); - junction2->configureOutputPort(0, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/rfhip")); - junction2->configureOutputPort(1, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/rhhip")); - junction2->configureOutputPort(2, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/lfknee")); - junction2->configureOutputPort(3, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/lhknee")); - - /** - * Collect all joint angles to send them at once - */ - CCANodePtr collector = Collector::create(8); - collector->setProcessingStrategy(ModerateProcessing::create()); - collector->configureInputPort(0, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/lfhip")); - collector->configureInputPort(1, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/rfhip")); - collector->configureInputPort(2, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/lhhip")); - collector->configureInputPort(3, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/rhhip")); - collector->configureInputPort(4, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/lfknee")); - collector->configureInputPort(5, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/rfknee")); - collector->configureInputPort(6, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/lhknee")); - collector->configureInputPort(7, - PortConfiguration::LOCAL("/oncilla/command/nodes/angles/rhknee")); - collector->configureOutputPort(0, - PortConfiguration::REMOTE("/oncilla/command/nodes/angles/all")); - - std::cout << std::endl << "Two oscillators oscillating between " << (offset - - amplitude) << " and " << (offset + amplitude) << " with " - << frequency << " Hertz ..." << std::endl; - heartbeat->run(); - - return EXIT_SUCCESS; -} diff --git a/examples/walkOneLeg.cpp b/examples/walkOneLeg.cpp index ce09d1f..c515e4f 100644 --- a/examples/walkOneLeg.cpp +++ b/examples/walkOneLeg.cpp @@ -1,107 +1,63 @@ #include #include #include #include #include -#include - #include #include #include #include #include -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include +#include "Oncilla.h" +#include "OncillaSynchronizer.h" using namespace std; using namespace boost; using namespace boost::program_options; -using namespace rsc; -using namespace rsc::logging; - -using namespace rsb; -using namespace rsb::converter; -using namespace rst::converter::rci; - -using namespace cca; -using namespace cca::rci; -using namespace cca::rci::driver; +using namespace rci; +using namespace rci::oncilla; int main(int ac, char **av) { unsigned int cycleTimeMs = 50; double amplitude = 1.0; double offset = 0.0; double frequency = 1; - LoggerFactory::getInstance().reconfigure(Logger::LEVEL_ERROR); - /** * Handle command line options */ options_description desc("Allowed options"); desc.add_options()("help", "Produce help message")("frequency", value (), "Frequency of oscillation in Hertz")("amplitude", value (), "Amplitude of the sine")("offset", value (), "Offset to the output value"); variables_map vm; store(parse_command_line(ac, av, desc), vm); notify(vm); if (vm.count("help")) { cout << desc << "\n"; return 1; } if (vm.count("frequency")) { frequency = vm["frequency"].as (); } cout << "Frequency set to " << frequency << " Hertz.\n"; if (vm.count("amplitude")) { amplitude = vm["amplitude"].as (); } cout << "Amplitude set to " << amplitude << ".\n"; if (vm.count("offset")) { offset = vm["offset"].as (); } cout << "Offset set to " << offset << ".\n"; - /** - * Register converters for Joint Angles - */ - boost::shared_ptr converter( - new JointAnglesConverter()); - stringConverterRepository()->registerConverter(converter); - - /** - * Create Oscillator Node - */ - CCANodePtr oscillator = SimpleOscillator::create( - "Knee Oscillator", frequency, amplitude, offset); - oscillator->configureOutputPort(0, - PortConfiguration::REMOTE("/oncilla/command/nodes/angles/lhknee")); - - /** - * Setup and run the main beat - */ - GlobalBeatPtr heartbeat; - heartbeat = GlobalBeat::create(cycleTimeMs); - heartbeat->registerReceiver(oscillator); - std::cout << "Oscillating between " << (offset - amplitude) << " and " - << (offset + amplitude) << " with " << frequency << " Hertz ..." - << std::endl; - heartbeat->run(); + OncillaSynchronizerPtr s = + OncillaSynchronizerPtr(new OncillaSynchronizer()); + Oncilla o; return EXIT_SUCCESS; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 45ae094..e28aa78 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,34 +1,35 @@ # Configure config header CONFIGURE_FILE("config.h.in" "${PROJECT_NAME}Config.h") SET(ONCILLAHEADERS OncillaTrunk.h OncillaL01.h OncillaL2.h OncillaL3.h OncillaL4.h Oncilla.h OncillaSynchronizer.h) SET(ONCILLASOURCES OncillaTrunk.cpp OncillaL01.cpp OncillaL2.cpp OncillaL3.cpp OncillaL4.cpp + Oncilla.cpp OncillaSynchronizer.cpp) ADD_LIBRARY(${LIBONCILLA_NAME} SHARED ${ONCILLASOURCES}) TARGET_LINK_LIBRARIES(${LIBONCILLA_NAME} ${RSC_LIBRARIES} ${RCI_LIBRARIES} ${LIBRARIES_LIBRARIES}) SET_TARGET_PROPERTIES(${LIBONCILLA_NAME} PROPERTIES VERSION ${LIBONCILLA_VERSION_STRING}) INSTALL(TARGETS ${LIBONCILLA_NAME} RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) INSTALL_FILES_RECURSIVE(include/lib${LIBNAME} ONCILLAHEADERS) diff --git a/src/Oncilla.cpp b/src/Oncilla.cpp index df9c757..84829df 100644 --- a/src/Oncilla.cpp +++ b/src/Oncilla.cpp @@ -1,25 +1,87 @@ /* * Oncilla.cpp * - * Created on: 15 dŽc. 2011 - * Author: Alexandre Tuleu + * Created on: 15 dec. 2011 + * Author: Alexandre Tuleu, Arne Nordmann */ - #include "Oncilla.h" -namespace cca { namespace rci { -namespace driver { - -Oncilla::Oncilla() { - // TODO Auto-generated constructor stub +namespace oncilla { +Oncilla::Oncilla() : + synchronizer(), d_l0s(), d_l1s(), d_l2s(), d_l3s(), d_l4s(), d_trunk() { } Oncilla::~Oncilla() { - // TODO Auto-generated destructor stub + // TODO Auto-generated destructor stub +} + +void Oncilla::init() { + d_l0s.push_back(OncillaL0Ptr(new OncillaL0("Oncilla L0 LEFT FORE"))); + d_l0s.push_back(OncillaL0Ptr(new OncillaL0("Oncilla L0 RIGHT FORE"))); + d_l0s.push_back(OncillaL0Ptr(new OncillaL0("Oncilla L0 LEFT HIND"))); + d_l0s.push_back(OncillaL0Ptr(new OncillaL0("Oncilla L0 RIGHT HIND"))); + + d_l1s.push_back( + OncillaL1Ptr(new OncillaL1(*synchronizer, "Oncilla L1 LEFT FORE"))); + d_l1s.push_back( + OncillaL1Ptr(new OncillaL1(*synchronizer, "Oncilla L1 RIGHT FORE"))); + d_l1s.push_back( + OncillaL1Ptr(new OncillaL1(*synchronizer, "Oncilla L1 LEFT HIND"))); + d_l1s.push_back( + OncillaL1Ptr(new OncillaL1(*synchronizer, "Oncilla L1 RIGHT HIND"))); + + d_l2s.push_back( + OncillaL2Ptr(new OncillaL2(*synchronizer, "Oncilla L2 LEFT FORE"))); + d_l2s.push_back( + OncillaL2Ptr(new OncillaL2(*synchronizer, "Oncilla L2 RIGHT FORE"))); + d_l2s.push_back( + OncillaL2Ptr(new OncillaL2(*synchronizer, "Oncilla L2 LEFT HIND"))); + d_l2s.push_back( + OncillaL2Ptr(new OncillaL2(*synchronizer, "Oncilla L2 RIGHT HIND"))); + + d_l3s.push_back(OncillaL3Ptr(new OncillaL3("Oncilla L3 LEFT FORE"))); + d_l3s.push_back(OncillaL3Ptr(new OncillaL3("Oncilla L3 RIGHT FORE"))); + d_l3s.push_back(OncillaL3Ptr(new OncillaL3("Oncilla L3 LEFT HIND"))); + d_l3s.push_back(OncillaL3Ptr(new OncillaL3("Oncilla L3 RIGHT HIND"))); + + d_l4s.push_back(OncillaL4Ptr(new OncillaL4("L4 LEFT FORE"))); + d_l4s.push_back(OncillaL4Ptr(new OncillaL4("L4 RIGHT FORE"))); + d_l4s.push_back(OncillaL4Ptr(new OncillaL4("L4 LEFT HIND"))); + d_l4s.push_back(OncillaL4Ptr(new OncillaL4("L4 RIGHT HIND"))); + + d_trunk = OncillaTrunkPtr(new OncillaTrunk("Oncilla Trunk")); + +} + +OncillaL0Ptr Oncilla::getL0(Leg l) const { + return this->d_l0s[l]; +} + +OncillaL1Ptr Oncilla::getL1(Leg l) const { + return this->d_l1s[l]; +} + +OncillaL2Ptr Oncilla::getL2(Leg l) const { + return this->d_l2s[l]; +} + +OncillaL3Ptr Oncilla::getL3(Leg l) const { + return this->d_l3s[l]; +} + +OncillaL4Ptr Oncilla::getL4(Leg l) const { + return this->d_l4s[l]; } -} /* namespace driver */ -} /* namespace rci */ -} /* namespace cca */ +OncillaTrunkPtr Oncilla::getTrunk() const { + return this->d_trunk; +} + +void Oncilla::setSynchronizer(OncillaSynchronizerPtr sync) { + this->synchronizer = sync; +} + +} +} diff --git a/src/Oncilla.h b/src/Oncilla.h index ee7b284..1330ad4 100644 --- a/src/Oncilla.h +++ b/src/Oncilla.h @@ -1,66 +1,67 @@ /* * Oncilla.h * - * Created on: 15 d�c. 2011 - * Author: Alexandre Tuleu + * Created on: 15 dec. 2011 + * Author: Alexandre Tuleu, Arne Nordmann */ +#pragma once -#ifndef LIBONCILLA_ONCILLA_H_ -#define LIBONCILLA_ONCILLA_H_ - +#include "OncillaTrunk.h" #include "OncillaL01.h" #include "OncillaL2.h" #include "OncillaL3.h" #include "OncillaL4.h" -#include "OncillaTrunk.h" /* * */ /* * */ -namespace cca { namespace rci { -namespace driver { +namespace oncilla { + +class OncillaSynchronizer; +typedef boost::shared_ptr OncillaSynchronizerPtr; class Oncilla; typedef boost::shared_ptr OncillaPtr; class Oncilla { public: enum Leg { LEFT_FORE = 0, RIGHT_FORE = 1, LEFT_HIND = 2, RIGHT_HIND = 3, NUM_LEGS = 4 }; Oncilla(); virtual ~Oncilla(); - OncillaL0Ptr getL0(Leg l); - OncillaL1Ptr getL1(Leg l); - OncillaL2Ptr getL2(Leg l); - OncillaL3Ptr getL3(Leg l); - OncillaL4Ptr getL4(Leg l); + OncillaL0Ptr getL0(Leg l) const; + OncillaL1Ptr getL1(Leg l) const; + OncillaL2Ptr getL2(Leg l) const; + OncillaL3Ptr getL3(Leg l) const; + OncillaL4Ptr getL4(Leg l) const; + OncillaTrunkPtr getTrunk() const; - OncillaTrunkPtr getTrunk(); + void setSynchronizer(OncillaSynchronizerPtr synchronizer); private: void init(); + OncillaSynchronizerPtr synchronizer; + std::vector d_l0s; std::vector d_l1s; std::vector d_l2s; std::vector d_l3s; std::vector d_l4s; - OncillaPtr d_trunk; + OncillaTrunkPtr d_trunk; }; } } -} -#endif /* LIBONCILLA_ONCILLA_H_ */ diff --git a/src/OncillaL01.cpp b/src/OncillaL01.cpp index 0671797..4b1c2db 100644 --- a/src/OncillaL01.cpp +++ b/src/OncillaL01.cpp @@ -1,97 +1,95 @@ #include "OncillaL01.h" using namespace std; namespace rci { namespace oncilla { -OncillaL1::OncillaL1(const std::string & name) : - ResourceNode(name), Controlled(), Sensing(), PositionControlled(), - PositionSensing(), TorqueControlled(), ImpedanceControlled() { - this->_dimension = 2; // Two encoder values - should always be the same +OncillaL0::OncillaL0(const std::string &name) : + ResourceNode(name), Controlled(), PositionControlled() { } -bool OncillaL1::isConverged() const { - throw std::runtime_error("Not yet implemented."); - return false; +bool OncillaL0::isConverged() const { + return false; } -bool OncillaL1::setJointPosition(JointAnglesPtr position) { - // Successfull - this->_lastCommandedPosition = position; - return true; +bool OncillaL0::setJointPosition(JointAnglesPtr position) { + // Successfull + this->_lastCommandedPosition = position; + return true; } -JointAnglesPtr OncillaL1::getJointPosition() const { - return this->_latestJointPosition; +JointAnglesPtr OncillaL0::getLastPositionCommand() const { + // TODO: The second part f this condition shouldn`t be necessary + if (this->_lastCommandedPosition && this->_lastCommandedPosition.get()) { + //std::cout << this->_lastCommandedPosition->print(); + return this->_lastCommandedPosition; + } + return JointAnglesPtr(); } -bool OncillaL1::setJointVelocity(JointVelocitiesPtr vel) { - throw std::runtime_error("Not yet implemented."); +OncillaL0::~OncillaL0() { } -bool OncillaL1::setJointTorque(JointTorquesPtr torque) { - throw std::runtime_error("Not yet implemented."); +std::string OncillaL0::print() const { + ostringstream outstream(ostringstream::out); + outstream.precision(3); // Precision when printing double values + outstream << "" << endl; + return outstream.str(); } -bool OncillaL1::setJointImpedance(JointImpedancePtr imped) { - throw std::runtime_error("Not yet implemented."); +OncillaL1::OncillaL1(OncillaSynchronizer &s, const std::string &name) : + ResourceNode(name), Controlled(), Sensing(), PositionControlled(), + PositionSensing(), TorqueControlled(), ImpedanceControlled() { + this->_dimension = 2; // Two encoder values - should always be the same } -JointAnglesPtr OncillaL1::getLastPositionCommand() const { - // TODO: The second part f this condition shouldn`t be necessary - if (this->_lastCommandedPosition && this->_lastCommandedPosition.get()) { - //std::cout << this->_lastCommandedPosition->print(); - return this->_lastCommandedPosition; - } - // No command set yet. Returning current joint values instead - return this->_latestJointPosition; +bool OncillaL1::isConverged() const { + throw std::runtime_error("Not yet implemented."); + return false; } -OncillaL1::~OncillaL1() { +bool OncillaL1::setJointPosition(JointAnglesPtr position) { + // Successfull + this->_lastCommandedPosition = position; + return true; } -std::string OncillaL1::print() const { - ostringstream outstream(ostringstream::out); - outstream.precision(3); // Precision when printing double values - outstream << "" << endl; - return outstream.str(); +JointAnglesPtr OncillaL1::getJointPosition() const { + return this->_latestJointPosition; } -/** Oncilla Hip Transverse **/ - -OncillaL0::OncillaL0(std::string name) : - ResourceNode(name), Controlled(), PositionControlled() { +bool OncillaL1::setJointVelocity(JointVelocitiesPtr vel) { + throw std::runtime_error("Not yet implemented."); } -bool OncillaL0::isConverged() const { - return false; +bool OncillaL1::setJointTorque(JointTorquesPtr torque) { + throw std::runtime_error("Not yet implemented."); } -bool OncillaL0::setJointPosition(JointAnglesPtr position) { - // Successfull - this->_lastCommandedPosition = position; - return true; +bool OncillaL1::setJointImpedance(JointImpedancePtr imped) { + throw std::runtime_error("Not yet implemented."); } -JointAnglesPtr OncillaL0::getLastPositionCommand() const { - // TODO: The second part f this condition shouldn`t be necessary - if (this->_lastCommandedPosition && this->_lastCommandedPosition.get()) { - //std::cout << this->_lastCommandedPosition->print(); - return this->_lastCommandedPosition; - } - return JointAnglesPtr(); +JointAnglesPtr OncillaL1::getLastPositionCommand() const { + // TODO: The second part f this condition shouldn`t be necessary + if (this->_lastCommandedPosition && this->_lastCommandedPosition.get()) { + //std::cout << this->_lastCommandedPosition->print(); + return this->_lastCommandedPosition; + } + // No command set yet. Returning current joint values instead + return this->_latestJointPosition; } -OncillaL0::~OncillaL0() { +OncillaL1::~OncillaL1() { } -std::string OncillaL0::print() const { - ostringstream outstream(ostringstream::out); - outstream.precision(3); // Precision when printing double values - outstream << "" << endl; - return outstream.str(); +std::string OncillaL1::print() const { + ostringstream outstream(ostringstream::out); + outstream.precision(3); // Precision when printing double values + outstream << "" << endl; + return outstream.str(); } } } diff --git a/src/OncillaL01.h b/src/OncillaL01.h index c3f373d..6497610 100644 --- a/src/OncillaL01.h +++ b/src/OncillaL01.h @@ -1,144 +1,146 @@ #pragma once #include #include #include #include #include #include #include namespace rci { namespace oncilla { +class OncillaSynchronizer; + class OncillaL1; typedef boost::shared_ptr OncillaL1Ptr; /** * Node class, representing the hip node of the quadruped robot. * * @todo In case of simulation, this node can also sense the power consumption. */ class OncillaL1: public rci::ResourceNode, public rci::Controlled, public rci::Sensing, public rci::PositionControlled, public rci::PositionSensing, // Two encoder values public rci::VelocityControlled, public rci::TorqueControlled, public rci::ImpedanceControlled { public: /** * Special constructor to also link to webots */ - OncillaL1(const std::string & name = "Oncilla Hip"); + OncillaL1(OncillaSynchronizer &s, + const std::string &name = "Oncilla Hip"); virtual ~OncillaL1(); /** * Returns, if controller is converged. * @return True, if controller is converged after last command. */ bool isConverged() const; /** * Commanding a joint position. * @param position Position command * @return Return, if successfull. (e.g. not exceeding joint limits) * @todo Check for correct control mode */ bool setJointPosition(JointAnglesPtr position); /** * Returns current joint position. * @return Current joint position */ virtual JointAnglesPtr getJointPosition() const; - /** * Commanding a joint velocity. * @param position Position command * @return Return, if successfull. (e.g. not exceeding joint limits) * @todo Check for correct control mode */ virtual bool setJointVelocity(rci::JointVelocitiesPtr vel); /** * Returns current joint torque. * @return Current joint torque */ virtual bool setJointTorque(JointTorquesPtr torque); /** * Returns current joint torque. * @return Current joint torque */ virtual bool setJointImpedance(JointImpedancePtr imped); /** * Returns latest position command. Note, that this is the latest valid * commanded position. If the position command exceeds limits and is * therefore rejected, it .. */ virtual JointAnglesPtr getLastPositionCommand() const; /** * Print */ std::string print() const; }; class OncillaL0; typedef boost::shared_ptr OncillaL0Ptr; /** * Node class, representing the hip node of the quadruped robot. * @todo In case of simulation, this node can also sense the power consumption. */ class OncillaL0: public rci::ResourceNode, public rci::Controlled, public rci::PositionControlled { public: /** * Special constructor to also link to webots */ - OncillaL0(std::string name = "Oncilla Hip"); + OncillaL0(const std::string &name = "Oncilla Hip"); virtual ~OncillaL0(); /** * Returns, if controller is converged. * @return True, if controller is converged after last command. */ bool isConverged() const; /** * Commanding a joint position. * @param position Position command * @return Return, if successfull. (e.g. not exceeding joint limits) * @todo Check for correct control mode */ bool setJointPosition(JointAnglesPtr position); /** * Returns latest position command. Note, that this is the latest valid * commanded position. If the position command exceeds limits and is * therefore rejected, it .. */ virtual JointAnglesPtr getLastPositionCommand() const; /** * Print */ std::string print() const; }; } } diff --git a/src/OncillaL2.cpp b/src/OncillaL2.cpp index 0537670..07c6f8d 100644 --- a/src/OncillaL2.cpp +++ b/src/OncillaL2.cpp @@ -1,66 +1,66 @@ #include "OncillaL2.h" using namespace std; using namespace boost; namespace rci { namespace oncilla { -OncillaL2::OncillaL2(const std::string & name) : +OncillaL2::OncillaL2(OncillaSynchronizer &s, const std::string &name) : ResourceNode(name), Controlled(), Sensing(), PositionControlled(), PositionSensing(), VelocityControlled(), TorqueControlled(), ImpedanceControlled() { // Two encoder values - difference is due to passive compliance this->_dimension = 2; } bool OncillaL2::isConverged() const { return false; } bool OncillaL2::setJointPosition(JointAnglesPtr position) { // Successfull // std::cerr << "[OncillaKnee] " << position << std::endl; this->_lastCommandedPosition = position; return true; } JointAnglesPtr OncillaL2::getJointPosition() const { return this->_latestJointPosition; } OncillaL2::~OncillaL2() { } std::string OncillaL2::print() const { ostringstream outstream(ostringstream::out); outstream.precision(3); // Precision when printing double values outstream << "" << endl; return outstream.str(); } bool OncillaL2::setJointTorque(JointTorquesPtr torques) { throw std::runtime_error("Not yet implemented."); } bool OncillaL2::setJointImpedance(JointImpedancePtr imped) { throw std::runtime_error("Not yet implemented."); } bool OncillaL2::setJointVelocity(JointVelocitiesPtr vel) { throw std::runtime_error("Not yet implemented."); } JointAnglesPtr OncillaL2::getLastPositionCommand() const { // TODO: The second part f this condition shouldn`t be necessary if (!this->_lastCommandedPosition || !this->_lastCommandedPosition.get()) { // No command set yet. Returning current joint values instead // FIXME: Instead of return current position set command to current position return this->_latestJointPosition; } return this->_lastCommandedPosition; } } } diff --git a/src/OncillaL2.h b/src/OncillaL2.h index 2c3869f..ce38d86 100644 --- a/src/OncillaL2.h +++ b/src/OncillaL2.h @@ -1,95 +1,98 @@ #pragma once #include #include #include #include #include #include #include namespace rci { namespace oncilla { +class OncillaSynchronizer; + class OncillaL2; typedef boost::shared_ptr OncillaL2Ptr; /** * Node class, representing the knee node of the quadruped robot. * @todo In case of simulation, this node can also sense the power consumption. */ class OncillaL2: public rci::ResourceNode, public rci::Controlled, public rci::Sensing, public rci::PositionControlled, public rci::PositionSensing, public rci::VelocityControlled, public rci::TorqueControlled, public rci::ImpedanceControlled { public: - OncillaL2(const std::string & name = "Oncilla Knee"); + OncillaL2(OncillaSynchronizer &s, + const std::string &name = "Oncilla Knee"); virtual ~OncillaL2(); /** * Returns, if controller is converged. * @return True, if controller is converged after last command. */ bool isConverged() const; /** * Commanding a joint position. * @param position Position command * @return Return, if successfull. (e.g. not exceeding joint limits) * @todo Check for correct control mode */ bool setJointPosition(JointAnglesPtr position); /** * Returns current joint position. * @return Current joint position */ virtual JointAnglesPtr getJointPosition() const; /** * Commanding a joint velocity. * @param position Velocity command * @return Return, if successfull. (e.g. not exceeding joint limits) * @todo Check for correct control mode */ bool setJointVelocity(JointVelocitiesPtr vel); /** * Commanding a joint velocity. * @param position Velocity command * @return Return, if successfull. (e.g. not exceeding joint limits) * @todo Check for correct control mode */ bool setJointImpedance(JointImpedancePtr imped); /** * Commanding a joint torque. * @param position Torque command * @return Return, if successfull. (e.g. not exceeding joint limits) * @todo Check for correct control mode */ virtual bool setJointTorque(rci::JointTorquesPtr torques); /** * Returns latest position command. Note, that this is the latest valid * commanded position. If the position command exceeds limits and is * therefore rejected, it .. */ virtual JointAnglesPtr getLastPositionCommand() const; /** * Print */ std::string print() const; }; } } diff --git a/src/OncillaSynchronizer.h b/src/OncillaSynchronizer.h index 1ef87b4..8a7e23b 100644 --- a/src/OncillaSynchronizer.h +++ b/src/OncillaSynchronizer.h @@ -1,85 +1,86 @@ #pragma once #include #include #include #include +#include "Oncilla.h" #include "OncillaTrunk.h" #include "OncillaL01.h" #include "OncillaL2.h" #include "OncillaL3.h" #include "OncillaL4.h" namespace rci { namespace oncilla { class OncillaSynchronizer; typedef boost::shared_ptr OncillaSynchronizerPtr; /** * OncillaSynchronizer * Different OncillaSynchronizers may be for example: * * Update with a given frequency * ** Send data every time * ** Send only if new data * * Update only if new data (event-based) * * Triggered from robot side (e.g. FRI) */ class OncillaSynchronizer : public Synchronizer { public: OncillaSynchronizer(const std::string &name); virtual ~OncillaSynchronizer(); /** * Registers a trunk node. */ - virtual void registerTrunkNode(unsigned int index, OncillaTrunkPtr node) = 0; + virtual void registerTrunkNode(Oncilla::Leg index, OncillaTrunkPtr node) = 0; /** * Registers an L0 node. */ - virtual void registerL0Node(unsigned int index, OncillaL0Ptr node) = 0; + virtual void registerL0Node(Oncilla::Leg index, OncillaL0Ptr node) = 0; /** * Registers an L1 node. */ - virtual void registerL1Node(unsigned int index, OncillaL1Ptr node) = 0; + virtual void registerL1Node(Oncilla::Leg index, OncillaL1Ptr node) = 0; /** * Registers an L2 node. */ - virtual void registerL2Node(unsigned int index, OncillaL2Ptr node) = 0; + virtual void registerL2Node(Oncilla::Leg index, OncillaL2Ptr node) = 0; /** * Registers an L3 node. */ - virtual void registerL3Node(unsigned int index, OncillaL3Ptr node) = 0; + virtual void registerL3Node(Oncilla::Leg index, OncillaL3Ptr node) = 0; /** * Registers an L4 node. */ - virtual void registerL4Node(unsigned int index, OncillaL4Ptr node) = 0; + virtual void registerL4Node(Oncilla::Leg index, OncillaL4Ptr node) = 0; /** * */ friend std::ostream & operator<<(std::ostream& os, const OncillaSynchronizer& val); protected: /** * Only true for the first time */ bool _onlyReceive; /** * */ std::string name; }; } }