-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fixCompilationWarnings
- Loading branch information
Showing
120 changed files
with
5,960 additions
and
1,527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
project(${POLOLU_LIBRARY}) | ||
|
||
set(POLOLU_MAJOR_VERSION 1 PARENT_SCOPE) | ||
set(POLOLU_MINOR_VERSION 0 PARENT_SCOPE) | ||
set(POLOLU_PATCH_VERSION 0 PARENT_SCOPE) | ||
|
||
vp_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
|
||
set(lib_srcs src/RPMSerialInterface.cpp) | ||
set(lib_hdrs include/RPMSerialInterface.h) | ||
|
||
if(CMAKE_SYSTEM_NAME MATCHES "Windows") | ||
list(APPEND lib_hdrs include/RPMSerialInterfaceWindows.h) | ||
list(APPEND lib_srcs src/RPMSerialInterfaceWindows.cpp) | ||
elseif( CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "Darwin") | ||
# Could also be used on Windows with MinGW | ||
list(APPEND lib_hdrs include/RPMSerialInterfacePOSIX.h) | ||
list(APPEND lib_srcs src/RPMSerialInterfacePOSIX.cpp) | ||
else() | ||
message("${PROJECT_NAME} is only available for Windows, Linux and Darwin") | ||
endif() | ||
|
||
add_library(${POLOLU_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs}) | ||
|
||
if(UNIX) | ||
if(CMAKE_COMPILER_IS_GNUCXX OR CV_ICC) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") | ||
endif() | ||
endif() | ||
|
||
if(ENABLE_SOLUTION_FOLDERS) | ||
set_target_properties(${POLOLU_LIBRARY} PROPERTIES FOLDER "3rdparty") | ||
endif() | ||
|
||
set_target_properties(${POLOLU_LIBRARY} | ||
PROPERTIES OUTPUT_NAME ${POLOLU_LIBRARY} | ||
DEBUG_POSTFIX "${VISP_DEBUG_POSTFIX}" | ||
COMPILE_PDB_NAME ${POLOLU_LIBRARY} | ||
COMPILE_PDB_NAME_DEBUG "${POLOLU_LIBRARY}${VISP_DEBUG_POSTFIX}" | ||
ARCHIVE_OUTPUT_DIRECTORY ${VISP_3P_LIBRARY_OUTPUT_PATH} | ||
) | ||
|
||
if(NOT BUILD_SHARED_LIBS) | ||
vp_install_target(${POLOLU_LIBRARY} EXPORT VISPModules ARCHIVE DESTINATION ${VISP_3P_LIB_INSTALL_PATH} COMPONENT dev) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Jacques Menuet | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Porting of the RapaPololuMaestro project: https://github.com/jbitoniau/RapaPololuMaestro commit d30b0af210 | ||
|
||
2023-10-20: | ||
- Changes introduced to fix warnings | ||
- Remove the RPM namespace that makes the SerialInterface class nested and prevents it from being used as a private | ||
class in vpServoPololuMaestro.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
RapaPololuMaestro | ||
================= | ||
A cross-platform C++ library for controlling Pololu Maestro devices | ||
|
||
![alt text](docs/RapaPololuMaestro1.jpg?raw=true "Pololu Maestro driving a servo") | ||
![alt text](docs/RapaPololuMaestro2.jpg?raw=true "Pololu Maestro controlled by a Raspberry Pi") | ||
![alt text](docs/RapaPololuMaestroViewer.png?raw=true "Pololu Maestro Viewer") | ||
|
||
# Overview | ||
RapaPololuMaestro (formerly [Polstro](https://code.google.com/p/polstro/)) is a lightweight cross-platform C++ library that provides access, in an object-oriented fashion, to one or more [Pololu Maestro servo-controller devices](http://www.pololu.com/docs/0J40) connected to the computer. | ||
|
||
The communication is based on the [Serial Interface protocol](http://www.pololu.com/docs/0J40/5.c Serial Interface), not the native USB interface (which offers more advanced functionalities). | ||
|
||
With RapaPololuMaestro it's possible to: | ||
|
||
* set/get the target position of any servo connected to the Maestro device (from 6 to 24 depending on the Maestro model) | ||
* set the speed and acceleration at which the Maestro changes the position. | ||
|
||
Note that by servo here we mean any RC component that is driven by a PWM signal. This can be for example an ESC (Electronic Speed Controller) that controls a brushless motor. | ||
|
||
The code is based on the [cross-platform C](http://www.pololu.com/docs/0J40/5.h.2) and [Windows examples](http://www.pololu.com/docs/0J40/5.h.2 Windows) provided by Pololu. | ||
|
||
# Example of use | ||
```cpp | ||
#include "RPMSerialInterface.h" | ||
|
||
int main( int argc, char** argv ) | ||
{ | ||
// Create the interface | ||
RPM::SerialInterface* serialInterface = RPM::SerialInterface::createSerialInterface( "COM4", 9600 ); | ||
if ( !serialInterface->isOpen() ) | ||
return -1; | ||
|
||
// Set the value of channel 0 to 6000 quarter-of-microseconds (i.e. 1.5 milliseconds) | ||
serialInterface->setTargetCP( 0, 6000 ); | ||
|
||
// Delete the interface | ||
delete serialInterface; | ||
|
||
return 0; | ||
} | ||
``` | ||
# Compiling the code | ||
RapaPololuMaestro uses CMake 3 to create the build system corresponding to the platform. You need to have it installed on your system, please visit [CMake](http://www.cmake.org/) for more information. | ||
After downloading the source code and opening a console in the main source folder, creating the build system can be done like this: | ||
``` | ||
mkdir _build_ | ||
cd _build_ | ||
cmake .. -DCMAKE_INSTALL_PREFIX=../_output_ | ||
``` | ||
You should then have a build system ready to use for your platform (for example, a Visual Studio solution on Windows, a makefile on Linux, etc...). | ||
The build process generates a static library, and two samples: | ||
* a command-line test program. | ||
* a GUI program to control a Maestro interactively | ||
The GUI uses Qt as a dependency. If it can't be found on your system, the GUI program will simply be not built. | ||
Either Qt4 or Qt5 can be used. You can specify one or the other using the RAPA_USE_QT5 CMake variable. For example, to compile using QT4: | ||
``` | ||
cmake .. -DCMAKE_INSTALL_PREFIX=../_output_ -DRAPA_USE_QT5=OFF | ||
``` | ||
If CMake doesn't find Qt automatically, you can point it to the appropriate folder. In this example we also compile for Visual Studio 12 2013 in 64 bits: | ||
``` | ||
cmake .. -DCMAKE_INSTALL_PREFIX=../_output_ -DCMAKE_PREFIX_PATH=C:\SomePath\Qt\5.5\msvc2013_64 -G "Visual Studio 12 2013 Win64" | ||
``` | ||
Once the compilation done, you can deploy/install RapaPololuMaestro as a standalone SDK, by building the INSTALL target/project generated by CMake. This will copy the headers, libs and binaries into the directory designated by the standard CMAKE_INSTALL_PREFIX variable. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
The MIT License (MIT) (http://opensource.org/licenses/MIT) | ||
Copyright (c) 2015 Jacques Menuet | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
/* | ||
SerialInterface | ||
The SerialInterface implements the Pololu Maestro serial communication protocol. | ||
See http://www.pololu.com/docs/0J40/5.e for the details of the commands available. | ||
The SerialInterface methods of the SerialInterface come into different flavours, | ||
each uses a different protocol: | ||
- Compact protocol (CP) | ||
- Pololu protocol (PP) | ||
- Mini-SSC protocol (MSSCP) | ||
See http://www.pololu.com/docs/0J40/5.c for more information. | ||
Note: add the ability to specify min/max target value at construction time rather | ||
than having it hard-coded. | ||
*/ | ||
class RPMSerialInterface | ||
{ | ||
public: | ||
// Create a concrete platform-specific SerialInterface. | ||
// Return NULL if the interface couldn't be created and set the optional error message. | ||
static RPMSerialInterface *createSerialInterface(const std::string &portName, unsigned int baudRate, std::string *errorMessage = NULL); | ||
|
||
// Return the last error message. The message is set when a methods encounters a problem and returns false. | ||
// It is automatically cleared at the beginning of each method. | ||
const std::string &getErrorMessage() const { return mErrorMessage; } | ||
|
||
// Destructor | ||
virtual ~RPMSerialInterface(); | ||
|
||
// Indicates whether the serial port has been successfully open at construction | ||
virtual bool isOpen() const = 0; | ||
|
||
// Return the minimum valid channel value in 0.25 microsecond units | ||
static unsigned short getMinChannelValue() { return mMinChannelValue; } | ||
|
||
// Return the maximum valid channel value in 0.25 microsecond units | ||
static unsigned short getMaxChannelValue() { return mMaxChannelValue; } | ||
|
||
// Set the target position of a channel to a given value in 0.25 microsecond units | ||
bool setTargetCP(unsigned char channelNumber, unsigned short target); | ||
bool setTargetPP(unsigned char deviceNumber, unsigned char channelNumber, unsigned short target); | ||
|
||
// In the Mini-SSC version of this method, the normalizedTarget value is between 0 and 255. | ||
// The value is converted to an actual 0.25 microsecond unit value based on pre-configured | ||
// settings (neutral and range parameters) stored on the Pololu Maestro device itself. | ||
// This is done using a tool such as the Maestro Control Center. Calibration can be therefore | ||
// done externally quite easily. | ||
// Additionally, the miniSCC channel number allows access to channels of chained devices. | ||
bool setTargetMSSCP(unsigned char miniSCCChannelNumber, unsigned char normalizedTarget); | ||
|
||
// On Mini Maestro 12, 18 and 24 only, so not supported here (as I only have a Mini Maestro 6) | ||
// bool setMultipleTargets(...) | ||
|
||
// Set the speed limit of a channel in units of (0.25 microsecond)/(10ms) | ||
bool setSpeedCP(unsigned char channelNumber, unsigned short speed); | ||
bool setSpeedPP(unsigned char deviceNumber, unsigned char channelNumber, unsigned short speed); | ||
|
||
// Set the acceleration limit of a channel in units of (0.25 microsecond)/(10ms)/(80ms) | ||
bool setAccelerationCP(unsigned char channelNumber, unsigned char acceleration); | ||
bool setAccelerationPP(unsigned char deviceNumber, unsigned char channelNumber, unsigned char acceleration); | ||
|
||
// Return the position of a channel. | ||
// For a servo channel, the position is the current pulse width in 0.25 microsecond units | ||
// For a digital output channel, a position less than 6000 means the line is low, and high when above 6000 | ||
// For an input channel, the position represents the voltage measured on the channel. | ||
bool getPositionCP(unsigned char channelNumber, unsigned short &position); | ||
bool getPositionPP(unsigned char deviceNumber, unsigned char channelNumber, unsigned short &position); | ||
|
||
// Indicate whether the servo outputs have reached their targets or are still moving. | ||
bool getMovingStateCP(bool &servosAreMoving); | ||
bool getMovingStatePP(unsigned char deviceNumber, bool &servosAreMoving); | ||
|
||
// The return the error detected by the Pololu Maestro. This automatically clears the error flag. | ||
bool getErrorsCP(unsigned short &error); | ||
bool getErrorsPP(unsigned char deviceNumber, unsigned short &error); | ||
|
||
// Request the Pololu Maestro to "go home". | ||
// Going home sets the channels to their startup/error state. | ||
// This state is defined on a per-channel. It can either be: | ||
// - ignore: the value is unchanged when we do a "go home". PWM signal is continues to be generated | ||
// - go to: the channel is set to the specified value. Again PWM signal is generated | ||
// - off: the channel is turned off. There's no more PWM signal generated for the channel | ||
bool goHomeCP(); | ||
bool goHomePP(unsigned char deviceNumber); | ||
|
||
protected: | ||
RPMSerialInterface(); | ||
void clearErrorMessage(); | ||
void setErrorMessage(const std::string &message); | ||
|
||
bool checkPortIsOpen() const; // And update error message if not | ||
bool checkValidTargetValue(unsigned short target) const; // Same here | ||
|
||
private: | ||
static const unsigned short mMinChannelValue = 3968; | ||
static const unsigned short mMaxChannelValue = 8000; | ||
|
||
virtual bool writeBytes(const unsigned char *data, unsigned int dataSizeInBytes) = 0; | ||
virtual bool readBytes(unsigned char *data, unsigned int dataSizeInBytes) = 0; | ||
|
||
std::string mErrorMessage; | ||
}; |
Oops, something went wrong.