Skip to content

Commit

Permalink
Merge branch 'serialport'
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBowman committed Nov 24, 2022
2 parents 760c414 + b439993 commit e65ada4
Show file tree
Hide file tree
Showing 17 changed files with 193 additions and 368 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ install:
Start-FileDownload "$env:YARP_DOWNLOAD_URL" -FileName "$env:DOWNLOADS_PATH\yarp.zip"
7z x -y -o"$env:DOWNLOADS_PATH" "$env:DOWNLOADS_PATH\yarp.zip"
$env:yarp_temp = "$env:DOWNLOADS_PATH\yarp-$env:YARP_LATEST"
cmake -H"$env:yarp_temp" -B"$env:yarp_temp\build" -A"$env:PLATFORM" -DCMAKE_INSTALL_PREFIX:PATH=C:\YARP
cmake -H"$env:yarp_temp" -B"$env:yarp_temp\build" -A"$env:PLATFORM" -DCMAKE_INSTALL_PREFIX:PATH=C:\YARP -DENABLE_yarpmod_serialport:BOOL=ON
cmake --build "$env:yarp_temp\build" --config "$env:CONFIGURATION" --target INSTALL -- /m /v:m
Set-Content C:\YARP\.version "$env:YARP_LATEST"
}
Expand Down
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ cache:
addons:
apt:
packages:
# device deps
- libserial-dev
- libboost-dev # libserial-dev dependency (packaging bug on Xenial and later)
- swig # bindings
- lcov # code coverage

Expand Down Expand Up @@ -72,7 +69,7 @@ install:
--package-name YARP
--repo-url https://github.com/robotology/yarp
--repo-checkout "${ROBOTOLOGY_CHECKOUT:-$YARP_CHECKOUT}"
--additional-cmake-options "-DSKIP_ACE:BOOL=ON"
--additional-cmake-options "-DENABLE_yarpmod_serialport:BOOL=ON"
--prepend-to-linker-path lib
--additional-export-paths "YARP_DATA_DIRS;share/yarp"
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ find_package(YCM 0.11 REQUIRED)
find_package(YARP 3.5 REQUIRED COMPONENTS os dev)

# Soft dependencies.
find_package(LibSerial 0.6 QUIET)
find_package(wiringPi QUIET)
find_package(SWIG 3.0.12 QUIET)
find_package(Doxygen QUIET)
Expand Down
48 changes: 0 additions & 48 deletions cmake/find-modules/FindLibSerial.cmake

This file was deleted.

3 changes: 0 additions & 3 deletions doc/yarp-devices-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ mkdir -p repos && cd repos # make $HOME/repos if it doesn't exist; then, enter
git clone https://github.com/asrob-uc3m/wiringPi # Mirror of defunct git://git.drogon.net/wiringPi
cd wiringPi
./build # May require sudo
# libserial required for several devices
sudo apt install --no-install-recommends libboost-dev # libserial, next, requires boost/scoped_ptr.hpp
sudo apt install libserial-dev
# Now our repo
git clone https://github.com/asrob-uc3m/yarp-devices.git # Download yarp-devices software from the repository
mkdir -p yarp-devices/build && cd yarp-devices/build && cmake .. # Configure the yarp-devices software
Expand Down
12 changes: 1 addition & 11 deletions libraries/YarpPlugins/EcroPwmController/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
# CopyPolicy: released under the terms of the LGPLv2.1, see LICENSE at project root.
# URL: https://github.com/asrob-uc3m/yarp-devices

if(NOT LibSerial_FOUND AND (NOT DEFINED ENABLE_EcroPwmController OR ENABLE_EcroPwmController))
message(WARNING "LibSerial package not found, disabling EcroPwmController device")
endif()

yarp_prepare_plugin(EcroPwmController
CATEGORY device
TYPE asrob::EcroPwmController
INCLUDE EcroPwmController.hpp
EXTRA_CONFIG WRAPPER=RobotServer
DEFAULT ${_rd_packaging_defaults}
DEPENDS LibSerial_FOUND)
DEFAULT ${_rd_packaging_defaults})

if(NOT SKIP_EcroPwmController)

Expand All @@ -24,16 +19,11 @@ if(NOT SKIP_EcroPwmController)

target_link_libraries(EcroPwmController YARP::YARP_os
YARP::YARP_dev
LibSerial::serial
ASROB::RobotInterfaces)

yarp_install(TARGETS EcroPwmController
LIBRARY DESTINATION ${ASROB-YARP-DEVICES_DYNAMIC_PLUGINS_INSTALL_DIR}
ARCHIVE DESTINATION ${ASROB-YARP-DEVICES_STATIC_PLUGINS_INSTALL_DIR}
YARP_INI DESTINATION ${ASROB-YARP-DEVICES_PLUGIN_MANIFESTS_INSTALL_DIR})

else()

set(ENABLE_EcroPwmController OFF CACHE BOOL "Enable/disable EcroPwmController device" FORCE)

endif()
37 changes: 16 additions & 21 deletions libraries/YarpPlugins/EcroPwmController/DeviceDriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "EcroPwmController.hpp"

#include <yarp/os/LogStream.h>
#include <yarp/os/Property.h>

#include "LogComponent.hpp"

Expand All @@ -12,38 +13,32 @@ constexpr auto DEFAULT_SERIAL_PORT_NAME = "/dev/ttyUSB0";

bool EcroPwmController::open(yarp::os::Searchable& config)
{
std::string serialPortName = config.check("serialPortName", yarp::os::Value(DEFAULT_SERIAL_PORT_NAME), "serialPortName").asString();
auto serialPortName = config.check("serialPortName", yarp::os::Value(DEFAULT_SERIAL_PORT_NAME), "serialPortName").asString();

yCInfo(EPC) << "EcroPwmController options:";
yCInfo(EPC) << "--serialPortName" << serialPortName;
yarp::os::Property serialDeviceOptions {
{"device", yarp::os::Value("serialport")},
{"comport", yarp::os::Value(serialPortName)},
{"baudrate", yarp::os::Value(57600)},
{"paritymode", yarp::os::Value("NONE")},
{"databits", yarp::os::Value(8)}
};

yCDebug(EPC) << "Init Serial Port";
serialPort = new SerialPort(serialPortName); // "/dev/ttyUSB0"

try
if (!serialDevice.open(serialDeviceOptions))
{
serialPort->Open(SerialPort::BAUD_57600, SerialPort::CHAR_SIZE_8,
SerialPort::PARITY_NONE, SerialPort::STOP_BITS_1,
SerialPort::FLOW_CONTROL_NONE);
yCError(EPC) << "Could not open serial device";
return false;
}
catch (SerialPort::OpenFailed e)

if (!serialDevice.view(serial))
{
yCError(EPC) << "Error opening the serial port" << serialPortName;
yCError(EPC) << "Could not view serial interface";
return false;
}

yCInfo(EPC) << "Ok Serial Port:" << serialPortName << "(without check)";

leftMotorVelocity = leftMotorInitial;
rightMotorVelocity = rightMotorInitial;

return true;
}

bool EcroPwmController::close()
{
serialPort->Close();
delete serialPort;
serialPort = nullptr;
return true;
return serialDevice.close();
}
26 changes: 14 additions & 12 deletions libraries/YarpPlugins/EcroPwmController/EcroPwmController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@

using namespace asrob;

constexpr int leftMotorRangeMin = 0;
constexpr int leftMotorRangeMax = 90;

constexpr int rightMotorRangeMin = 0;
constexpr int rightMotorRangeMax = 90;

constexpr int leftMotorOffset = 90;
constexpr int rightMotorOffset = 90;

bool EcroPwmController::moveForward(double value)
{
yCDebug(EPC) << "moveForward" << value;
Expand Down Expand Up @@ -67,20 +76,13 @@ bool EcroPwmController::stopCameraMovement()

bool EcroPwmController::sendCurrentJointValues()
{
if (serialPort->IsOpen())
{
SerialPort::DataBuffer outputBuff;
outputBuff.push_back(0x50); //-- 0x50 -> Set pos to all joints
char msg[] = {0x50, static_cast<char>(leftMotorVelocity), static_cast<char>(rightMotorVelocity)};

outputBuff.push_back((char) leftMotorVelocity);
outputBuff.push_back((char) rightMotorVelocity);
serialPort->Write( outputBuff );

return true;
}
else
if (!serial->send(msg, sizeof(msg)))
{
yCWarning(EPC) << "Robot could not send joints (because it is not connected)";
yCError(EPC) << "Error sending message";
return false;
}

return true;
}
21 changes: 6 additions & 15 deletions libraries/YarpPlugins/EcroPwmController/EcroPwmController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#define __ECRO_PWM_CONTROLLER__

#include <yarp/dev/DeviceDriver.h>

#include <SerialStream.h>
#include <yarp/dev/ISerialDevice.h>
#include <yarp/dev/PolyDriver.h>

#include "IRobotManager.hpp"

Expand Down Expand Up @@ -37,22 +37,13 @@ class EcroPwmController : public yarp::dev::DeprecatedDeviceDriver,
bool close() override;

private:
SerialPort * serialPort;
bool sendCurrentJointValues();

int leftMotorVelocity;
int rightMotorVelocity;

static const int leftMotorRangeMin = 0;
static const int leftMotorRangeMax = 90;
static const int leftMotorInitial = 0;

static const int rightMotorRangeMin = 0;
static const int rightMotorRangeMax = 90;
static const int rightMotorInitial = 0;
yarp::dev::PolyDriver serialDevice;
yarp::dev::ISerialDevice * serial;

static const int leftMotorOffset = 90;
static const int rightMotorOffset = 90;
int leftMotorVelocity {0};
int rightMotorVelocity {0};
};

} // namespace asrob
Expand Down
12 changes: 1 addition & 11 deletions libraries/YarpPlugins/EcroWheelController/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@
# CopyPolicy: released under the terms of the LGPLv2.1, see LICENSE at project root.
# URL: https://github.com/asrob-uc3m/yarp-devices

if(NOT LibSerial_FOUND AND (NOT DEFINED ENABLE_EcroWheelController OR ENABLE_EcroWheelController))
message(WARNING "LibSerial package not found, disabling EcroWheelController device")
endif()

yarp_prepare_plugin(EcroWheelController
CATEGORY device
TYPE asrob::EcroWheelController
INCLUDE EcroWheelController.hpp
EXTRA_CONFIG WRAPPER=RobotServer
DEFAULT ${_rd_packaging_defaults}
DEPENDS LibSerial_FOUND)
DEFAULT ${_rd_packaging_defaults})

if(NOT SKIP_EcroWheelController)

Expand All @@ -24,16 +19,11 @@ if(NOT SKIP_EcroWheelController)

target_link_libraries(EcroWheelController YARP::YARP_os
YARP::YARP_dev
LibSerial::serial
ASROB::RobotInterfaces)

yarp_install(TARGETS EcroWheelController
LIBRARY DESTINATION ${ASROB-YARP-DEVICES_DYNAMIC_PLUGINS_INSTALL_DIR}
ARCHIVE DESTINATION ${ASROB-YARP-DEVICES_STATIC_PLUGINS_INSTALL_DIR}
YARP_INI DESTINATION ${ASROB-YARP-DEVICES_PLUGIN_MANIFESTS_INSTALL_DIR})

else()

set(ENABLE_EcroWheelController OFF CACHE BOOL "Enable/disable EcroWheelController device" FORCE)

endif()
49 changes: 18 additions & 31 deletions libraries/YarpPlugins/EcroWheelController/DeviceDriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "EcroWheelController.hpp"

#include <yarp/os/LogStream.h>
#include <yarp/os/Time.h>
#include <yarp/os/Property.h>

#include "LogComponent.hpp"

Expand All @@ -15,41 +15,31 @@ constexpr auto DEFAULT_SERIAL_PORT_NAME = "/dev/ttyUSB0";

bool EcroWheelController::open(yarp::os::Searchable& config)
{
std::string serialPortName = config.check("serialPortName", yarp::os::Value(DEFAULT_SERIAL_PORT_NAME), "serialPortName").asString();
auto serialPortName = config.check("serialPortName", yarp::os::Value(DEFAULT_SERIAL_PORT_NAME), "serialPortName").asString();

yCInfo(EWC) << "EcroWheelController options:";
yCInfo(EWC) << "--serialPortName" << serialPortName;
yarp::os::Property serialDeviceOptions {
{"device", yarp::os::Value("serialport")},
{"comport", yarp::os::Value(serialPortName)},
{"baudrate", yarp::os::Value(19200)},
{"paritymode", yarp::os::Value("NONE")},
{"databits", yarp::os::Value(8)}
};

yCDebug(EWC) << "Init Serial Port";
serialPort = new SerialPort(serialPortName); // "/dev/ttyUSB0"

try
{
serialPort->Open(SerialPort::BAUD_19200, SerialPort::CHAR_SIZE_8,
SerialPort::PARITY_NONE, SerialPort::STOP_BITS_1,
SerialPort::FLOW_CONTROL_NONE);
}
catch (SerialPort::OpenFailed e)
if (!serialDevice.open(serialDeviceOptions))
{
yCError(EWC) << "Error opening the serial port" << serialPortName;
yCError(EWC) << "Could not open serial device";
return false;
}

if (serialPort->IsOpen())
if (!serialDevice.view(serial))
{
SerialPort::DataBuffer outputBuff;
outputBuff.push_back(0x32); // Invert motor 1
serialPort->Write( outputBuff );
yarp::os::Time::delay(0.5);

outputBuff.clear();
outputBuff.push_back(0x28); // Este ambos, 29 limpiaria 1, 30 el 2 ?
serialPort->Write( outputBuff );
yarp::os::Time::delay(0.5);
yCError(EWC) << "Could not view serial interface";
return false;
}
else

if (!stopMovement())
{
yWarning(EWC) << "Robot could not revert wheel command (because it is not connected)";
yCError(EWC) << "Could not stop movement during initial config";
return false;
}

Expand All @@ -58,8 +48,5 @@ bool EcroWheelController::open(yarp::os::Searchable& config)

bool EcroWheelController::close()
{
serialPort->Close();
delete serialPort;
serialPort = nullptr;
return true;
return serialDevice.close();
}
Loading

0 comments on commit e65ada4

Please sign in to comment.