Commit cf70e052 authored by Abdelali Elaazzouzi's avatar Abdelali Elaazzouzi

new zaber driver

parent 12e9333d
<module name="xmcb2">
<driver class="xmcb2::Xmcb2Driver"/>
<driver class="xmcb2::Xmcb2AxisDriver"/>
</module>
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include <drivers/zaber/xmcb2/PerfectXmcb2AxisDriver.h>
#include <drivers/zaber/xmcb2/Xmcb2Def.h>
namespace xmcb2 {
/*
* Constructor
*/
PerfectXmcb2AxisDriver::PerfectXmcb2AxisDriver(Xmcb2AxisDriver* owner) :
Xmcb2AxisState(owner) {
/* Empty */
}
/*
* Destructor
*/
PerfectXmcb2AxisDriver::~PerfectXmcb2AxisDriver() {
/* Empty */
}
/*
* continu
*/
void PerfectXmcb2AxisDriver::continu() {
}
/*
* pause
*/
void PerfectXmcb2AxisDriver::pause() {
}
/*
* writeEncoder
*/
void PerfectXmcb2AxisDriver::writeEncoder() {
}
/*
* writeParam
*/
void PerfectXmcb2AxisDriver::writeParam() {
}
/*
* homeSearch
*/
void PerfectXmcb2AxisDriver::homeSearch() {
}
/*
* goHome
*/
void PerfectXmcb2AxisDriver::goHome() {
}
/*
* stop
*/
void PerfectXmcb2AxisDriver::stop() {
// Stop command
// Do nothing
}
/*
* init
*/
void PerfectXmcb2AxisDriver::init() {
// Stop command
// Do nothing
}
/*
* readStatus
*/
void PerfectXmcb2AxisDriver::readStatus() {
// Status command
if (owner()->actualPosition() <= owner()->minPosition()) {
owner()->computeAxisStatus(LOW_HARDSTOP);
} else if (owner()->actualPosition() >= owner()->maxPosition()) {
owner()->computeAxisStatus(HIGH_HARDSTOP);
} else {
owner()->computeAxisStatus(0);
}
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
/*
* read
*/
void PerfectXmcb2AxisDriver::read() {
// Read command
// Do nothing
}
/*
* move
*/
void PerfectXmcb2AxisDriver::move() {
owner()->actualPosition.update(owner()->wantedPosition());
owner()->setPointPosition.update(owner()->wantedPosition());
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef PERFECTXMCB2AXISDRIVER_H
#define PERFECTXMCB2AXISDRIVER_H
#include <drivers/zaber/xmcb2/Xmcb2AxisState.h>
namespace xmcb2 {
class Xmcb2AxisDriver;
/*!
* \class PerfectXmcb2AxisDriver
* \brief Perfect implementation class for the Xmcb2Axis device driver
*
* This class is a perfect implementation of Xmcb2Axis device driver.
* On start command, all actual values become target's ones.
*/
class PerfectXmcb2AxisDriver: public Xmcb2AxisState {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
PerfectXmcb2AxisDriver(Xmcb2AxisDriver *owner);
/*!
* \brief Destructor
*/
virtual ~PerfectXmcb2AxisDriver();
/*!
* \brief Initialisation implementation
*/
virtual void init();
/*!
* \brief move command implementation
*/
virtual void move();
/*!
* \brief Pause command implementation
*/
virtual void pause();
/*!
* \brief Continu command implementation
*/
virtual void continu();
/*!
* \brief Write encoder command implementation
*/
virtual void writeEncoder();
/*!
* \brief Read command implementation
*/
virtual void read();
/*!
* \brief Read status command implementation
*/
virtual void readStatus();
/*!
* \brief Stop command implementation
*/
virtual void stop();
/*!
* \brief Write parameters command implementation
*/
virtual void writeParam();
/*!
* \brief Home search command implementation
*/
virtual void homeSearch();
/*!
* \brief Go home command implementation
*/
virtual void goHome();
};
}
#endif //PERFECTXMCB2AXISDRIVER_H
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include <drivers/zaber/xmcb2/PerfectXmcb2Driver.h>
namespace xmcb2 {
/*
* Constructor
*/
PerfectXmcb2Driver::PerfectXmcb2Driver(Xmcb2Driver* owner) :
Xmcb2State(owner) {
/* Empty */
}
/*
* Destructor
*/
PerfectXmcb2Driver::~PerfectXmcb2Driver() {
/* Empty */
}
/*
* init
*/
void PerfectXmcb2Driver::init() {
}
/*
* readInfos
*/
void PerfectXmcb2Driver::readInfos() {
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef PERFECTXMCB2DRIVER_H
#define PERFECTXMCB2DRIVER_H
#include <drivers/zaber/xmcb2/Xmcb2State.h>
namespace xmcb2 {
class Xmcb2Driver;
/*!
* \class PerfectXmcb2Driver
* \brief Perfect implementation class for the Xmcb2 device driver
*
* This class is a perfect implementation of Xmcb2 device driver.EXPT301es
* On start command, all actual values become target's ones.
*/
class PerfectXmcb2Driver: public Xmcb2State {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
PerfectXmcb2Driver(Xmcb2Driver* owner);
/*!
* \brief Destructor
*/
virtual ~PerfectXmcb2Driver();
/*!
* \brief Initialisation command implementation
*/
virtual void init();
/*!
* \brief Read Infos command implementation
*/
virtual void readInfos();
};
}
#endif //PERFECXMCB2DRIVER_H
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "Utilities/Calculations.h"
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <drivers/zaber/xmcb2/RealXmcb2AxisDriver.h>
using namespace std;
using namespace driver;
using namespace boost;
namespace xmcb2 {
/*
* Constructor
*/
RealXmcb2AxisDriver::RealXmcb2AxisDriver(Xmcb2AxisDriver* owner) :
Xmcb2AxisState(owner) {
}
/*
* Destructor
*/
RealXmcb2AxisDriver::~RealXmcb2AxisDriver() {
/* Empty */
}
/*
* init
*/
void RealXmcb2AxisDriver::init() {
writeParam();
read();
readStatus();
}
/*
* writeEncoder
*/
void RealXmcb2AxisDriver::writeEncoder() {
}
/*
* writeParam
*/
void RealXmcb2AxisDriver::writeParam() {
writeXmcb2(MOTOR_OFF_COMMAND);
writeXmcb2Value(MAX_MOTOR_CURRENT_COMMAND, owner()->maxMotorCurrent());
writeXmcb2Value(MAX_VELOCITY_COMMAND, owner()->maxVelocity());
writeXmcb2Value(MAX_ACC_DEC_COMMAND, owner()->maxAccAndDec());
writeXmcb2Value(VELOCITY_COMMAND, owner()->velocity());
writeXmcb2Value(ACCELERATION_COMMAND, owner()->acceleration());
writeXmcb2Value(DECELERATION_COMMAND, owner()->deceleration());
writeXmcb2Value(JERK_RATE_COMMAND, owner()->jerkRate());
writeXmcb2Value(JOG_HIGH_SPEED_COMMAND, owner()->jogHighSpeed());
writeXmcb2Value(JOG_LOW_SPEED_COMMAND, owner()->jogLowSpeed());
writeXmcb2Value(HOME_SEARCH_HIGH_SPEED_COMMAND, owner()->homeSearchHighSpeed());
writeXmcb2Value(HOME_SEARCH_LOW_SPEED_COMMAND, owner()->homeSearchLowSpeed());
writeXmcb2(MOTOR_ON_COMMAND);
}
/*
* homeSearch
*/
void RealXmcb2AxisDriver::homeSearch() {
writeXmcb2Value(HOME_SEARCH_COMMAND, (int32) 4);
}
/*
* goHome
*/
void RealXmcb2AxisDriver::goHome() {
writeXmcb2Value(MOVE_POSITION_COMMAND, owner()->homePosition());
}
/*
* pause
*/
void RealXmcb2AxisDriver::pause() {
writeXmcb2(STOP_COMMAND);
}
/*
* stop
*/
void RealXmcb2AxisDriver::stop() {
writeXmcb2(STOP_COMMAND);
}
/*
* readStatus
*/
void RealXmcb2AxisDriver::readStatus() {
vector<string> answer = writeXmcb2AndRead(MOTOR_STATUS_COMMAND);
if (answer.size() == 1) {
if (answer[0].size() == 1) {
int32 status = 0;
// cout << owner()->getName() << " status = 0x" << hex << (uint32) answer[0][0] << dec << endl;
uint32 motorstatus = (uint32) answer[0][0];
if (owner()->startActivated() == true) {
int32 channel = owner()->leafChannel();
if ((owner()->pauseActivated == true) || ((motorstatus & channel) != 0)) {
status |= MOVING_ACTIVATED;
owner()->calculateProgression();
} else {
// Command finished
if (owner()->startActivated() == true) {
read();
}
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
}
else {
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
answer = writeXmcb2AndRead(SWITCH_STATUS_COMMAND);
if (answer.size() > 1) {
uint32 value = static_cast<uint32>(std::strtoul(answer[0].substr(0, answer[0].size() - 1).c_str(), NULL, 16));
// cout << owner()->getName() << " switches 2 = " << value << endl;
int32 channel = owner()->leafChannel() - 1;
if (value & (HIGH_SWITCH << channel)) {
status |= HIGH_HARDSTOP;
}
if (value & (LOW_SWITCH << channel)) {
status |= LOW_HARDSTOP;
}
if (value & (AMPLIFIER_FAULT << channel)) {
status |= EMERGENCY_STOP;
}
}
owner()->computeAxisStatus(status);
}
}
}
/*
* read
*/
void RealXmcb2AxisDriver::read() {
vector<string> answer = writeXmcb2AndRead(READ_POSITION_COMMAND);
if (answer.size() == 1) {
owner()->actualPosition.update(lexical_cast<float64>(answer[0]));
}
answer = writeXmcb2AndRead(READ_WANTED_POSITION_COMMAND);
if (answer.size() == 1) {
owner()->setPointPosition.update(lexical_cast<float64>(answer[0]));
}
}
/*
* move
*/
void RealXmcb2AxisDriver::move() {
writeXmcb2Value(MOVE_POSITION_COMMAND, owner()->wantedPosition());
}
/*
* continu
*/
void RealXmcb2AxisDriver::continu() {
}
/*
* writeXmcb2
*/
vector<string> RealXmcb2AxisDriver::writeXmcb2AndRead(const std::string& command) {
writeXmcb2(command);
string buf;
owner()->read(buf, TERMINATOR);
// cout << owner()->getName() << " --> " << buf << endl;
vector<string> answer;
typedef tokenizer<char_separator<char> > tokenizer;
// string ssep = SEPARATOR;
// ssep.append(TERMINATOR);
char_separator<char> sep(",\r\n");
tokenizer tok1(buf, sep);
tokenizer::iterator iter = tok1.begin();
while (iter != tok1.end()) {
answer.push_back(*iter);
++iter;
}
return answer;
}
/*
* writeXmcb2
*/
void RealXmcb2AxisDriver::writeXmcb2(const std::string& command) {
ostringstream com;
com << command << TERMINATOR;
// cout << owner()->getName() << " writeXmcb2 : " << command << endl;
dynamic_cast<Xmcb2Driver*>(owner()->getParent())->write(owner(), com.str());
}
}
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef REALXMCB2AXISDRIVER_H
#define REALXMCB2AXISDRIVER_H
#include <drivers/zaber/xmcb2/Xmcb2AxisState.h>
#include <drivers/zaber/xmcb2/Xmcb2Def.h>
#include <drivers/zaber/xmcb2/Xmcb2Driver.h>
namespace xmcb2 {
class Xmcb2AxisDriver;
/*!
* \class RealXmcb2AxisDriver
* \brief Real implementation class for the Rio Axis device driver
*
* This class is a real implementation of Rio Axis device driver.
*/
class RealXmcb2AxisDriver: public Xmcb2AxisState {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
RealXmcb2AxisDriver(Xmcb2AxisDriver* owner);
/*!
* \brief Destructor
*/
virtual ~RealXmcb2AxisDriver();
/*!
* \brief Initialisation implementation
*/
virtual void init();
/*!
* \brief move command implementation
*/
virtual void move();
/*!
* \brief Pause command implementation
*/
virtual void pause();
/*!
* \brief Continu command implementation
*/
virtual void continu();
/*!
* \brief Write encoder command implementation
*/
virtual void writeEncoder();
/*!
* \brief Read command implementation
*/
virtual void read();
/*!
* \brief Read status command implementation
*/
virtual void readStatus();
/*!
* \brief Stop command implementation
*/
virtual void stop();
/*!
* \brief Write parameters command implementation
*/
virtual void writeParam();
/*!
* \brief Home search command implementation
*/
virtual void homeSearch();
/*!
* \brief Go home command implementation
*/
virtual void goHome();
private:
std::vector<std::string> writeXmcb2AndRead(const std::string& command);
template<typename Type> void writeXmcb2Value(const std::string& command, Type value);
void writeXmcb2(const std::string& command);
};
template<typename Type> void RealXmcb2AxisDriver::writeXmcb2Value(const std::string& command, Type value) {
std::ostringstream scom;
scom << command << value << TERMINATOR;
dynamic_cast<Xmcb2Driver*>(owner()->getParent())->write(owner(), scom.str());
}
}
#endif //REALXMCB2AXISDRIVER_H
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include <fstream>
#include "boost/lexical_cast.hpp"
#include <boost/filesystem.hpp>
#include <drivers/zaber/xmcb2/RealXmcb2Driver.h>
#include <drivers/zaber/xmcb2/RealXmcb2Driver.h>