Skip to content

Commit

Permalink
Adding wrapper vpServoPololuMaestro class over RappaPololuMaestro sdk
Browse files Browse the repository at this point in the history
Allow position and velocity control using pololu board

Move documentation from .cpp to .h
  • Loading branch information
Pierre Perraud committed Oct 6, 2023
1 parent a108a15 commit a91a161
Show file tree
Hide file tree
Showing 12 changed files with 1,167 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ VP_OPTION(USE_UEYE Ueye "" "Include uEye SDK support for IDS ca
VP_OPTION(USE_COMEDI Comedi "" "Include comedi (linux control and measurement device interface) support" "" ON IF NOT WINRT AND NOT IOS)
VP_OPTION(USE_FTIITSDK FTIITSDK "" "Include IIT force-torque SDK support" "" ON IF NOT WINRT AND NOT IOS)
VP_OPTION(USE_BICLOPS BICLOPS "" "Include biclops support" "" ON IF NOT WINRT AND NOT IOS)
VP_OPTION(USE_RAPA_POLOLU_MAESTRO MyRapaPololuMaestro "" "Include Rapa Pololu Maestro 3rd party" "" ON IF UNIX)
VP_OPTION(USE_PTU46 PTU46 "" "Include ptu-46 support" "" ON IF UNIX AND NOT WINRT AND NOT IOS)
VP_OPTION(USE_FLIRPTUSDK FlirPtuSDK "" "Include Flir PTU SDK support" "" ON IF NOT WINRT AND NOT IOS)
VP_OPTION(USE_CMU1394 CMU1394 "" "Include cmu1494 support" "" ON IF WIN32 AND NOT WINRT AND NOT IOS)
Expand Down Expand Up @@ -914,6 +915,7 @@ VP_SET(VISP_HAVE_FRANKA TRUE IF (BUILD_MODULE_visp_robot AND USE_FRANKA))
VP_SET(VISP_HAVE_JACOSDK TRUE IF (BUILD_MODULE_visp_robot AND USE_JACOSDK))
VP_SET(VISP_HAVE_MAVSDK TRUE IF (BUILD_MODULE_visp_robot AND USE_MAVSDK))
VP_SET(VISP_HAVE_BICLOPS TRUE IF (BUILD_MODULE_visp_robot AND USE_BICLOPS))
VP_SET(VISP_HAVE_RAPA_POLOLU_MAESTRO TRUE IF (BUILD_MODULE_visp_robot AND USE_RAPA_POLOLU_MAESTRO))
VP_SET(VISP_HAVE_PTU46 TRUE IF (BUILD_MODULE_visp_robot AND USE_PTU46))
VP_SET(VISP_HAVE_FLIR_PTU_SDK TRUE IF (BUILD_MODULE_visp_robot AND USE_FLIRPTUSDK))
VP_SET(VISP_HAVE_ARSDK TRUE IF (BUILD_MODULE_visp_robot AND USE_ARSDK))
Expand Down Expand Up @@ -1539,6 +1541,7 @@ status(" Use Kinova Jaco:" USE_JACOSDK THEN "yes" ELSE "no")
status(" Use aria (Pioneer):" USE_ARIA THEN "yes" ELSE "no")
status(" Use PTU46:" USE_PTU46 THEN "yes" ELSE "no")
status(" Use Biclops PTU:" USE_BICLOPS THEN "yes" ELSE "no")
status(" Use Rapa Pololu Maestro:" USE_RAPA_POLOLU_MAESTRO THEN "yes" ELSE "no")
status(" Use Flir PTU SDK:" USE_FLIRPTUSDK THEN "yes (ver ${FLIRPTUSDK_VERSION})" ELSE "no")
status(" Use MAVSDK:" USE_MAVSDK THEN "yes (ver ${MAVSDK_VERSION})" ELSE "no")
status(" Use Parrot ARSDK:" USE_ARSDK THEN "yes" ELSE "no")
Expand Down
71 changes: 71 additions & 0 deletions cmake/FindMyRapaPololuMaestro.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#############################################################################
#
# ViSP, open source Visual Servoing Platform software.
# Copyright (C) 2005 - 2023 by Inria. All rights reserved.
#
# This software is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# See the file LICENSE.txt at the root directory of this source
# distribution for additional information about the GNU GPL.
#
# For using ViSP with software that can not be combined with the GNU
# GPL, please contact Inria about acquiring a ViSP Professional
# Edition License.
#
# See https://visp.inria.fr for more information.
#
# This software was developed at:
# Inria Rennes - Bretagne Atlantique
# Campus Universitaire de Beaulieu
# 35042 Rennes Cedex
# France
#
# If you have questions regarding the use of this file, please contact
# Inria at [email protected]
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
# Description:
# Try to find Rapa Pololu Maestro library material
# See https://github.com/jbitoniau/RapaPololuMaestro
#
# RapaPololuMaestro_FOUND
# RapaPololuMaestro_INCLUDE_DIRS
# RapaPololuMaestro_LIBRARIES
#
#############################################################################

find_path(RapaPololuMaestro_INCLUDE_DIR RPMSerialInterface.h
PATHS
$ENV{RapaPololuMaestro_DIR}/include
${RapaPololuMaestro_DIR}/include
/usr/include
/usr/local/include
)

find_library(RapaPololuMaestro_LIBRARY
NAMES RapaPololuMaestro
PATHS
$ENV{RapaPololuMaestro_DIR}/lib
${RapaPololuMaestro_DIR}/lib
/usr/lib
/usr/local/lib
)

if(RapaPololuMaestro_INCLUDE_DIR AND RapaPololuMaestro_LIBRARY)
set(RapaPololuMaestro_FOUND TRUE)
set(RapaPololuMaestro_INCLUDE_DIRS ${RapaPololuMaestro_INCLUDE_DIR})
set(RapaPololuMaestro_LIBRARIES ${RapaPololuMaestro_LIBRARY})
else()
set(RapaPololuMaestro_FOUND FALSE)
endif()

mark_as_advanced(
RapaPololuMaestro_INCLUDE_DIR
RapaPololuMaestro_LIBRARY
RapaPololuMaestro_INCLUDE_DIRS
RapaPololuMaestro_LIBRARIES
)
61 changes: 32 additions & 29 deletions cmake/templates/vpConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,33 @@
#include <cstdlib>

#if defined _MSC_VER && _MSC_VER >= 1200
#pragma warning( disable: 4100 4127 4251 4275 4351 4514 4668 4710 4820 )
#if _MSC_VER >= 1400 // 1400 = MSVC 8 2005
#pragma warning( disable: 4548 )
#endif
#if _MSC_VER > 1500 // 1500 = MSVC 9 2008
#pragma warning( disable: 4986 )
#endif
#ifdef WINRT
#pragma warning(disable:4447)
#endif

// 4100 : undocumented ("unreferenced formal parameter")
// 4127 : conditional expression is constant
// 4251 : 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2', ie. disable warnings related to inline functions
// 4275 : non – DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
// 4351 : new behavior: elements of array will be default initialized
// 4447 : Disable warning 'main' signature found without threading model
// 4514 : 'function' : unreferenced inline function has been removed
// 4548 : expression before comma has no effect
// 4668 : 'symbol' is not defined as a preprocessor macro, replacing with '0' for 'directives'
// 4710 : 'function' : function not inlined
// 4820 : 'bytes' bytes padding added after construct 'member_name'
// 4986 : undocumented

#ifndef NOMINMAX
#define NOMINMAX
#endif
#pragma warning( disable: 4100 4127 4251 4275 4351 4514 4668 4710 4820 )
#if _MSC_VER >= 1400 // 1400 = MSVC 8 2005
#pragma warning( disable: 4548 )
#endif
#if _MSC_VER > 1500 // 1500 = MSVC 9 2008
#pragma warning( disable: 4986 )
#endif
#ifdef WINRT
#pragma warning(disable:4447)
#endif

// 4100 : undocumented ("unreferenced formal parameter")
// 4127 : conditional expression is constant
// 4251 : 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2', ie. disable warnings related to inline functions
// 4275 : non – DLL-interface classkey 'identifier' used as base for DLL-interface classkey 'identifier'
// 4351 : new behavior: elements of array will be default initialized
// 4447 : Disable warning 'main' signature found without threading model
// 4514 : 'function' : unreferenced inline function has been removed
// 4548 : expression before comma has no effect
// 4668 : 'symbol' is not defined as a preprocessor macro, replacing with '0' for 'directives'
// 4710 : 'function' : function not inlined
// 4820 : 'bytes' bytes padding added after construct 'member_name'
// 4986 : undocumented

#ifndef NOMINMAX
#define NOMINMAX
#endif
#endif

#if defined _MSC_VER && (_MSC_VER == 1500)
Expand Down Expand Up @@ -104,7 +104,7 @@
#define VISP_VERSION_PATCH ${VISP_VERSION_PATCH}

// ViSP version with dots "${VISP_VERSION_MAJOR}.${VISP_VERSION_MINOR}.${VISP_VERSION_PATCH}".
#cmakedefine VISP_VERSION ${VISP_VERSION}
#cmakedefine VISP_VERSION $ { VISP_VERSION }

// ViSP version as an integer
#define VP_VERSION_INT(a, b, c) (a<<16 | b<<8 | c)
Expand All @@ -115,7 +115,7 @@
// Enable debug and trace printings
#cmakedefine VP_TRACE
#cmakedefine VP_DEBUG
#cmakedefine VP_DEBUG_MODE ${VP_DEBUG_MODE}
#cmakedefine VP_DEBUG_MODE $ { VP_DEBUG_MODE }

// ViSP library is either compiled static or shared
// Used to set declspec(import, export) in headers if required under Windows
Expand Down Expand Up @@ -395,6 +395,9 @@
#cmakedefine VISP_HAVE_BICLOPS
#cmakedefine VISP_HAVE_BICLOPS_AND_GET_HOMED_STATE_FUNCTION

// Defined if Rapa Pololu Maestro 3rd party library available.
#cmakedefine VISP_HAVE_RAPA_POLOLU_MAESTRO

// Defined if Irisa's Ptu-46 pan-tilt head available.
#cmakedefine VISP_HAVE_PTU46

Expand Down
1 change: 1 addition & 0 deletions doc/config-doxygen.in
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,7 @@ PREDEFINED = @DOXYGEN_SHOULD_SKIP_THIS@ \
VISP_HAVE_QBDEVICE \
VISP_HAVE_QT \
VISP_HAVE_QUALISYS \
VISP_HAVE_RAPA_POLOLU_MAESTRO \
VISP_HAVE_REALSENSE \
VISP_HAVE_REALSENSE_VERSION=0x020000 \
VISP_HAVE_REALSENSE2 \
Expand Down
5 changes: 5 additions & 0 deletions modules/robot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ if(USE_BICLOPS)
list(APPEND opt_libs ${BICLOPS_LIBRARIES})
endif()

if(USE_RAPA_POLOLU_MAESTRO)
list(APPEND opt_incs ${RapaPololuMaestro_INCLUDE_DIRS})
list(APPEND opt_libs ${RapaPololuMaestro_LIBRARIES})
endif()

if(USE_PTU46)
list(APPEND opt_incs ${PTU46_INCLUDE_DIRS})
list(APPEND opt_libs ${PTU46_LIBRARIES})
Expand Down
170 changes: 170 additions & 0 deletions modules/robot/include/visp3/robot/vpPTUPololuMaestro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2023 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See https://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at [email protected]
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Common features for Pololu Maestro PanTiltUnit.
*/

#ifndef _vpPTUPololuMaestro_h_
#define _vpPTUPololuMaestro_h_

#include <visp3/core/vpConfig.h>

#ifdef VISP_HAVE_RAPA_POLOLU_MAESTRO

#include <iostream>
#include <string>
#include <thread>
#include <chrono>

#include <RPMSerialInterface.h>

#include <visp3/robot/vpServoPololuMaestro.h>

using namespace std;

/*!
* \class vpPTUPololuMaestro
* \ingroup group_robot_real_arm
*
* \brief Interface for the Pololu Maestro Pan Tilt Unit using servo motors.
*
* See https://www.pololu.com/category/102/maestro-usb-servo-controllers for more details.
*
* This class handle the vpServoPololuMaestro class in a higher level and allows to control
* the Pan Tilt Unit using position or velocity commands.
*
*/
class VISP_EXPORT vpPTUPololuMaestro
{
public:
typedef enum { pan, tilt, yaw } Axe;

/*!
* Default constructor.
*/
vpPTUPololuMaestro();


/*!
* Value constructor.
*
* \param baudrate : Baudrate used for the serial communication.
*
* \param device : Name of the serial interface used for communication.
*/
vpPTUPololuMaestro(const std::string &device, int baudrate);

/*!
* Destructor.
*/
virtual ~vpPTUPololuMaestro();

/*!
* Get ranges for a given axe.
*
* \param minAngle : Pointer to minimum range of the servo.
*
* \param maxAngle : Pointer to maximum range of the servo.
*
* \param rangeAngle : Pointer to the range of the servo.
*
* \param axe : One of the axe define in vpPTUPololuMaestro.h Axe enum.
*
*/
void getRange(float &minAngle, float &maxAngle, float &rangeAngle, Axe axe = pan);

/*!
* Get the current position of a servo motor in degree.
*
* \param angle : Angle, in degree.
*
* \param axe : One of the axe define in vpPTUPololuMaestro.h Axe enum.
*
*/
void getPositionAngle(float &angle, Axe axe);


/*!
* Initiate the serial connection with the Pololu board.
*
* \param device : Name of the serial interface used for communication.
*
* \param baudrate : Baudrate used for the serial communication.
*
*/
void setConnection(std::string device, int baudrate);

/*!
* Set position in degree and the maximum speed of displacement for a given axe.
*
* \param angle : Angle to reach, in degree.
*
* \param speed : Maximum speed for movement in units of (0.25 μs)/(10 ms).
* You can use the vpServoPololuMaestro::degSToSpeed method for conversion.
*
* \param axe : One of the axe define in vpPTUPololuMaestro.h Axe enum.
*
*/
void setPositionAngle(float angle, unsigned short speed = 0, Axe axe = pan);

/*!
* Set and start the velocity command for a given axe.
*
* \param speed : Speed for movement in units of (0.25 μs)/(10 ms).
* You can use the vpServoPololuMaestro::degSToSpeed method for conversion.
*
* \param axe : One of the axe define in vpPTUPololuMaestro.h Axe enum.
*
*/
void setVelocityCmd(short speed, Axe axe = pan);


/*!
* Stop the velocity command for a given axe.
*
* \param axe : One of the axe define in vpPTUPololuMaestro.h Axe enum.
*
*/
void stopVelocityCmd(Axe axe);

private:
// Serial connection parameters.
int m_baudrate;
std::string m_device;
RPM::SerialInterface *m_serialInterface;

vpServoPololuMaestro m_pan;
vpServoPololuMaestro m_tilt;

bool m_verbose;
};

#endif
#endif
2 changes: 1 addition & 1 deletion modules/robot/include/visp3/robot/vpRobotException.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class VISP_EXPORT vpRobotException : public vpException
enum errorRobotCodeEnum
{

//! Error from constructor
//! Error from constructor
constructionError,

//! Not unique robot object construction
Expand Down
Loading

0 comments on commit a91a161

Please sign in to comment.