Skip to content

Commit

Permalink
Tweak moar config params, clean stuff in DeviceDriver::open
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBowman committed Nov 28, 2019
1 parent d8c5f85 commit b752d18
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

#define CHECK_JOINT(j) do { int n = deviceMapper.getControlledAxes(); if ((j) < 0 || (j) > n - 1) return false; } while (0)

#define DEFAULT_MODE "position"
#define DEFAULT_CUI_TIMEOUT 1.0
#define DEFAULT_CAN_BUS "CanBusHico"
#define DEFAULT_LIN_INTERP_PERIOD_MS 50
#define DEFAULT_LIN_INTERP_BUFFER_SIZE 1
#define DEFAULT_LIN_INTERP_MODE "pt"
Expand All @@ -28,8 +25,8 @@
#define DEFAULT_CAN_TX_BUFFER_SIZE 500
#define DEFAULT_CAN_RX_PERIOD_MS -1
#define DEFAULT_CAN_TX_PERIOD_MS 1.0
#define DEFAULT_CAN_SDO_TIMEOUT_MS 25.0
#define DEFAULT_CAN_DRIVE_STATE_TIMEOUT 2.5
#define DEFAULT_CAN_SDO_TIMEOUT_MS 25.0 // FIXME unused
#define DEFAULT_CAN_DRIVE_STATE_TIMEOUT 2.5 // FIXME unused

namespace roboticslab
{
Expand Down
47 changes: 25 additions & 22 deletions libraries/YarpPlugins/CanBusControlboard/DeviceDriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ bool CanBusControlboard::open(yarp::os::Searchable & config)
return false;
}

std::string bus = config.find("bus").asString();
std::string canBus = config.find("bus").asString();
yarp::os::Bottle * nodes = config.find("nodes").asList();

if (bus.empty() || nodes == nullptr)
if (canBus.empty() || nodes == nullptr)
{
CD_ERROR("Illegal key(s): empty \"bus\" or nullptr \"nodes\".\n");
return false;
}

yarp::os::Bottle & canBusGroup = config.findGroup(bus);
yarp::os::Bottle & canBusGroup = config.findGroup(canBus);

if (canBusGroup.isNull())
{
CD_ERROR("Missing CAN bus device group %s.\n", bus.c_str());
CD_ERROR("Missing CAN bus device group %s.\n", canBus.c_str());
return false;
}

Expand All @@ -42,7 +42,7 @@ bool CanBusControlboard::open(yarp::os::Searchable & config)
canBusOptions.fromString(config.toString(), false);
canBusOptions.put("canBlockingMode", false); // enforce non-blocking mode
canBusOptions.put("canAllowPermissive", false); // always check usage requirements
canBusOptions.setMonitor(config.getMonitor(), bus.c_str());
canBusOptions.setMonitor(config.getMonitor(), canBus.c_str());

if (!canBusDevice.open(canBusOptions))
{
Expand All @@ -52,29 +52,32 @@ bool CanBusControlboard::open(yarp::os::Searchable & config)

if (!canBusDevice.view(iCanBus))
{
CD_ERROR("Cannot view ICanBus interface in device: %s.\n", bus.c_str());
CD_ERROR("Cannot view ICanBus interface in device: %s.\n", canBus.c_str());
return false;
}

yarp::dev::ICanBufferFactory * iCanBufferFactory;

if (!canBusDevice.view(iCanBufferFactory))
{
CD_ERROR("Cannot view ICanBufferFactory interface in device: %s.\n", bus.c_str());
CD_ERROR("Cannot view ICanBufferFactory interface in device: %s.\n", canBus.c_str());
return false;
}

iCanBusSharers.resize(nodes->size());

int cuiTimeout = config.check("waitEncoder", yarp::os::Value(DEFAULT_CUI_TIMEOUT), "CUI timeout (seconds)").asInt32();

std::string canBusType = config.check("canBusType", yarp::os::Value(DEFAULT_CAN_BUS), "CAN bus device name").asString();
int canRxBufferSize = config.check("canBusRxBufferSize", yarp::os::Value(DEFAULT_CAN_RX_BUFFER_SIZE), "CAN bus RX buffer size").asInt();
int canTxBufferSize = config.check("canBusTxBufferSize", yarp::os::Value(DEFAULT_CAN_TX_BUFFER_SIZE), "CAN bus TX buffer size").asInt();
double canRxPeriodMs = config.check("canRxPeriodMs", yarp::os::Value(DEFAULT_CAN_RX_PERIOD_MS), "CAN bus RX period (milliseconds)").asFloat64();
double canTxPeriodMs = config.check("canTxPeriodMs", yarp::os::Value(DEFAULT_CAN_TX_PERIOD_MS), "CAN bus TX period (milliseconds)").asFloat64();
double canSdoTimeoutMs = config.check("canSdoTimeoutMs", yarp::os::Value(DEFAULT_CAN_SDO_TIMEOUT_MS), "CAN bus SDO timeout (milliseconds)").asFloat64();
double canDriveStateTimeout = config.check("canDriveStateTimeout", yarp::os::Value(DEFAULT_CAN_DRIVE_STATE_TIMEOUT), "CAN drive state timeout (seconds)").asFloat64();

canReaderThread = new CanReaderThread(canBus, iCanBusSharers);
canReaderThread->setCanHandles(iCanBus, iCanBufferFactory, canRxBufferSize);
canReaderThread->setPeriod(canRxPeriodMs);

canWriterThread = new CanWriterThread(canBus);
canWriterThread->setCanHandles(iCanBus, iCanBufferFactory, canTxBufferSize);
canWriterThread->setPeriod(canTxPeriodMs);

linInterpPeriodMs = config.check("linInterpPeriodMs", yarp::os::Value(DEFAULT_LIN_INTERP_PERIOD_MS), "linear interpolation mode period (milliseconds)").asInt32();
linInterpBufferSize = config.check("linInterpBufferSize", yarp::os::Value(DEFAULT_LIN_INTERP_BUFFER_SIZE), "linear interpolation mode buffer size").asInt32();
Expand Down Expand Up @@ -133,17 +136,17 @@ bool CanBusControlboard::open(yarp::os::Searchable & config)
}
}

const std::string canDevice = canBusOptions.find("canDevice").asString();

canReaderThread = new CanReaderThread(canDevice, iCanBusSharers);
canReaderThread->setCanHandles(iCanBus, iCanBufferFactory, canRxBufferSize);
canReaderThread->setPeriod(canRxPeriodMs);
canReaderThread->start();
if (!canReaderThread->start())
{
CD_ERROR("Unable to start reader thread.\n");
return false;
}

canWriterThread = new CanWriterThread(canDevice);
canWriterThread->setCanHandles(iCanBus, iCanBufferFactory, canTxBufferSize);
canWriterThread->setPeriod(canTxPeriodMs);
canWriterThread->start();
if (!canWriterThread->start())
{
CD_ERROR("Unable to start writer thread.\n");
return false;
}

for (auto p : iCanBusSharers)
{
Expand Down
22 changes: 11 additions & 11 deletions libraries/YarpPlugins/CanBusHico/CanBusHico.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
#include "hico_api.h"
#include "HicoCanMessage.hpp"

#define DEFAULT_CAN_DEVICE "/dev/can0"
#define DEFAULT_CAN_BITRATE 1000000
#define DEFAULT_PORT "/dev/can0"
#define DEFAULT_BITRATE 1000000

#define DEFAULT_CAN_RX_TIMEOUT_MS 1
#define DEFAULT_CAN_TX_TIMEOUT_MS 0 // '0' means no timeout
#define DEFAULT_RX_TIMEOUT_MS 1
#define DEFAULT_TX_TIMEOUT_MS 0 // '0' means no timeout

#define DEFAULT_CAN_BLOCKING_MODE true
#define DEFAULT_CAN_ALLOW_PERMISSIVE false
#define DEFAULT_BLOCKING_MODE true
#define DEFAULT_ALLOW_PERMISSIVE false

#define DELAY 0.001 // [s]

#define DEFAULT_CAN_FILTER_CONFIGURATION "disabled"
#define DEFAULT_FILTER_CONFIGURATION "disabled"

namespace roboticslab
{
Expand All @@ -51,10 +51,10 @@ class CanBusHico : public yarp::dev::DeviceDriver,
public:

CanBusHico() : fileDescriptor(0),
rxTimeoutMs(DEFAULT_CAN_RX_TIMEOUT_MS),
txTimeoutMs(DEFAULT_CAN_TX_TIMEOUT_MS),
blockingMode(DEFAULT_CAN_BLOCKING_MODE),
allowPermissive(DEFAULT_CAN_ALLOW_PERMISSIVE),
rxTimeoutMs(DEFAULT_RX_TIMEOUT_MS),
txTimeoutMs(DEFAULT_TX_TIMEOUT_MS),
blockingMode(DEFAULT_BLOCKING_MODE),
allowPermissive(DEFAULT_ALLOW_PERMISSIVE),
filterManager(NULL),
filterConfig(FilterManager::DISABLED)
{}
Expand Down
14 changes: 7 additions & 7 deletions libraries/YarpPlugins/CanBusHico/DeviceDriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@

bool roboticslab::CanBusHico::open(yarp::os::Searchable& config)
{
std::string devicePath = config.check("canDevice", yarp::os::Value(DEFAULT_CAN_DEVICE), "CAN device path").asString();
int bitrate = config.check("canBitrate", yarp::os::Value(DEFAULT_CAN_BITRATE), "CAN bitrate (bps)").asInt32();
std::string devicePath = config.check("port", yarp::os::Value(DEFAULT_PORT), "CAN device path").asString();
int bitrate = config.check("bitrate", yarp::os::Value(DEFAULT_BITRATE), "CAN bitrate (bps)").asInt32();

blockingMode = config.check("canBlockingMode", yarp::os::Value(DEFAULT_CAN_BLOCKING_MODE), "CAN blocking mode enabled").asBool();
allowPermissive = config.check("canAllowPermissive", yarp::os::Value(DEFAULT_CAN_ALLOW_PERMISSIVE), "CAN read/write permissive mode").asBool();
blockingMode = config.check("blockingMode", yarp::os::Value(DEFAULT_BLOCKING_MODE), "CAN blocking mode enabled").asBool();
allowPermissive = config.check("allowPermissive", yarp::os::Value(DEFAULT_ALLOW_PERMISSIVE), "CAN read/write permissive mode").asBool();

if (blockingMode)
{
CD_INFO("Blocking mode enabled for CAN device: %s.\n", devicePath.c_str());

rxTimeoutMs = config.check("canRxTimeoutMs", yarp::os::Value(DEFAULT_CAN_RX_TIMEOUT_MS), "CAN RX timeout (milliseconds)").asInt32();
txTimeoutMs = config.check("canTxTimeoutMs", yarp::os::Value(DEFAULT_CAN_TX_TIMEOUT_MS), "CAN TX timeout (milliseconds)").asInt32();
rxTimeoutMs = config.check("rxTimeoutMs", yarp::os::Value(DEFAULT_RX_TIMEOUT_MS), "CAN RX timeout (milliseconds)").asInt32();
txTimeoutMs = config.check("txTimeoutMs", yarp::os::Value(DEFAULT_TX_TIMEOUT_MS), "CAN TX timeout (milliseconds)").asInt32();

if (rxTimeoutMs <= 0)
{
Expand All @@ -49,7 +49,7 @@ bool roboticslab::CanBusHico::open(yarp::os::Searchable& config)

CD_INFO("Permissive mode flag for read/write operations on CAN device %s: %d.\n", devicePath.c_str(), allowPermissive);

std::string filterConfigStr = config.check("canFilterConfiguration", yarp::os::Value(DEFAULT_CAN_FILTER_CONFIGURATION),
std::string filterConfigStr = config.check("filterConfiguration", yarp::os::Value(DEFAULT_FILTER_CONFIGURATION),
"CAN filter configuration (disabled|noRange|maskAndRange)").asString();

CD_INFO("CAN filter configuration for CAN device %s: %s.\n", devicePath.c_str(), filterConfigStr.c_str());
Expand Down
20 changes: 10 additions & 10 deletions libraries/YarpPlugins/CanBusPeak/CanBusPeak.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

#include "PeakCanMessage.hpp"

#define DEFAULT_CAN_DEVICE "/dev/pcan0"
#define DEFAULT_CAN_BITRATE 1000000
#define DEFAULT_PORT "/dev/pcan0"
#define DEFAULT_BITRATE 1000000

#define DEFAULT_CAN_RX_TIMEOUT_MS 1
#define DEFAULT_CAN_TX_TIMEOUT_MS 0 // '0' means no timeout
#define DEFAULT_RX_TIMEOUT_MS 1
#define DEFAULT_TX_TIMEOUT_MS 0 // '0' means no timeout

#define DEFAULT_CAN_BLOCKING_MODE true
#define DEFAULT_CAN_ALLOW_PERMISSIVE false
#define DEFAULT_BLOCKING_MODE true
#define DEFAULT_ALLOW_PERMISSIVE false

namespace roboticslab
{
Expand Down Expand Up @@ -76,10 +76,10 @@ class CanBusPeak : public yarp::dev::DeviceDriver,
public:

CanBusPeak() : fileDescriptor(0),
rxTimeoutMs(DEFAULT_CAN_RX_TIMEOUT_MS),
txTimeoutMs(DEFAULT_CAN_TX_TIMEOUT_MS),
blockingMode(DEFAULT_CAN_BLOCKING_MODE),
allowPermissive(DEFAULT_CAN_ALLOW_PERMISSIVE)
rxTimeoutMs(DEFAULT_RX_TIMEOUT_MS),
txTimeoutMs(DEFAULT_TX_TIMEOUT_MS),
blockingMode(DEFAULT_BLOCKING_MODE),
allowPermissive(DEFAULT_ALLOW_PERMISSIVE)
{}

// --------- DeviceDriver declarations. Implementation in DeviceDriverImpl.cpp ---------
Expand Down
12 changes: 6 additions & 6 deletions libraries/YarpPlugins/CanBusPeak/DeviceDriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@

bool roboticslab::CanBusPeak::open(yarp::os::Searchable& config)
{
std::string devicePath = config.check("canDevice", yarp::os::Value(DEFAULT_CAN_DEVICE), "CAN device path").asString();
std::string devicePath = config.check("port", yarp::os::Value(DEFAULT_PORT), "CAN device path").asString();

int bitrate = config.check("canBitrate", yarp::os::Value(DEFAULT_CAN_BITRATE), "CAN bitrate (bps)").asInt32();
int bitrate = config.check("bitrate", yarp::os::Value(DEFAULT_BITRATE), "CAN bitrate (bps)").asInt32();

blockingMode = config.check("canBlockingMode", yarp::os::Value(DEFAULT_CAN_BLOCKING_MODE), "CAN blocking mode enabled").asBool();
allowPermissive = config.check("canAllowPermissive", yarp::os::Value(DEFAULT_CAN_ALLOW_PERMISSIVE), "CAN read/write permissive mode").asBool();
blockingMode = config.check("blockingMode", yarp::os::Value(DEFAULT_BLOCKING_MODE), "blocking mode enabled").asBool();
allowPermissive = config.check("allowPermissive", yarp::os::Value(DEFAULT_ALLOW_PERMISSIVE), "read/write permissive mode").asBool();

int flags = OFD_BITRATE | PCANFD_INIT_STD_MSG_ONLY;

if (blockingMode)
{
CD_INFO("Blocking mode enabled for CAN device: %s.\n", devicePath.c_str());

rxTimeoutMs = config.check("canRxTimeoutMs", yarp::os::Value(DEFAULT_CAN_RX_TIMEOUT_MS), "RX timeout (milliseconds)").asInt32();
txTimeoutMs = config.check("canTxTimeoutMs", yarp::os::Value(DEFAULT_CAN_TX_TIMEOUT_MS), "TX timeout (milliseconds)").asInt32();
rxTimeoutMs = config.check("rxTimeoutMs", yarp::os::Value(DEFAULT_RX_TIMEOUT_MS), "RX timeout (milliseconds)").asInt32();
txTimeoutMs = config.check("txTimeoutMs", yarp::os::Value(DEFAULT_TX_TIMEOUT_MS), "TX timeout (milliseconds)").asInt32();

if (rxTimeoutMs <= 0)
{
Expand Down
6 changes: 3 additions & 3 deletions libraries/YarpPlugins/TechnosoftIpos/DeviceDriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ bool TechnosoftIpos::open(yarp::os::Searchable & config)
vars.actualControlMode = VOCAB_CM_NOT_CONFIGURED;

// immutable variables
vars.drivePeakCurrent = driverGroup.check("drivePeakCurrent", yarp::os::Value(0.0), "peak drive current (amperes)").asFloat64();
vars.drivePeakCurrent = driverGroup.check("peakCurrent", yarp::os::Value(0.0), "peak drive current (amperes)").asFloat64();
vars.maxVel = config.check("maxVel", yarp::os::Value(0.0), "maxVel (meters/second or degrees/second)").asFloat64();
vars.axisName = config.check("axisName", yarp::os::Value(""), "axis name").asString();
vars.jointType = config.check("jointType", yarp::os::Value(yarp::dev::VOCAB_JOINTTYPE_UNKNOWN), "joint type [atrv|atpr|unkn]").asVocab();
vars.axisName = config.check("name", yarp::os::Value(""), "axis name").asString();
vars.jointType = config.check("type", yarp::os::Value(yarp::dev::VOCAB_JOINTTYPE_UNKNOWN), "joint type [atrv|atpr|unkn]").asVocab();
vars.reverse = config.check("reverse", yarp::os::Value(false), "reverse motor encoder counts").asBool();
vars.min = config.check("min", yarp::os::Value(0.0), "min (meters or degrees)").asFloat64();
vars.max = config.check("max", yarp::os::Value(0.0), "max (meters or degrees)").asFloat64();
Expand Down

0 comments on commit b752d18

Please sign in to comment.