Skip to content
Snippets Groups Projects
Commit c50a6037 authored by Fabian Paus's avatar Fabian Paus
Browse files

Hokuyo: Implemented using the URG driver (added dummy implementation)

parent 2507da1c
No related branches found
No related tags found
No related merge requests found
Showing
with 619 additions and 19 deletions
<?xml version="1.0" encoding="utf-8"?>
<scenario name="LaserScannerTest" lastChange="2017-03-07.16:53:44" creation="2017-03-07.16:12:47" globalConfigName="./config/global.cfg" package="RobotAPI">
<application name="HokuyoLaserUnitApp" instance="" package="RobotAPI"/>
<application name="LaserScannerUnitObserverApp" instance="" package="RobotAPI"/>
</scenario>
# ==================================================================
# HokuyoLaserUnitApp properties
# ==================================================================
# ArmarX.AdditionalPackages: List of additional ArmarX packages which should be in the list of default packages. If you have custom packages, which should be found by the gui or other apps, specify them here. Comma separated List.
# Attributes:
# - Default: Default value not mapped.
# - Case sensitivity: no
# - Required: no
# ArmarX.AdditionalPackages = Default value not mapped.
# ArmarX.ApplicationName: Application name
# Attributes:
# - Default: ""
# - Case sensitivity: no
# - Required: no
# ArmarX.ApplicationName = ""
# ArmarX.CachePath: Path for cache files
# Attributes:
# - Default: ${HOME}/.armarx/mongo/.cache
# - Case sensitivity: no
# - Required: no
# ArmarX.CachePath = ${HOME}/.armarx/mongo/.cache
# ArmarX.Config: Comma-separated list of configuration files
# Attributes:
# - Default: ""
# - Case sensitivity: no
# - Required: no
# ArmarX.Config = ""
# ArmarX.DataPath: Semicolon-separated search list for data files
# Attributes:
# - Default: ""
# - Case sensitivity: no
# - Required: no
# ArmarX.DataPath = ""
# ArmarX.DefaultPackages: List of ArmarX packages which are accessible by default. Comma separated List. If you want to add your own packages and use all default ArmarX packages, use the property 'AdditionalPackages'.
# Attributes:
# - Default: Default value not mapped.
# - Case sensitivity: no
# - Required: no
# ArmarX.DefaultPackages = Default value not mapped.
# ArmarX.DependenciesConfig: Path to the (usually generated) config file containing all data paths of all dependent projects. This property usually does not need to be edited.
# Attributes:
# - Default: ./config/dependencies.cfg
# - Case sensitivity: no
# - Required: no
# ArmarX.DependenciesConfig = ./config/dependencies.cfg
# ArmarX.DisableLogging: Turn logging off in whole application
# Attributes:
# - Default: 0
# - Case sensitivity: no
# - Required: no
# ArmarX.DisableLogging = 0
# ArmarX.EnableProfiling: Enable profiling of CPU load produced by this application
# Attributes:
# - Default: 0
# - Case sensitivity: no
# - Required: no
# ArmarX.EnableProfiling = 0
# ArmarX.HokuyoLaserUnit.Devices: List of devices in form of 'IP1,port1;IP2,port2;...'
# Attributes:
# - Default: ""
# - Case sensitivity: no
# - Required: no
ArmarX.HokuyoLaserUnit.Devices = "Dummy1,100"
# ArmarX.HokuyoLaserUnit.EnableProfiling: enable profiler which is used for logging performance events
# Attributes:
# - Default: 0
# - Case sensitivity: no
# - Required: no
# ArmarX.HokuyoLaserUnit.EnableProfiling = 0
# ArmarX.HokuyoLaserUnit.LaserScannerTopicName: Name of the laser scan topic.
# Attributes:
# - Default: LaserScans
# - Case sensitivity: no
# - Required: no
# ArmarX.HokuyoLaserUnit.LaserScannerTopicName = LaserScans
# ArmarX.HokuyoLaserUnit.MinimumLoggingLevel: Local logging level only for this component
# Attributes:
# - Default: Undefined
# - Case sensitivity: no
# - Required: no
# ArmarX.HokuyoLaserUnit.MinimumLoggingLevel = Undefined
# ArmarX.HokuyoLaserUnit.ObjectName: Name of IceGrid well-known object
# Attributes:
# - Default: ""
# - Case sensitivity: no
# - Required: no
# ArmarX.HokuyoLaserUnit.ObjectName = ""
# ArmarX.HokuyoLaserUnit.UpdatePeriod: Update period for laser scans
# Attributes:
# - Default: 25
# - Case sensitivity: no
# - Required: no
# ArmarX.HokuyoLaserUnit.UpdatePeriod = 25
# ArmarX.RedirectStdout: Redirect std::cout and std::cerr to ArmarXLog
# Attributes:
# - Default: 1
# - Case sensitivity: no
# - Required: no
# ArmarX.RedirectStdout = 1
# ArmarX.RemoteHandlesDeletionTimeout: The timeout (in ms) before a remote handle deletes the managed object after the use count reached 0. This time can be used by a client to increment the count again (may be required when transmitting remote handles)
# Attributes:
# - Default: 3000
# - Case sensitivity: no
# - Required: no
# ArmarX.RemoteHandlesDeletionTimeout = 3000
# ArmarX.StartDebuggerOnCrash: If this application crashes (segmentation fault) qtcreator will attach to this process and start the debugger.
# Attributes:
# - Default: 0
# - Case sensitivity: no
# - Required: no
# ArmarX.StartDebuggerOnCrash = 0
# ArmarX.TopicSuffix: Suffix appended to all topic names for outgoing topics. This is mainly used to direct all topics to another name for TopicReplaying purposes.
# Attributes:
# - Default: ""
# - Case sensitivity: no
# - Required: no
# ArmarX.TopicSuffix = ""
# ArmarX.UseTimeServer: Enable using a global Timeserver (e.g. from ArmarXSimulator)
# Attributes:
# - Default: 0
# - Case sensitivity: no
# - Required: no
# ArmarX.UseTimeServer = 0
# ArmarX.Verbosity: Global logging level for whole application
# Attributes:
# - Default: Info
# - Case sensitivity: no
# - Required: no
# ArmarX.Verbosity = Info
# ==================================================================
# LaserScannerUnitObserverApp properties
# ==================================================================
# ArmarX.AdditionalPackages: List of additional ArmarX packages which should be in the list of default packages. If you have custom packages, which should be found by the gui or other apps, specify them here. Comma separated List.
# Attributes:
# - Default: Default value not mapped.
# - Case sensitivity: no
# - Required: no
# ArmarX.AdditionalPackages = Default value not mapped.
# ArmarX.ApplicationName: Application name
# Attributes:
# - Default: ""
# - Case sensitivity: no
# - Required: no
# ArmarX.ApplicationName = ""
# ArmarX.CachePath: Path for cache files
# Attributes:
# - Default: ${HOME}/.armarx/mongo/.cache
# - Case sensitivity: no
# - Required: no
# ArmarX.CachePath = ${HOME}/.armarx/mongo/.cache
# ArmarX.Config: Comma-separated list of configuration files
# Attributes:
# - Default: ""
# - Case sensitivity: no
# - Required: no
# ArmarX.Config = ""
# ArmarX.DataPath: Semicolon-separated search list for data files
# Attributes:
# - Default: ""
# - Case sensitivity: no
# - Required: no
# ArmarX.DataPath = ""
# ArmarX.DefaultPackages: List of ArmarX packages which are accessible by default. Comma separated List. If you want to add your own packages and use all default ArmarX packages, use the property 'AdditionalPackages'.
# Attributes:
# - Default: Default value not mapped.
# - Case sensitivity: no
# - Required: no
# ArmarX.DefaultPackages = Default value not mapped.
# ArmarX.DependenciesConfig: Path to the (usually generated) config file containing all data paths of all dependent projects. This property usually does not need to be edited.
# Attributes:
# - Default: ./config/dependencies.cfg
# - Case sensitivity: no
# - Required: no
# ArmarX.DependenciesConfig = ./config/dependencies.cfg
# ArmarX.DisableLogging: Turn logging off in whole application
# Attributes:
# - Default: 0
# - Case sensitivity: no
# - Required: no
# ArmarX.DisableLogging = 0
# ArmarX.EnableProfiling: Enable profiling of CPU load produced by this application
# Attributes:
# - Default: 0
# - Case sensitivity: no
# - Required: no
# ArmarX.EnableProfiling = 0
# ArmarX.LaserScannerUnitObserver.CreateUpdateFrequenciesChannel: If true, an additional channel is created that shows the update frequency of every other channel in that observer.
# Attributes:
# - Default: 0
# - Case sensitivity: no
# - Required: no
# ArmarX.LaserScannerUnitObserver.CreateUpdateFrequenciesChannel = 0
# ArmarX.LaserScannerUnitObserver.EnableProfiling: enable profiler which is used for logging performance events
# Attributes:
# - Default: 0
# - Case sensitivity: no
# - Required: no
# ArmarX.LaserScannerUnitObserver.EnableProfiling = 0
# ArmarX.LaserScannerUnitObserver.LaserScannerTopicName: Name of the laser scan topic.
# Attributes:
# - Default: LaserScans
# - Case sensitivity: no
# - Required: no
# ArmarX.LaserScannerUnitObserver.LaserScannerTopicName = LaserScans
# ArmarX.LaserScannerUnitObserver.MaxHistoryRecordFrequency: The Observer history is written with this maximum frequency. Everything faster is being skipped.
# Attributes:
# - Default: 50
# - Case sensitivity: no
# - Required: no
# ArmarX.LaserScannerUnitObserver.MaxHistoryRecordFrequency = 50
# ArmarX.LaserScannerUnitObserver.MaxHistorySize: Maximum number of entries in the Observer history
# Attributes:
# - Default: 5000
# - Case sensitivity: no
# - Required: no
# ArmarX.LaserScannerUnitObserver.MaxHistorySize = 5000
# ArmarX.LaserScannerUnitObserver.MinimumLoggingLevel: Local logging level only for this component
# Attributes:
# - Default: Undefined
# - Case sensitivity: no
# - Required: no
# ArmarX.LaserScannerUnitObserver.MinimumLoggingLevel = Undefined
# ArmarX.LaserScannerUnitObserver.ObjectName: Name of IceGrid well-known object
# Attributes:
# - Default: ""
# - Case sensitivity: no
# - Required: no
# ArmarX.LaserScannerUnitObserver.ObjectName = ""
# ArmarX.RedirectStdout: Redirect std::cout and std::cerr to ArmarXLog
# Attributes:
# - Default: 1
# - Case sensitivity: no
# - Required: no
# ArmarX.RedirectStdout = 1
# ArmarX.RemoteHandlesDeletionTimeout: The timeout (in ms) before a remote handle deletes the managed object after the use count reached 0. This time can be used by a client to increment the count again (may be required when transmitting remote handles)
# Attributes:
# - Default: 3000
# - Case sensitivity: no
# - Required: no
# ArmarX.RemoteHandlesDeletionTimeout = 3000
# ArmarX.StartDebuggerOnCrash: If this application crashes (segmentation fault) qtcreator will attach to this process and start the debugger.
# Attributes:
# - Default: 0
# - Case sensitivity: no
# - Required: no
# ArmarX.StartDebuggerOnCrash = 0
# ArmarX.TopicSuffix: Suffix appended to all topic names for outgoing topics. This is mainly used to direct all topics to another name for TopicReplaying purposes.
# Attributes:
# - Default: ""
# - Case sensitivity: no
# - Required: no
# ArmarX.TopicSuffix = ""
# ArmarX.UseTimeServer: Enable using a global Timeserver (e.g. from ArmarXSimulator)
# Attributes:
# - Default: 0
# - Case sensitivity: no
# - Required: no
# ArmarX.UseTimeServer = 0
# ArmarX.Verbosity: Global logging level for whole application
# Attributes:
# - Default: Info
# - Case sensitivity: no
# - Required: no
# ArmarX.Verbosity = Info
# Ice.Config: Custom Property
# Attributes:
# - Default: ::NOT_DEFINED::
# - Case sensitivity: no
# - Required: no
# Ice.Config = ::NOT_DEFINED::
# ==================================================================
# Global Config from Scenario LaserScannerTest
# ==================================================================
......@@ -22,4 +22,5 @@ add_subdirectory(InertialMeasurementUnitObserver)
add_subdirectory(ViewSelection)
add_subdirectory(HokuyoLaserUnit)
\ No newline at end of file
add_subdirectory(HokuyoLaserUnit)
add_subdirectory(LaserScannerUnitObserver)
\ No newline at end of file
armarx_component_set_name("LaserScannerUnitObserverApp")
#find_package(MyLib QUIET)
#armarx_build_if(MyLib_FOUND "MyLib not available")
#
# all include_directories must be guarded by if(Xyz_FOUND)
# for multiple libraries write: if(X_FOUND AND Y_FOUND)....
#if(MyLib_FOUND)
# include_directories(${MyLib_INCLUDE_DIRS})
#endif()
set(COMPONENT_LIBS
ArmarXCoreInterfaces
ArmarXCore
RobotAPIUnits
)
set(EXE_SOURCE main.cpp)
armarx_add_component_executable("${EXE_SOURCE}")
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotAPI::application::LaserScannerUnitObserver
* @author Fabian Paus ( fabian dot paus at kit dot edu )
* @date 2017
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include <RobotAPI/components/units/LaserScannerUnitObserver.h>
#include <ArmarXCore/core/application/Application.h>
#include <ArmarXCore/core/Component.h>
#include <ArmarXCore/core/logging/Logging.h>
int main(int argc, char* argv[])
{
return armarx::runSimpleComponentApp < armarx::LaserScannerUnitObserver > (argc, argv, "LaserScannerUnitObserver");
}
......@@ -15,9 +15,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package
* @author
* @date
* @author Fabian Paus ( fabian dot paus at kit dot edu )
* @date 2017
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
......
......@@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotAPI::units
* @author David Schiebener <schiebener at kit dot edu>
* @date 2014
* @author Fabian Paus ( fabian dot paus at kit dot edu )
* @date 2017
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
......
......@@ -9,7 +9,15 @@ armarx_component_set_name("HokuyoLaserUnit")
# include_directories(${MyLib_INCLUDE_DIRS})
#endif()
set(COMPONENT_LIBS ArmarXCoreInterfaces ArmarXCore)
find_package(HokuyoLaserScannerDriver QUIET)
armarx_build_if(HokuyoLaserScannerDriver_FOUND "Hokuyo laser scanner driver not found")
if(HokuyoLaserScannerDriver_FOUND)
include_directories(${HokuyoLaserScannerDriver_INCLUDE_DIR})
endif()
set(COMPONENT_LIBS ArmarXCoreInterfaces ArmarXCore ArmarXCoreObservers ArmarXCoreEigen3Variants
RobotAPICore RobotAPIUnits
HokuyoLaserScannerDriver)
set(SOURCES
./HokuyoLaserUnit.cpp
......
......@@ -22,25 +22,103 @@
#include "HokuyoLaserUnit.h"
#include <ArmarXCore/observers/variant/TimestampVariant.h>
#include <boost/algorithm/string/split.hpp>
#include <urg_utils.h>
using namespace armarx;
void HokuyoLaserUnit::onInitComponent()
{
topicName = getProperty<std::string>("LaserScannerTopicName").getValue();
offeringTopic(topicName);
updatePeriod = getProperty<int>("UpdatePeriod").getValue();
std::string deviceStrings = getProperty<std::string>("Devices").getValue();
std::vector<std::string> splitDeviceStrings;
boost::split(splitDeviceStrings, deviceStrings, boost::is_any_of(";"));
devices.clear();
devices.reserve(splitDeviceStrings.size());
for (std::string const & deviceString : splitDeviceStrings)
{
std::vector<std::string> ipAndPort;
boost::split(ipAndPort, deviceString, boost::is_any_of(","));
if (ipAndPort.size() != 2)
{
ARMARX_WARNING << "Unexpected format for laser scanner device: " << deviceString
<< " (split size: " << ipAndPort.size() << ")";
continue;
}
try
{
HokuyoLaserScanDevice device;
device.ip = ipAndPort[0];
device.port = std::stoi(ipAndPort[1]);
device.connected = false;
device.isDummy = boost::starts_with(device.ip, "Dummy");
devices.push_back(device);
}
catch (std::exception const& ex)
{
ARMARX_WARNING << "Could not convert port to integer for laser scanner device " << deviceString
<< " (port is " << ipAndPort[1] << ") : " << ex.what();
continue;
}
}
}
void HokuyoLaserUnit::onConnectComponent()
{
topic = getTopic<LaserScannerUnitListenerPrx>(topicName);
if (task)
{
task->stop();
}
for (HokuyoLaserScanDevice & device : devices)
{
if (device.isDummy)
{
continue;
}
int ret = urg_open(&device.urg, URG_ETHERNET, device.ip.c_str(), device.port);
device.connected = (ret == 0);
if (!device.connected)
{
ARMARX_WARNING << "Could not connect to laser scanner device using URG driver (IP: "
<< device.ip << ", Port: " << device.port << ", Error: " << ret << ")";
continue;
}
int lengthDataSize = urg_max_data_size(&device.urg);
device.lengthData.resize(lengthDataSize);
}
task = new PeriodicTask<HokuyoLaserUnit>(this, &HokuyoLaserUnit::updateScanData, updatePeriod, false, "HokuyoLaserScanUpdate");
task->start();
}
void HokuyoLaserUnit::onDisconnectComponent()
{
if (task)
{
task->stop();
}
for (HokuyoLaserScanDevice & device : devices)
{
if (device.connected)
{
urg_close(&device.urg);
device.connected = false;
}
}
}
......@@ -52,6 +130,64 @@ void HokuyoLaserUnit::onExitComponent()
armarx::PropertyDefinitionsPtr HokuyoLaserUnit::createPropertyDefinitions()
{
return armarx::PropertyDefinitionsPtr(new HokuyoLaserUnitPropertyDefinitions(
getConfigIdentifier()));
getConfigIdentifier()));
}
void HokuyoLaserUnit::updateScanData()
{
LaserScan scan;
TimestampVariantPtr now(new TimestampVariant(TimeUtil::GetTime()));
for (HokuyoLaserScanDevice & device : devices)
{
if (device.isDummy)
{
int lengthDataSize = 1081;
scan.clear();
scan.reserve(lengthDataSize);
for (int stepIndex = 0; stepIndex < lengthDataSize; ++stepIndex)
{
LaserScanStep step;
step.angle = float(0.25 * M_PI / 180.0 * stepIndex);
step.distance = lengthDataSize * stepIndex / 100.0f + 200.0f;
scan.push_back(step);
}
// TODO: Better names for the devices?
topic->reportSensorValues(device.ip, device.ip, scan, now);
continue;
}
if (device.connected)
{
int ret = urg_start_measurement(&device.urg, URG_DISTANCE, 1, 0);
if (ret != 0)
{
ARMARX_WARNING << deactivateSpam(1) << "Could not start measurement for laser scanner (IP: "
<< device.ip << ", Port: " << device.port << ", Error: " << ret << ")";
continue;
}
int lengthDataSize = urg_get_distance(&device.urg, device.lengthData.data(), nullptr);
if (lengthDataSize < 0)
{
ARMARX_WARNING << deactivateSpam(1) << "Could not get measurement for laser scanner (IP: "
<< device.ip << ", Port: " << device.port << ", Error: " << lengthDataSize << ")";
continue;
}
scan.clear();
scan.reserve(lengthDataSize);
for (int stepIndex = 0; stepIndex < lengthDataSize; ++stepIndex)
{
LaserScanStep step;
// TODO: We need an angle offset for the sensor
step.angle = (float)urg_step2rad(&device.urg, stepIndex); // Convert steps to rad
step.distance = (float)device.lengthData[stepIndex]; // Data is already in mm
scan.push_back(step);
}
// TODO: Better names for the devices?
topic->reportSensorValues(device.ip, device.ip, scan, now);
}
}
}
......@@ -23,8 +23,13 @@
#ifndef _ARMARX_COMPONENT_RobotAPI_HokuyoLaserUnit_H
#define _ARMARX_COMPONENT_RobotAPI_HokuyoLaserUnit_H
#include <ArmarXCore/core/Component.h>
#include <ArmarXCore/core/services/tasks/PeriodicTask.h>
#include <RobotAPI/components/units/SensorActorUnit.h>
#include <RobotAPI/interface/units/LaserScannerUnit.h>
#include <urg_sensor.h>
#include <vector>
namespace armarx
{
......@@ -39,24 +44,36 @@ namespace armarx
HokuyoLaserUnitPropertyDefinitions(std::string prefix):
armarx::ComponentPropertyDefinitions(prefix)
{
//defineRequiredProperty<std::string>("PropertyName", "Description");
//defineOptionalProperty<std::string>("PropertyName", "DefaultValue", "Description");
defineOptionalProperty<std::string>("LaserScannerTopicName", "LaserScans", "Name of the laser scan topic.");
defineOptionalProperty<int>("UpdatePeriod", 25, "Update period for laser scans");
defineOptionalProperty<std::string>("Devices", "", "List of devices in form of 'IP1,port1;IP2,port2;...'");
}
};
struct HokuyoLaserScanDevice
{
std::string ip;
int port = 0;
bool connected = false;
bool isDummy = false;
urg_t urg;
std::vector<long> lengthData;
};
/**
* @defgroup Component-HokuyoLaserUnit HokuyoLaserUnit
* @ingroup RobotAPI-Components
* A description of the component HokuyoLaserUnit.
*
*
* @class HokuyoLaserUnit
* @ingroup Component-HokuyoLaserUnit
* @brief Brief description of class HokuyoLaserUnit.
*
*
* Detailed description of class HokuyoLaserUnit.
*/
class HokuyoLaserUnit :
virtual public armarx::Component
virtual public armarx::LaserScannerUnitInterface,
virtual public armarx::SensorActorUnit
{
public:
/**
......@@ -92,6 +109,17 @@ namespace armarx
* @see PropertyUser::createPropertyDefinitions()
*/
virtual armarx::PropertyDefinitionsPtr createPropertyDefinitions();
private:
void updateScanData();
private:
std::string topicName;
LaserScannerUnitListenerPrx topic;
int updatePeriod = 25;
std::vector<HokuyoLaserScanDevice> devices;
PeriodicTask<HokuyoLaserUnit>::pointer_type task;
};
}
......
......@@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotAPI
* @author Markus Grotz <markus dot grotz at kit dot edu>
* @date 2015
* @author Fabian Paus ( fabian dot paus at kit dot edu )
* @date 2017
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment