Skip to content
Snippets Groups Projects
Commit ab44094b authored by Arafat Nourredine's avatar Arafat Nourredine
Browse files

Add MotionProxyDevice module (helper for GalilAxis device)

parent 6f73e856
Branches
Tags
No related merge requests found
#ifndef _MOTIONPROXYDEVICE_H_
#define _MOTIONPROXYDEVICE_H_
// ============================================================================
//
// = CONTEXT
// Utility class - Implementation of class encapsulating creation and control
// of a Tango device proxy to a simple Rotation, Translation motors
//
// = File
// MotionProxyDevice.h
//
// = AUTHOR
// Arafat NOUREDDINE - Synchrotron SOLEIL
//
// ============================================================================
#include <tango.h>
#include <TangoExceptionsHelper.h>
#include <DeviceProxyHelper.h>
using namespace std;
class MotionProxyDevice : public Tango::LogAdapter
{
public:
//- ctor
MotionProxyDevice( const string sProxyName,
const string sDescription,
Tango::DeviceImpl * _device)
throw (Tango::DevFailed) ;
//- dtor
virtual ~MotionProxyDevice();
//- Move motor to a new position
virtual void Move(double)
throw (Tango::DevFailed);
//- Stop the motor
virtual void Stop(void)
throw (Tango::DevFailed);
//- Forward the motor
virtual void Forward(void)
throw (Tango::DevFailed);
//- Backward the motor
virtual void Backward(void)
throw (Tango::DevFailed);
//- Read the read part of the attribute "attributePositionName" associated to the motor (call read_attribute)
virtual double Read(void)
throw (Tango::DevFailed);
//- Read the write part of the attribute "attributePositionName" associated to the motor (call read_attribute_w)
virtual double ReadW(void)
throw (Tango::DevFailed);
//- Read the the attribute "attributeBLSWName" associated to the motor (call read_attribute)
bool ReadBLSW(void)
throw (Tango::DevFailed);
//- Read the the attribute "attributeFLSWName" associated to the motor (call read_attribute)
bool ReadFLSW(void)
throw (Tango::DevFailed);
//- Read the state of the motor
virtual Tango::DevState State(void)
throw (Tango::DevFailed);
//- Read the status of the motor
string Status(void)
throw (Tango::DevFailed);
protected:
Tango::DeviceProxyHelper* _mProxy;
string _sProxyName;
string _sDescription;
string _sAttributePositionName;
string _sAttributeBLSWName;
string _sAttributeFLSWName;
string _sCommandStateName;
string _sCommandStatusName;
string _sCommandStopName;
string _sCommandForwardName;
string _sCommandBackwardName;
private:
};
////////////////////////////////////////////////////////////////////////////////
#endif // _MOTIONPROXYDEVICE_H_
......@@ -11,7 +11,7 @@
<groupId>fr.soleil.lib</groupId>
<artifactId>Utils-${aol}-${library}-${mode}</artifactId>
<version>1.2.0</version>
<version>1.2.1-SNAPSHOT</version>
<packaging>nar</packaging>
......
// ============================================================================
//
// = CONTEXT
// Utility class - Implementation of class encapsulating creation and control
// of a Tango device proxy to a simple Rotation, Translation motors
//
// = File
// MotionProxyDevice.cpp
//
// = AUTHOR
// Arafat NOUREDDINE - Synchrotron SOLEIL
//
// ============================================================================
#include <MotionProxyDevice.h>
//////////////////////////////////////////////////////////////////////////////////////
//-ctor
//////////////////////////////////////////////////////////////////////////////////////
MotionProxyDevice::MotionProxyDevice( const string sProxyName,
const string sDescription,
Tango::DeviceImpl * _device)
throw (Tango::DevFailed)
: Tango::LogAdapter((Tango::DeviceImpl *)_device)
{
DEBUG_STREAM << "MotionProxyDevice::MotionProxyDevice() [ "<< sDescription<< " ] entering... " << endl;
//Init. members
_sProxyName = sProxyName;
_sDescription = sDescription;
_sAttributePositionName = "position";
_sAttributeBLSWName = "backwardLimitSwitch";
_sAttributeFLSWName = "forwardLimitSwitch";
_sCommandStateName = "State";
_sCommandStatusName = "Status";
_sCommandStopName = "Stop";
_sCommandForwardName = "Forward";
_sCommandBackwardName = "Backward";
_mProxy = 0;
//fake motion proxy, nothing to do
if(sProxyName == "none/none/none")
return;
//create proxy to the device
try
{
_mProxy = new Tango::DeviceProxyHelper(sProxyName.c_str());
if(_mProxy==0)
throw std::bad_alloc();
else
_mProxy->get_device_proxy()->ping();
}
catch (const std::bad_alloc&)
{
//ERROR_STREAM << "Bad alloc Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to create proxy to " << _sDescription << " --> Memory allocation exception !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("OUT_OF_MEMORY"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::MotionProxyDevice()")
);
}
catch (Tango::DevFailed& e)
{
_mProxy = 0;
//ERROR_STREAM << e << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to create proxy to " << _sDescription << " --> check the Device proxy Name (" << _sProxyName << ") !" << endl;
Tango::Except::re_throw_exception
( e,
static_cast<const char*>("TANGO_DEVICE_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::MotionProxyDevice()")
);
}
catch(...)
{
_mProxy = 0;
//ERROR_STREAM << "Unknown Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to create proxy to " << _sDescription << " --> check the Device proxy Name (" << _sProxyName << ") !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("UNKNOWN_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::MotionProxyDevice()")
);
}
}
//////////////////////////////////////////////////////////////////////////////////////
//-dtor
//////////////////////////////////////////////////////////////////////////////////////
MotionProxyDevice::~MotionProxyDevice()
{
DEBUG_STREAM << "MotionProxyDevice::~MotionProxyDevice() [ "<< _sDescription<< " ] entering... " << endl;
delete _mProxy;
}
//////////////////////////////////////////////////////////////////////////////////////
//-
//////////////////////////////////////////////////////////////////////////////////////
void MotionProxyDevice::Move(double dMotorValue)
throw (Tango::DevFailed)
{
DEBUG_STREAM << "MotionProxyDevice::Move() [ "<< _sDescription<< " ] entering... " << endl;
try
{
if(_mProxy!=0)
_mProxy->write_attribute(_sAttributePositionName.c_str(),dMotorValue);
}
catch (Tango::DevFailed& e)
{
//ERROR_STREAM << e << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to write attribute "<<_sAttributePositionName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::re_throw_exception
( e,
static_cast<const char*>("TANGO_DEVICE_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Move()")
);
}
catch(...)
{
//ERROR_STREAM << "Unknown Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to write attribute "<<_sAttributePositionName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("UNKNOWN_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Move()")
);
}
}
//////////////////////////////////////////////////////////////////////////////////////
//-
//////////////////////////////////////////////////////////////////////////////////////
void MotionProxyDevice::Stop(void)
throw (Tango::DevFailed)
{
DEBUG_STREAM << "MotionProxyDevice::Stop() [ "<< _sDescription<< " ] entering... " << endl;
try
{
if(_mProxy!=0)
_mProxy->command(_sCommandStopName.c_str());
}
catch (Tango::DevFailed& e)
{
//ERROR_STREAM << e << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to execute command "<<_sCommandStopName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::re_throw_exception
( e,
static_cast<const char*>("TANGO_DEVICE_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Stop()")
);
}
catch(...)
{
//ERROR_STREAM << "Unknown Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to execute command "<<_sCommandStopName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("UNKNOWN_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Stop()")
);
}
}
//////////////////////////////////////////////////////////////////////////////////////
//-
//////////////////////////////////////////////////////////////////////////////////////
void MotionProxyDevice::Forward(void)
throw (Tango::DevFailed)
{
DEBUG_STREAM << "MotionProxyDevice::Forward() [ "<< _sDescription<< " ] entering... " << endl;
try
{
if(_mProxy!=0)
_mProxy->command(_sCommandForwardName.c_str());
}
catch (Tango::DevFailed& e)
{
//ERROR_STREAM << e << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to execute command "<<_sCommandForwardName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::re_throw_exception
( e,
static_cast<const char*>("TANGO_DEVICE_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Forward()")
);
}
catch(...)
{
//ERROR_STREAM << "Unknown Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to execute command "<<_sCommandForwardName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("UNKNOWN_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Forward()")
);
}
}
//////////////////////////////////////////////////////////////////////////////////////
//-
//////////////////////////////////////////////////////////////////////////////////////
void MotionProxyDevice::Backward(void)
throw (Tango::DevFailed)
{
DEBUG_STREAM << "MotionProxyDevice::Backward() [ "<< _sDescription<< " ] entering... " << endl;
try
{
if(_mProxy!=0)
_mProxy->command(_sCommandBackwardName.c_str());
}
catch (Tango::DevFailed& e)
{
//ERROR_STREAM << e << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to execute command "<<_sCommandBackwardName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::re_throw_exception
( e,
static_cast<const char*>("TANGO_DEVICE_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Backward()")
);
}
catch(...)
{
//ERROR_STREAM << "Unknown Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to execute command "<<_sCommandBackwardName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("UNKNOWN_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Backward()")
);
}
}
//////////////////////////////////////////////////////////////////////////////////////
//-
//////////////////////////////////////////////////////////////////////////////////////
double MotionProxyDevice::Read(void)
throw (Tango::DevFailed)
{
DEBUG_STREAM << "MotionProxyDevice::Read() [ "<< _sDescription<< " ] entering... " << endl;
double dMotorValue=0.0;
try
{
if(_mProxy!=0)
_mProxy->read_attribute(_sAttributePositionName.c_str(),dMotorValue);
}
catch (Tango::DevFailed& e)
{
//ERROR_STREAM << e << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to read attribute "<<_sAttributePositionName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::re_throw_exception
( e,
static_cast<const char*>("TANGO_DEVICE_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Read()")
);
}
catch(...)
{
//ERROR_STREAM << "Unknown Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to read attribute "<<_sAttributePositionName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("UNKNOWN_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Read()")
);
}
return dMotorValue;
}
//////////////////////////////////////////////////////////////////////////////////////
//-
//////////////////////////////////////////////////////////////////////////////////////
double MotionProxyDevice::ReadW(void)
throw (Tango::DevFailed)
{
DEBUG_STREAM << "MotionProxyDevice::ReadW() [ "<< _sDescription<< " ] entering... " << endl;
double dMotorValue=0.0;
try
{
if(_mProxy!=0)
_mProxy->read_attribute_w(_sAttributePositionName.c_str(),dMotorValue);
}
catch (Tango::DevFailed& e)
{
//ERROR_STREAM << e << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to read attribute "<<_sAttributePositionName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::re_throw_exception
( e,
static_cast<const char*>("TANGO_DEVICE_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::ReadW()")
);
}
catch(...)
{
//ERROR_STREAM << "Unknown Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to read attribute "<<_sAttributePositionName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("UNKNOWN_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::ReadW()")
);
}
return dMotorValue;
}
//////////////////////////////////////////////////////////////////////////////////////
//-
//////////////////////////////////////////////////////////////////////////////////////
bool MotionProxyDevice::ReadBLSW(void)
throw (Tango::DevFailed)
{
DEBUG_STREAM << "MotionProxyDevice::ReadBLSW() [ "<< _sDescription<< " ] entering... " << endl;
bool bBLSWValue = false;
try
{
if(_mProxy!=0)
_mProxy->read_attribute(_sAttributeBLSWName.c_str(),bBLSWValue);
}
catch (Tango::DevFailed& e)
{
//ERROR_STREAM << e << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to read attribute "<<_sAttributeBLSWName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::re_throw_exception
( e,
static_cast<const char*>("TANGO_DEVICE_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::ReadBLSW()")
);
}
catch(...)
{
//ERROR_STREAM << "Unknown Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to read attribute "<<_sAttributeBLSWName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("UNKNOWN_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::ReadBLSW()")
);
}
return bBLSWValue;
}
//////////////////////////////////////////////////////////////////////////////////////
//-
//////////////////////////////////////////////////////////////////////////////////////
bool MotionProxyDevice::ReadFLSW(void)
throw (Tango::DevFailed)
{
DEBUG_STREAM << "MotionProxyDevice::ReadFLSW() [ "<< _sDescription<< " ] entering... " << endl;
bool bFLSWValue = false;
try
{
if(_mProxy!=0)
_mProxy->read_attribute(_sAttributeFLSWName.c_str(),bFLSWValue);
}
catch (Tango::DevFailed& e)
{
//ERROR_STREAM << e << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to read attribute "<<_sAttributeFLSWName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::re_throw_exception
( e,
static_cast<const char*>("TANGO_DEVICE_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::ReadFLSW()")
);
}
catch(...)
{
//ERROR_STREAM << "Unknown Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to read attribute "<<_sAttributeFLSWName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("UNKNOWN_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::ReadFLSW()")
);
}
return bFLSWValue;
}
//////////////////////////////////////////////////////////////////////////////////////
//-
//////////////////////////////////////////////////////////////////////////////////////
Tango::DevState MotionProxyDevice::State(void)
throw (Tango::DevFailed)
{
DEBUG_STREAM << "MotionProxyDevice::State() [ "<< _sDescription<< " ] entering... " << endl;
Tango::DevState MotorState = Tango::STANDBY;
try
{
if(_mProxy!=0)
_mProxy->command_out(_sCommandStateName.c_str(),MotorState);
}
catch (Tango::DevFailed& e)
{
//ERROR_STREAM << e << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to execute command "<<_sCommandStateName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::re_throw_exception
( e,
static_cast<const char*>("TANGO_DEVICE_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::State()")
);
}
catch(...)
{
//ERROR_STREAM << "Unknown Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to execute command "<<_sCommandStateName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("UNKNOWN_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::State()")
);
}
return MotorState;
}
//////////////////////////////////////////////////////////////////////////////////////
//-
//////////////////////////////////////////////////////////////////////////////////////
string MotionProxyDevice::Status(void)
throw (Tango::DevFailed)
{
DEBUG_STREAM << "MotionProxyDevice::State() [ "<< _sDescription<< " ] entering... " << endl;
string MotorStatus = "STANDBY";
try
{
if(_mProxy!=0)
_mProxy->command_out(_sCommandStatusName.c_str(),MotorStatus);
}
catch (Tango::DevFailed& e)
{
//ERROR_STREAM << e << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to execute command "<<_sCommandStatusName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::re_throw_exception
( e,
static_cast<const char*>("TANGO_DEVICE_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Status()")
);
}
catch(...)
{
//ERROR_STREAM << "Unknown Exception" << ENDLOG;
TangoSys_OMemStream o;
o << "Unable to execute command "<<_sCommandStatusName <<" of the device " << _sDescription << " !" << endl;
Tango::Except::throw_exception
(
static_cast<const char*>("UNKNOWN_ERROR"),
static_cast<const char*>(o.str().c_str()),
static_cast<const char*>("MotionProxyDevice::Status()")
);
}
return MotorStatus;
}
//////////////////////////////////////////////////////////////////////////////////////
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment