AURobotServers  4
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ULaserDevice Class Reference

#include <ulaserdevice.h>

Inheritance diagram for ULaserDevice:
Inheritance graph

Public Member Functions

virtual void callGotNewDataWithObject ()
 
virtual bool changeMode (int scanangle, double resolution)
 
virtual void createBaseVars ()
 
unsigned int getBad ()
 
char * getDeviceName ()
 
int getDeviceNum ()
 
UPosition getDevicePos ()
 
UPosRot getDevicePose ()
 
URotation getDeviceRot ()
 
unsigned int getGood ()
 
char * getLogFileName (char *buffer, int bufferCnt)
 
int getLogInterval ()
 
bool getLogUsedScans ()
 
int getMaxMeasurements ()
 
bool getMirror ()
 
double getMsgRate ()
 
char * getName ()
 
virtual const char * getNameFromDevice ()
 
virtual bool getNewestData (ULaserData *dest, unsigned long lastSerial, int fake)
 
int getScanAngle ()
 
double getScanAngle (int measurement)
 
double getScanResolution ()
 
unsigned long getSerial ()
 
void gotNewScan (ULaserData *gotData)
 
virtual bool isLogFileOpen ()
 
virtual bool isPortOpen ()
 
virtual bool isReplayDevice ()
 
bool isRunning ()
 
bool isSend ()
 
virtual bool isVerbose ()
 
void logFileClose ()
 
bool logFileOpen ()
 
void logThisScan (ULaserData *scan)
 
void openRequest (bool toOpen)
 
void print (char *preString)
 
virtual const char * print (const char *preString, char *buff, int buffCnt)
 
void send (char *msg)
 
virtual void setCore (UCmdExe *pCore)
 
virtual void setDeviceName (const char *device)
 
void setDeviceNum (int value)
 
void setDevicePose (UPosRot *newPose)
 
void setLogInterval (int value)
 
void setLogUsedScans (bool value)
 
void setMirror (bool value)
 
void setVarStructure (UVarPool *varStruct)
 
void setVerbose (bool value)
 
bool start ()
 
void stop (bool justClosePort)
 
void threadRunLoop ()
 
 ULaserDevice ()
 
virtual ~ULaserDevice ()
 
- Public Member Functions inherited from UServerPush
int addPushCommand (UServerInMsg *msg)
 
bool doPushCall (UServerPushElement *pe, const char *value)
 
void flushClientCmds (int clientIdx)
 
UServerPushImplementgetImplementor ()
 
int getPushCmdCnt (int *cmdCnt, int *callCnt)
 
UServerPushQueuegetPushQueue ()
 
bool gotCmdExe ()
 
void gotNewData (void *pData)
 
bool isUpdated (int lastCnt, int *newCnt)
 
bool needNewData ()
 
void print (const char *preString)
 
void print (const char *preString, char *buff, int buffCnt)
 
void servicePendingPushCmds ()
 
void setCmdExe (UServerPushImplement *executor)
 
void setImplementor (UServerPushImplement *executor)
 
bool setResource (UResBase *resource, bool remove)
 
bool setUpdated (const char *value)
 Add watch object if needed. An image or other object is updated. set object as updated, with an extra qualifier, that may be used as a parameter in a push call. this push list is then added to the to the push list examined by the server thread. when server thread reach this push list it will call to get a possible associated data structure by a call to needNewData() whish is expected to call gotNewData(void * data_structure) - but now in the server thread. More...
 
 UServerPush ()
 
virtual ~UServerPush ()
 

Protected Member Functions

virtual void closePort ()
 
virtual double getDefaultDelay ()
 
void getFakeScan (ULaserData *dest, unsigned long lastSerial, int fake, double fakeDt=0.2)
 
virtual bool openPort ()
 
virtual bool receiveData ()
 
virtual bool sendToDevice (const char *msg, int lng)
 
void updateScanData (UTime scanTime)
 

Protected Attributes

double angleResolution
 
ULogFile datalog
 
int datalogSeq
 
bool datalogUsedScans
 
int deviceNum
 
char devName [MAX_DEVICE_NAME_LNG]
 
UTime lastScanTime
 
int loopCnt
 
double maxValidRange
 
bool mirrorData
 
int modeAngleScan
 
char name [MAX_NAME_LNG]
 
ULaserDatapushData
 
bool replayOrFake
 
bool sendNewData
 
char sendStr [MAX_SEND_MSG_LNG]
 
int sendStrCnt
 
unsigned long serial
 
unsigned int statBadCnt
 
unsigned int statGoodCnt
 
double statMsgRate
 
pthread_t threadHandle
 
bool threadRunning
 
bool threadStop
 
struct {
   UVariable *   framerate
 
   UVariable *   logData
 
   UVariable *   logDataInterval
 
   UVariable *   logSource
 
   UVariable *   maxRange
 
   UVariable *   name
 
   UVariable *   open
 
   UVariable *   pose
 
   UVariable *   scanDelay
 
   UVariable *   scanres
 
   UVariable *   scanwidth
 
   UVariable *   serial
 
   UVariable *   type
 
   UVariable *   versionInfo
 
var
 
UVarPoolvars
 
bool verbose
 

Detailed Description

Root class with basical laser scanner services, start, stop, get data etc.

Author
Christian Andersen

Constructor & Destructor Documentation

ULaserDevice::ULaserDevice ( )
ULaserDevice::~ULaserDevice ( )
virtual

Destructor

References logFileClose(), and pushData.

Member Function Documentation

void ULaserDevice::callGotNewDataWithObject ( )
virtual

Called by cmdExe to get push object followed by a call to 'gotNewData(object)'. Should be overwritten by push object holder.

Reimplemented from UServerPush.

References UServerPush::gotNewData(), ULock::lock(), pushData, and ULock::unlock().

Referenced by isReplayDevice().

bool ULaserDevice::changeMode ( int  scanangle,
double  resolution 
)
virtual

Change scanner resolution mode. (modeAngleScan and angleResolution) Returns true if new resolution is implemented. If not open, then values are just saved

Reimplemented in USick, UHokuyo, ULaserSim, ULms500, ULms100, and UFakeDevice.

Referenced by getSerial(), and UFunctionLaser::handleSetCommand().

void ULaserDevice::closePort ( )
protectedvirtual

Close serial port

Reimplemented in USick, UHokuyo, UFakeDevice, ULms500, ULms100, and ULaserSim.

References getDeviceName().

Referenced by openRequest(), and threadRunLoop().

void ULaserDevice::createBaseVars ( )
virtual
unsigned int ULaserDevice::getBad ( )
inline

Get statistics - bad count

References statBadCnt.

Referenced by UFunctionLaser::handleSetCommand().

virtual double ULaserDevice::getDefaultDelay ( )
inlineprotectedvirtual

Get default delat estimate for the device type

Reimplemented in USick, UHokuyo, ULms500, and ULms100.

char* ULaserDevice::getDeviceName ( )
inline
int ULaserDevice::getDeviceNum ( )
inline
UPosition ULaserDevice::getDevicePos ( )

Get the device position on robot. The position (in 3D) is part of the device pose that also includes the rotation around the three axex (see gerDeviceRot(). The position is in meter x is forward, y is left and z is up.

References var.

Referenced by getMirror(), UFuncPpl::handleCommand(), UFunctionPassable::handlePass(), UResLocater::locate(), UFunctionPassable::sendFullScan(), UFuncEfLine::sendRobotPoseAndSensorPosition(), and UFunctionLaser::sendScan().

UPosRot ULaserDevice::getDevicePose ( )

Get the full device pose including 3D position (x,y,z) (see getDevicePos()) and rotation (Omega, Phi, Kappa) (see getDeviceRot)). Returns a pointer to the structure, and can thus be used to modify the value too.

References var.

Referenced by UNamedBoxes::doDetect(), getFakeScan(), getMirror(), UFakeDevice::getNewestData(), UFuncLocalize::handleLocalize(), UFuncLocalize::handleLocalizeMHF(), UFuncLocalize::handleLocalizeUKF(), UFunctionPassable::handlePass(), UFunctionLaser::handleSetCommand(), UResLobst::makeObst(), UFuncEfLine::sendBoxPose(), and UResV360::update().

URotation ULaserDevice::getDeviceRot ( )

Get the device rotation relative to robot. The roattion (in 3D) is part of the device pose that also includes the position (see gerDeviceRos(). The rotation is in radians where Omega is rotation around the x-axis (Roll) positive is roll to the right. Phi is rotation around the Y-axis (tilt), positive is tilt down. Kappa is rotation around the Z-axis (turn) positive is left. The specified rotation order is like for a crane, forst rotation, then tilt and finally roll of the in this way turned and tilted axis.

References UPosRot::getRot(), and var.

Referenced by getMirror(), UFunctionPassable::handlePass(), UFunctionPassable::sendFullScan(), UFuncEfLine::sendRobotPoseAndSensorPosition(), and UFunctionLaser::sendScan().

void ULaserDevice::getFakeScan ( ULaserData dest,
unsigned long  lastSerial,
int  fake,
double  fakeDt = 0.2 
)
protected

Get fake data to this destination and advance fake position if scan number is used before, otherwise maintain position

Parameters
destis where to load the scan.
lastSerialis last used serial number - set next number in scan
intfake is fake number - 0 is live
doublefakeDt is update time for fake position - default is 0.2 sec

References angleResolution, UFakeMap::currentTruePose, datalogUsedScans, deviceNum, UFakeMap::fakeAdvancePose(), fakeMap, getDevicePose(), UPoseTVQ::getPose(), gotNewScan(), logThisScan(), mirrorData, modeAngleScan, UTime::now(), UPoseTVQ::print(), serial, ULaserData::setDeviceNum(), ULaserData::setMaxValidRange(), ULaserData::setMirror(), ULaserData::setScanTime(), ULaserData::setSerial(), ULaserData::setSimData(), UPoseTime::t, var, and verbose.

Referenced by ULaserSim::getNewestData(), UReplayDevice::getNewestData(), UFakeDevice::getNewestData(), ULms100::getNewestData(), ULms500::getNewestData(), UHokuyo::getNewestData(), USick::getNewestData(), and openRequest().

unsigned int ULaserDevice::getGood ( )
inline

Get statistics - good count

References statGoodCnt.

Referenced by UFunctionLaser::handleSetCommand().

char * ULaserDevice::getLogFileName ( char *  buffer,
int  bufferCnt 
)

Get name of logfile (open or not) - made form devicenumber as 'laser_N'. Returns 'buffer'

References dataPath, and deviceNum.

Referenced by UFunctionLaser::handleSetCommand(), and isReplayDevice().

int ULaserDevice::getLogInterval ( )
inline

Get log interval

References var.

Referenced by UFunctionLaser::handleSetCommand().

bool ULaserDevice::getLogUsedScans ( )
inline

Get log used scans

References datalogUsedScans.

Referenced by UFunctionLaser::handleSetCommand().

int ULaserDevice::getMaxMeasurements ( )
inline

Get number of measurements in scan-mode

References angleResolution, modeAngleScan, and roundi().

bool ULaserDevice::getMirror ( )
inline

Get mirror value. If false the first range is to the right. If mirror is true then first value is assumed to be to the left.

References getDevicePos(), getDevicePose(), getDeviceRot(), mirrorData, and setDevicePose().

Referenced by ULms100::getDataTo(), ULms500::getDataTo(), and UFunctionLaser::handleSetCommand().

double ULaserDevice::getMsgRate ( )
inline

Get statistics - number of good messages per second

References statMsgRate.

Referenced by UFunctionLaser::handleSetCommand(), and print().

char* ULaserDevice::getName ( )
inline
const char * ULaserDevice::getNameFromDevice ( )
virtual

Get name of device

Reimplemented in UHokuyo, ULms500, ULms100, and ULaserSim.

References getName().

Referenced by isSend().

bool ULaserDevice::getNewestData ( ULaserData dest,
unsigned long  lastSerial,
int  fake 
)
virtual
int ULaserDevice::getScanAngle ( )
inline

Get actual scan angle in degrees

References modeAngleScan.

Referenced by UFunctionLaser::handleSetCommand().

double ULaserDevice::getScanAngle ( int  measurement)
inline

Get angle from measurement number - result is in degrees

References angleResolution, getNewestData(), modeAngleScan, print(), and send().

double ULaserDevice::getScanResolution ( )
inline

Get actual scan resolution in centi degrees

References angleResolution.

Referenced by UFunctionLaser::handleSetCommand().

unsigned long ULaserDevice::getSerial ( )
inline

Get name of scanner

References changeMode(), isPortOpen(), serial, start(), stop(), and threadRunLoop().

Referenced by print().

void ULaserDevice::gotNewScan ( ULaserData gotData)

Got new measurement data from device. if 'gotData' == NULL, then data is available by a getNewestData(ULaserData*) call. Data should not be requested (by call) unless there is users waiting for the data. NB! this call is called by the read thread, and not the server message handler thread.

References ULaserData::copy(), data, datalogSeq, getNewestData(), UServerPush::getPushCmdCnt(), UServerPush::getPushQueue(), ULaserData::getScanTime(), logThisScan(), pushData, UServerPush::setUpdated(), ULock::tryLock(), ULock::unlock(), updateScanData(), and var.

Referenced by ULms100::decodeData(), ULms500::decodeData(), getFakeScan(), isReplayDevice(), ULaserSim::receiveData(), UHokuyo::receiveData(), USick::receiveData(), and UReplayDevice::replayStep().

virtual bool ULaserDevice::isLogFileOpen ( )
inlinevirtual

Is logfile open

References datalog, and ULogFile::isOpen().

Referenced by UFunctionLaser::handleSetCommand().

bool ULaserDevice::isPortOpen ( )
virtual
virtual bool ULaserDevice::isReplayDevice ( )
inlinevirtual

Is laserscanner a replay device scanner

Reimplemented in UReplayDevice.

References callGotNewDataWithObject(), getLogFileName(), gotNewScan(), logFileClose(), and logFileOpen().

Referenced by UFunctionLaser::handleSetCommand(), and ULaserPool::replayToTime().

bool ULaserDevice::isRunning ( )
inline

Is sick scanner running

References isPortOpen(), and threadRunning.

Referenced by USick::getNewestData(), and UFunctionLaser::handleSetCommand().

bool ULaserDevice::isSend ( )
inline

Is last string send

References getNameFromDevice(), and sendNewData.

Referenced by UFunctionLaser::handleSetCommand().

virtual bool ULaserDevice::isVerbose ( )
inlinevirtual

Is verbose flag on

References verbose.

Referenced by UFunctionLaser::handleSetCommand().

void ULaserDevice::logFileClose ( )

Close logfile for this device (if open).

References ULogFile::closeLog(), datalog, ULogFile::isLogOpen(), replayOrFake, and var.

Referenced by UFunctionLaser::handleSetCommand(), isReplayDevice(), and ~ULaserDevice().

bool ULaserDevice::logFileOpen ( )

Open a logfile in the data directory adding this device number at the end. If the log is open, then it is closed before (re) opening.

References datalog, ULogFile::isLogOpen(), ULogFile::isOpen(), ULogFile::openLog(), replayOrFake, var, and Wait().

Referenced by UFunctionLaser::handleSetCommand(), and isReplayDevice().

void ULaserDevice::logThisScan ( ULaserData scan)
bool ULaserDevice::openPort ( )
protectedvirtual

Open serial post. Return true if open(ed)

Reimplemented in USick, UHokuyo, UFakeDevice, ULms500, ULms100, and ULaserSim.

References getDeviceName().

Referenced by openRequest(), and threadRunLoop().

void ULaserDevice::openRequest ( bool  toOpen)
inline

open or close port that is set port to be opened or closed by the read thread

Parameters
toOpenset to open if true, else set to close

References closePort(), getFakeScan(), openPort(), receiveData(), sendToDevice(), updateScanData(), and var.

Referenced by UFunctionLaser::handleScanGetCommand(), and UFunctionLaser::handleSetCommand().

void ULaserDevice::print ( char *  preString)

Print status

Referenced by getScanAngle(), and ULaserPool::print().

const char * ULaserDevice::print ( const char *  preString,
char *  buff,
int  buffCnt 
)
virtual

Print device status to a buffer string

Reimplemented in UFakeDevice.

References angleResolution, bool2str(), devName, getMsgRate(), getName(), getSerial(), isPortOpen(), and modeAngleScan.

bool ULaserDevice::receiveData ( )
protectedvirtual

Receive data from device – called from device loop, should return as fast as possible after doing the job, i.e. no blocking read. Should add number of good and bad blocks of data to statBadCnt and statGootcnt. Returns true if data received.

Reimplemented in USick, UHokuyo, ULms500, ULms100, and ULaserSim.

References getDeviceName().

Referenced by openRequest(), and threadRunLoop().

void ULaserDevice::send ( char *  msg)

Send data to device Data must be a zero-terminated string.

References isPortOpen(), sendNewData, sendStr, sendStrCnt, and start().

Referenced by getScanAngle(), and UFunctionLaser::handleSetCommand().

bool ULaserDevice::sendToDevice ( const char *  msg,
int  lng 
)
protectedvirtual

Send data to device. Sends 'lng' bytes from 'msg'. Data must be a zero-terminated string.

Reimplemented in UHokuyo, ULms500, ULms100, and ULaserSim.

Referenced by openRequest(), and threadRunLoop().

virtual void ULaserDevice::setCore ( UCmdExe pCore)
inlinevirtual

set server core pointer - just a debug feature - I think)

Reimplemented in ULaserSim.

References createBaseVars().

Referenced by ULaserPool::addDevice().

virtual void ULaserDevice::setDeviceName ( const char *  device)
inlinevirtual
void ULaserDevice::setDeviceNum ( int  value)
inline

Set device number for device

References deviceNum, logThisScan(), and scan.

Referenced by ULaserPool::addDevice().

void ULaserDevice::setDevicePose ( UPosRot newPose)

Set the full device pose including 3D position (x,y,z) (see getDevicePos()) and rotation (Omega, Phi, Kappa) (see getDeviceRot)). Returns a pointer to the structure, and can thus be used to modify the value too.

References var.

Referenced by getMirror(), and UFunctionLaser::handleSetCommand().

void ULaserDevice::setLogInterval ( int  value)
inline

Set log interval

References var.

Referenced by UFunctionLaser::handleSetCommand().

void ULaserDevice::setLogUsedScans ( bool  value)
inline

Set log used scans

References datalogUsedScans.

Referenced by UFunctionLaser::handleSetCommand().

void ULaserDevice::setMirror ( bool  value)
inline

Set mirror flag. The mirror flag indicates that the laserscanner is mounted upside down, and thus the data is in reverse angle order. This will result in the start angle and resolution has negated sign. In normal mode first range is to the right, i.e. a negative angle. The resolution (angle step size) is then positive. With the mirror flag set, the start angle will be positive (first range to the left) and the resolution is negative.

References mirrorData.

Referenced by UFunctionLaser::handleSetCommand().

void ULaserDevice::setVarStructure ( UVarPool varStruct)
inline

Set pointer to var-pool structure for variables for this device.

References vars.

Referenced by ULaserPool::addDevice().

void ULaserDevice::setVerbose ( bool  value)
inline

Set verbose flag (for debugging)

References verbose.

Referenced by UFunctionLaser::handleSetCommand().

bool ULaserDevice::start ( )
void ULaserDevice::stop ( bool  justClosePort)

Stop sick scanner port. Stop also thread - if not 'justClosePort'.

References ULogFile::closeLog(), datalog, threadHandle, threadRunning, threadStop, and var.

Referenced by getSerial(), ULaserPool::stop(), UHokuyo::~UHokuyo(), ULms100::~ULms100(), ULms500::~ULms500(), and USick::~USick().

void ULaserDevice::threadRunLoop ( )
void ULaserDevice::updateScanData ( UTime  scanTime)
protected

Update global variables with new scan data

Parameters
scantimescantime of the new scan (for framerate calculation)

References angleResolution, lastScanTime, modeAngleScan, serial, and var.

Referenced by gotNewScan(), and openRequest().

Member Data Documentation

double ULaserDevice::angleResolution
protected
ULogFile ULaserDevice::datalog
protected
int ULaserDevice::datalogSeq
protected

Logging sequence number

Referenced by gotNewScan(), and ULaserDevice().

bool ULaserDevice::datalogUsedScans
protected

interval beteen systematic loggings. 0 is no (systematic) logging. 1 is log every scan. N log every N'th scan. Log the used scans - that is scans requested by 'getNewestData'

Referenced by getFakeScan(), getLogUsedScans(), ULaserSim::getNewestData(), ULms100::getNewestData(), ULms500::getNewestData(), UHokuyo::getNewestData(), USick::getNewestData(), setLogUsedScans(), and ULaserDevice().

int ULaserDevice::deviceNum
protected
char ULaserDevice::devName[MAX_DEVICE_NAME_LNG]
protected
UVariable* ULaserDevice::framerate
UTime ULaserDevice::lastScanTime
protected

Time of last scan

Referenced by updateScanData().

UVariable* ULaserDevice::logData
UVariable* ULaserDevice::logDataInterval
UVariable* ULaserDevice::logSource
int ULaserDevice::loopCnt
protected

Loop count for receive thread

Referenced by threadRunLoop(), and ULaserDevice().

UVariable* ULaserDevice::maxRange
double ULaserDevice::maxValidRange
protected
bool ULaserDevice::mirrorData
protected
int ULaserDevice::modeAngleScan
protected
char ULaserDevice::name[MAX_NAME_LNG]
protected
UVariable* ULaserDevice::name
UVariable* ULaserDevice::open
UVariable* ULaserDevice::pose
ULaserData* ULaserDevice::pushData
protected

Scan to be used by a pending push command

Referenced by callGotNewDataWithObject(), gotNewScan(), ULaserDevice(), and ~ULaserDevice().

bool ULaserDevice::replayOrFake
protected

Use thread based device interface - else generated, i.e. replay or fake

Referenced by logFileClose(), logFileOpen(), start(), threadRunLoop(), UFakeDevice::UFakeDevice(), ULaserDevice(), and UReplayDevice::UReplayDevice().

UVariable* ULaserDevice::scanDelay
UVariable* ULaserDevice::scanres
UVariable* ULaserDevice::scanwidth
bool ULaserDevice::sendNewData
protected

Flag for new data to send

Referenced by isSend(), send(), threadRunLoop(), and ULaserDevice().

char ULaserDevice::sendStr[MAX_SEND_MSG_LNG]
protected

Buffer for message to send

Referenced by send(), and threadRunLoop().

int ULaserDevice::sendStrCnt
protected

Send string length, may include a zero.

Referenced by send(), threadRunLoop(), and ULaserDevice().

unsigned long ULaserDevice::serial
protected
UVariable* ULaserDevice::serial
unsigned int ULaserDevice::statBadCnt
protected
unsigned int ULaserDevice::statGoodCnt
protected
double ULaserDevice::statMsgRate
protected

Good messages per second.

Referenced by getMsgRate(), threadRunLoop(), and ULaserDevice().

pthread_t ULaserDevice::threadHandle
protected

Thread handle for frame read thread.

Referenced by start(), and stop().

bool ULaserDevice::threadRunning
protected

Is thread actually running

Referenced by isRunning(), start(), stop(), threadRunLoop(), and ULaserDevice().

bool ULaserDevice::threadStop
protected

Should thread stop - terminate

Referenced by start(), stop(), threadRunLoop(), and ULaserDevice().

UVariable* ULaserDevice::type
struct { ... } ULaserDevice::var
UVarPool* ULaserDevice::vars
protected

Pointer to local variable structure

Referenced by UFakeDevice::createBaseVars(), createBaseVars(), setVarStructure(), and ULaserDevice().

bool ULaserDevice::verbose
protected
UVariable* ULaserDevice::versionInfo

The documentation for this class was generated from the following files: