...
 
Commits (5)
......@@ -53,6 +53,8 @@ const int32 RealAkdDriver::CMD_STOP_REGISTER = 5106;
const int32 RealAkdDriver::CMD_POSITION_REGISTER = 5108;
const int32 RealAkdDriver::CMD_SET_POSITION_REGISTER = 5110;
const int32 RealAkdDriver::CMD_READ_HISTO_REGISTER = 5112;
const int32 RealAkdDriver::CMD_USE_CAM_REGISTER = 5114;
const int32 RealAkdDriver::CMD_WRITE_CAM_REGISTER = 5116;
const int32 RealAkdDriver::AMPLITUDE_SETPOINT_REGISTER = 5210; //float value
const int32 RealAkdDriver::AMPLITUDE_ACTUAL_VALUE_REGISTER = 5210; //float value
......@@ -78,6 +80,9 @@ const int32 RealAkdDriver::DURATION_REGISTER = 5230; //int value
const int32 RealAkdDriver::HISTO_POSITION_REGISTER = 5300; //float value
const int32 RealAkdDriver::HISTO_SPEED_REGISTER = 5320; //float value
const int32 RealAkdDriver::VAR_CAM_REGISTER = 5340; //float value
const int32 RealAkdDriver::OFFSET_CAM_REGISTER = 5232; //int value
const int32 RealAkdDriver::SINUS_MAX_VALUE = 2740;
......@@ -270,6 +275,68 @@ void RealAkdDriver::positionMove() {
}
/*
* Position histo
*/
void RealAkdDriver::writeCAM() {
int32 k =0;
vector<string> values;
boost::filesystem::path tmp = "/users/d22/CAM.txt";
ifstream ffile(tmp.string().c_str());
if (ffile.is_open()) {
typedef tokenizer<char_separator<char> > tokenizer;
char_separator<char> sep(" \n");
if (ffile.eof()) {
cerr<< "Prematurity end of file"<<endl;
}
for (int32 i = 0; i < 500; ++i) {
string line;
getline(ffile, line);
if (line.empty() == true) {
return;
}
tokenizer tok1(line, sep);
tokenizer::iterator iter = tok1.begin();
if (iter == tok1.end()) {
cerr<< "Expected more values: " <<endl;
}
if (*iter == "!") {
cerr<< "Expected value instead of comment"<<endl;
}
values.push_back(*iter);
++iter;
}
}
ffile.close();
// sleep(5);
int32 j = 0;
for (int32 i = 0; i <50 ; ++i) {
for (int32 k = 0; k <10 ; ++k) {
float32 wantedValue = lexical_cast<float64>(values[j++]);
int32 wantedFloatContent = *(int32 *) &wantedValue;
int32 valueSetpoint = Calculations::swapD32ByD16(wantedFloatContent);
owner()->writeModbus(VAR_CAM_REGISTER+ k*2, valueSetpoint);
int32 commandSetOffset = Calculations::swapD32ByD16(1+i*10); //send a 1 value to execute command
owner()->writeModbus(OFFSET_CAM_REGISTER,commandSetOffset );
}
int32 commandwritecam = Calculations::swapD32ByD16(1); //send a 1 value to execute command
owner()->writeModbus(CMD_WRITE_CAM_REGISTER,commandwritecam );
}
int32 commandusecam = Calculations::swapD32ByD16(1); //send a 1 value to execute command
owner()->writeModbus(CMD_USE_CAM_REGISTER,commandusecam );
}
/*
* Position histo
*/
......
......@@ -87,7 +87,7 @@ public:
* read histo command implementation
*/
virtual void readHisto();
virtual void writeCAM();
/**
* Read status
......@@ -115,6 +115,8 @@ private:
static const int32 CMD_READ_HISTO_REGISTER;
static const int32 CMD_ACQERROR_REGISTER;
static const int32 CMD_SET_POSITION_REGISTER;
static const int32 CMD_USE_CAM_REGISTER;
static const int32 CMD_WRITE_CAM_REGISTER;
static const int32 STATUS_REGISTER;
static const int32 STATUS_FUNCTION_REGISTER;
static const int32 POSITION_STATUS_REGISTER;
......@@ -122,7 +124,8 @@ private:
static const int32 DURATION_REGISTER;
static const int32 HISTO_SPEED_REGISTER;
static const int32 OFFSET_HISTO_REGISTER;
static const int32 OFFSET_CAM_REGISTER;
static const int32 VAR_CAM_REGISTER;
};
}
......
<module name="pic867">
<driver class="pic867::PIC867Driver"/>
</module>
\ No newline at end of file
/*
* 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 PIC867DEF_H
#define PIC867DEF_H
#include "Utilities/Calculations.h"
namespace pic867 {
/*
* The PIC867 is able to manage 1 axis.
*/
/*
* PIC867 register description
*
* -----------------------------------------------------------------------------
* bit | Description
* -----------------------------------------------------------------------------
* 0 |
* -----------------------------------------------------------------------------
* -----------------------------------------------------------------------------
*/
/*
* PIC867 status register description
*/
static const int32 MAX_AMPLITUDE_REGISTER = 20;
static const int32 MIN_AMPLITUDE_REGISTER = 21;
static const int32 WANTED_SPEED_REGISTER = 22;
static const int32 WANTED_ACCEL_REGISTER = 23;
static const int32 WANTED_PLAGE_REGISTER = 24;
//Parameter Commands
static const char SET_VELOCITY[] = "VEL 1 ";
static const char SET_ACCELERATION[] = "ACC 1 ";
static const char SET_DECELERATION[] = "DEC 1 ";
static const char SET_LIMIT_MIN_MODE[] = "TMN 1 ";
static const char SET_LIMIT_MAX_MODE[] = "TMX 1 ";
static const char SET_POWER_ON[] = "SVO 1 1";
static const char SET_REFERENCE[] = "FRF 1";
static const char DEFINE_HOME[] = "DFH ";
static const char MOVE_ABSOLUTE[] = "MOV 1 ";
static const char MOVE_RELATIVE[] = "MVR 1 ";
static const char GO_HOME[] = "GOH ";
static const char STOP_MOTOR[] = "STP ";
static const char REBOOT_CONTROLLER[] = "RBT ";
static const char GET_VELOCITY[] = "VEL? 1";
static const char GET_POSITION[] = "POS? 1";
static const char GET_ACCELERATION[] = "ACC? 1 ";
static const char GET_DECELERATION[] = "DEC? 1 ";
static const char GET_LIMIT_MIN_MODE[] = "TMN? 1 ";
static const char GET_LIMIT_MAX_MODE[] = "TMX? 1 ";
static const char GET_POWER[] = "SVO? 1";
static const char GET_VERSION[] = "VER?";
static const char READ_STATUS[] = "SRG? 1 1";
static const char READ_MOTION_STATUS[] = "#5";
static const char READ_CONTROLLER_STATUS[] = "#7";
static const char GET_REFERENCE[] = "FRF?";
static const char ACK_TERMINATOR[] = "\n";
static const char SEPARATOR[] = ",";
static const char CR_TERMINATOR[] = "\r";
static const char ESC_TERMINATOR = 27;
static const char LF_TERMINATOR[] = "\n";
static const char TERMINATOR[] = "\n";
static const uint32 TERMINATOR_SIZE = 1;
static const int32 NB_AXIS_DEFAULT = 1;
static const int32 TIME_MAX = 30;
static const int32 NOT_MOVING_MAX = 2;
// Values for the status bits
static const int32 MOTOR_ON = 0x1000;
static const int32 MOTOR_ERROR = 0x0200;
static const int32 OVER_TEMP = 0x00000004;
static const int32 AXIS_READY = 0x00000010;
static const int32 DOWN_DIRECTION = 0x00000040;
static const int32 IS_HOMING = 0x4000;
static const int32 MECHANICAL_ZERO = 0x0002;
static const int32 MECHANICAL_ZERO1 = 0x00004000;
static const int32 LOW_HARDSTOP = 0x0001;
static const int32 HIGH_HARDSTOP = 0x0004;
static const int32 IN_TOLERANCE = 0x8000;
static const int32 RUNNING = 0x2000;
// Values for the timer
static const int32 TIMER_SECONDE = 2;
static const int32 TIMER_USECONDE = 2;
// Values for the offsets for the line
static const int32 INFOS_START = 1;
static const int32 POSITION_START = 2;
static const int32 STATUS = 3;
static const uint32 STATUS_ANSWER = 4;
static const int32 ERROR_CODE_POSITION = 2;
static const int32 ERROR_MESSAGE_POSITION = 3;
//static const int32 EMERGENCY_STOP = 0x0001;
//static const int32 MANUAL_MODE = 0x0008;
//static const int32 BRAKE_ACTIVATED = 0x0010;
//static const int32 MOVING_ACTIVATED = 0x0020;
}
#endif //PIC867DEF_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/pi/pic867/PerfectPIC867Driver.h>
#include <drivers/pi/pic867/PIC867Def.h>
#include <drivers/pi/pic867/PIC867Driver.h>
#include <drivers/pi/pic867/PIC867State.h>
#include <drivers/pi/pic867/RealPIC867Driver.h>
#include <drivers/pi/pic867/SimulatedPIC867Driver.h>
namespace pic867 {
const std::string PIC867Driver::TYPE = "PIC867";
const std::string PIC867Driver::COMMAND_WRITE = "write";
const std::string PIC867Driver::COMMAND_RESET = "reset";
const std::string PIC867Driver::COMMAND_FLASH = "flash";
const std::string PIC867Driver::COMMAND_READ_PARAM = "readParam";
const std::string PIC867Driver::COMMAND_WRITE_PARAM = "writeParam";
/*
* Constructor
*/
PIC867Driver::PIC867Driver(const std::string& name) :
axis::AxisCommon(name), m_pauseActivated(false) ,m_StartedPosition(0) {
driver::RS232::init(name);
registerStates(new RealPIC867Driver(this), new PerfectPIC867Driver(this), new SimulatedPIC867Driver(this));
deceleration.init(this, SAVE, "actual_deceleration","wanted_deceleration");
velocity.init(this, SAVE, "actual_velocity","wanted_velocity");
acceleration.init(this, SAVE, "actual_acceleration","wanted_acceleration");
/*
* Init the device command list
*/
initCommand(COMMAND_WRITE);
initCommand(COMMAND_RESET);
initCommand(COMMAND_FLASH);
initCommand(COMMAND_READ_PARAM);
initCommand(COMMAND_WRITE_PARAM);
// Init functions
registerFunction(NONE_FUNCTION);
deviceType = LEAF_DEVICE_TYPE_DEVICE_CONTAINER;
registerRefresher(wantedPosition, &PIC867Driver::refreshWantedPositionProperty, this);
/*
* Register the Spy and Observer commands necessary to do the updates.
*/
registerSpyCommand(driver::READ_COMMAND, 5);
registerSpyCommand(driver::STATUS_COMMAND, 5);
registerObserverCommand(driver::READ_COMMAND, 40);
registerObserverCommand(driver::STATUS_COMMAND, 40);
}
/*
* Destructor
*/
PIC867Driver::~PIC867Driver() {
}
/*
* execute
*/
void PIC867Driver::execute(const std::string& aCommand) {
if ((aCommand != driver::STOP_COMMAND) && (aCommand != driver::PAUSE_COMMAND) && (aCommand != driver::RESUME_COMMAND)
&& (aCommand != COMMAND_RESET) && (aCommand != driver::STATUS_COMMAND) && (aCommand != driver::PAUSE_COMMAND)) {
commandProgression = PROGRESSION_UNKNOWNSTATE_DEVICE_CONTAINER;
}
PIC867State* currentState = dynamic_cast<PIC867State*>(getCurrentState());
if (aCommand == driver::INIT_COMMAND) {
// init
currentState->init();
} else if (aCommand == COMMAND_WRITE_PARAM) {
// Write command
currentState->writeParam();
} else if (aCommand == COMMAND_WRITE) {
// Write command
currentState->write();
} else if (aCommand == driver::READ_COMMAND) {
// Read command
currentState->read();
} else if (aCommand == driver::START_COMMAND) {
// Start command
startActivated = true;
m_StartedPosition = actualPosition();
currentState->move();
} else if (aCommand == COMMAND_RESET) {
// Stop command
startActivated = false;
currentState->reset();
} else if (aCommand == driver::STOP_COMMAND) {
// Stop command
startActivated = false;
m_pauseActivated = false;
currentState->stop();
} else if (aCommand == driver::PAUSE_COMMAND) {
// Pause command
if (startActivated() == true) {
m_pauseActivated = true;
currentState->stop();
}
} else if (aCommand == driver::RESUME_COMMAND) {
// Continu command
if (m_pauseActivated == true) {
currentState->move();
m_pauseActivated = false;
}
} else if (aCommand == driver::STATUS_COMMAND) {
// Status command
currentState->readStatus();
} else if (aCommand == COMMAND_FLASH) {
// Status command
currentState->flash();
} else if (aCommand == COMMAND_READ_PARAM) {
// Read param command
currentState->readParam();
} else {
//Error bad command
//Todo , normaly it will be detect it device action driver
}
}
/*
* refreshWantedPositionProperty
*/
void PIC867Driver::refreshWantedPositionProperty(float64 value) throw (CannotSetValue) {
computeAxisStatus(status());
}
/*
* calculateProgression
*/
void PIC867Driver::calculateProgression() {
int32 progression = 0;
if (m_StartedPosition == wantedPosition()) {
progression = PROGRESSION_END_DEVICE_CONTAINER;
} else {
progression = PROGRESSION_END_DEVICE_CONTAINER
- (int32) (fabs(wantedPosition() - actualPosition()) / fabs(wantedPosition() - m_StartedPosition)
* PROGRESSION_RATIO_DEVICE_CONTAINER);
}
// Be sure that progression > 0%
if (progression < PROGRESSION_UNKNOWNSTATE_DEVICE_CONTAINER)
progression = 0;
// Be sure that only Phased status put 100%
if (progression >= PROGRESSION_END_DEVICE_CONTAINER)
progression = PROGRESSION_END_DEVICE_CONTAINER - 1;
commandProgression = progression;
}
/*
* computeAxisStatus
*/
void PIC867Driver::computeAxisStatus(int32 value) {
int32 valueout = 0;
if (value & (int32) pic867::RUNNING) {
valueout |= AxisCommon::MOVING;
} else if (value & pic867::LOW_HARDSTOP) {
valueout |= AxisCommon::LOW_HARDSTOP;
} else if (value & pic867::HIGH_HARDSTOP) {
valueout |= AxisCommon::HIGH_HARDSTOP;
}
if (valueout == 0) {
// In precision flag setting
float64 delta = fabs(wantedPosition() - actualPosition());
float64 tol = tolerance();
if (delta <= tol) {
valueout |= AxisCommon::IN_PRECISION;
} else {
valueout &= ~(AxisCommon::IN_PRECISION);
}
}
status.update(value);
axisStatus.update(valueout);
}
}
/*
* 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.
*/
/* Generated by Together */
#ifndef PIC867DRIVER_H
#define PIC867DRIVER_H
#include "controllers/common/axis/AxisCommon.h"
#include "drivers/global/RS232.h"
namespace pic867 {
/*!
* \class PIC867Driver
* \brief Main class for the PIC867Driver device driver
*
* \par
* Class for PIC867Driver driver. Implements DeviceDriver methods.
* \par
* The PIC867Driver device is axis controller using motor and encoder.
*/
class PIC867Driver: public axis::AxisCommon, public driver::RS232 {
friend class RealPIC867Driver;
friend class PerfectPIC867Driver;
friend class SimulatedPIC867Driver;
public:
static const std::string TYPE;
/*!
* true for instant command
*/
Property<float64, SETPOINT> acceleration;
Property<float64, SETPOINT> deceleration;
Property<float64, SETPOINT> velocity;
/*!
* \brief Constructor
* \param[in] name the name of the device driver
*/
PIC867Driver(const std::string& name);
/*!
* \brief Destructor
*/
virtual ~PIC867Driver();
/*!
* \brief Method called for executing a command
* \param[in] command the command to apply on the controller
*/
virtual void execute(const std::string& aCommand);
private:
/*!
* \brief Calculate the progression state.
*/
void calculateProgression();
/*!
* \brief Method called before changing the wanted position property value
* \param[in] value the property value
* \throws CannotSetValue the value isn't corrected, or property couldn't be changed
*/
virtual void refreshWantedPositionProperty(float64 value) throw (CannotSetValue);
/*!
* \brief compute global axis status
* \param[in] value the driver status
*/
virtual void computeAxisStatus(int32 value);
bool m_pauseActivated;
float64 m_StartedPosition;
static const std::string COMMAND_WRITE;
static const std::string COMMAND_RESET;
static const std::string COMMAND_FLASH;
static const std::string COMMAND_READ_PARAM;
static const std::string COMMAND_WRITE_PARAM;
};
}
#endif //PIC867DRIVER_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.
*/
/* Generated by Together */
#ifndef PIC867STATE_H
#define PIC867STATE_H
#include <drivers/pi/pic867/PIC867Driver.h>
#include <Driver.h>
namespace pic867 {
/*!
* \class PIC867State
* \brief Virtual class for implement State pattern
*
* Define all methods that perfect, simulated and real classes have to implement
*/
class PIC867State: public DriverState<PIC867Driver> {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
PIC867State(PIC867Driver* owner) :
DriverState<PIC867Driver>(owner) {
}
/*!
* \brief Destructor
*/
virtual ~PIC867State() {
}
/*!
* \brief read infos
*/
virtual void readInfos() = 0;
/*!
* \brief Write parameters command implementation
*/
virtual void writeParam() = 0;
/*!
* \brief Write encoder value
*/
virtual void write() = 0;
/*!
* \brief Read parameters command implementation
*/
virtual void readParam() = 0;
/*!
* \brief move command implementation
*/
virtual void move() = 0;
/*!
* \brief Read command implementation
*/
virtual void read() = 0;
/*!
* \brief Read status command implementation
*/
virtual void readStatus() = 0;
/*!
* \brief reset command implementation
*/
virtual void reset() = 0;
/*!
* \brief Stop command implementation
*/
virtual void stop() = 0;
/*!
* \brief flash command implementation
*/
virtual void flash() = 0;
};
}
#endif //PIC867DRIVER_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/pi/pic867/PerfectPIC867Driver.h>
#include <drivers/pi/pic867/PIC867Def.h>
#include <fstream>
#include "NameServer.h"
using namespace std;
namespace pic867 {
/*
* Constructor
*/
PerfectPIC867Driver::PerfectPIC867Driver(PIC867Driver* owner) :
PIC867State(owner) {
/* Empty */
}
/*
* Destructor
*/
PerfectPIC867Driver::~PerfectPIC867Driver() {
/* Empty */
}
/*
* init
*/
void PerfectPIC867Driver::init() {
}
/*
* writeParam
*/
void PerfectPIC867Driver::writeParam() {
}
/*
* write
*/
void PerfectPIC867Driver::write() {
}
/*
* readParam
*/
void PerfectPIC867Driver::readParam() {
}
/*
* readInfos
*/
void PerfectPIC867Driver::readInfos() {
}
/*
* move
*/
void PerfectPIC867Driver::move() {
owner()->actualPosition = owner()->wantedPosition();
}
/*
* read
*/
void PerfectPIC867Driver::read() {
}
/*
* readStatus
*/
void PerfectPIC867Driver::readStatus() {
owner()->computeAxisStatus(pic867::AXIS_READY);
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
/*
* reset
*/
void PerfectPIC867Driver::reset() {
}
/*
* stop
*/
void PerfectPIC867Driver::stop() {
}
/*
* flash
*/
void PerfectPIC867Driver::flash() {
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
}
/*
* 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.
*/
/* Generated by Together */
#ifndef PERFECTPIC867DRIVER_H
#define PERFECTPIC867DRIVER_H
#include <drivers/pi/pic867/PIC867State.h>
namespace pic867 {
class PIC867Driver;
/*!
* \class PerfectPIC867Driver
* \brief Perfect implementation class for the PIC867Axis device driver
*
* This class is a perfect implementation of PIC867Axis device driver.
* On start command, all actual values become target's ones.
*/
class PerfectPIC867Driver: public PIC867State {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
PerfectPIC867Driver(PIC867Driver* owner);
/*!
* \brief Destructor
*/
virtual ~PerfectPIC867Driver();
/*!
* \brief Initialisation implementation
*/
virtual void init();
/*!
* \brief read infos
*/
virtual void readInfos();
/*!
* \brief Write parameters command implementation
*/
virtual void writeParam();
/*!
* \brief Write encoder value
*/
virtual void write();
/*!
* \brief Read parameters command implementation
*/
virtual void readParam();
/*!
* \brief move command implementation
*/
virtual void move();
/*!
* \brief Read command implementation
*/
virtual void read();
/*!
* \brief Read status command implementation
*/
virtual void readStatus();
/*!
* \brief reset command implementation
*/
virtual void reset();
/*!
* \brief Stop command implementation
*/
virtual void stop();
/*!
* \brief flash command implementation
*/
virtual void flash();
};
}
#endif //PERFECTPIC867DRIVER_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/pi/pic867/PIC867Def.h>
#include <drivers/pi/pic867/PIC867Driver.h>
#include <drivers/pi/pic867/RealPIC867Driver.h>
#include <fstream>
#include "NameServer.h"
#include "Utilities/Calculations.h"
using namespace std;
namespace pic867 {
/*
* Constructor
*/
RealPIC867Driver::RealPIC867Driver(PIC867Driver* owner) :
PIC867State(owner) {
/* Empty */
}
/*
* Destructor
*/
RealPIC867Driver::~RealPIC867Driver() {
/* Empty */
}
/*
* init
*/
void RealPIC867Driver::init() {
string command;
string buf;
string buf_temp;
ostringstream buf_out;
ostringstream buf_out1;
ostringstream buf_out2;
int32 ref;
buf_out1 << SET_POWER_ON << TERMINATOR;
writeCmd(buf_out1.str());
buf_out << GET_REFERENCE << TERMINATOR;
owner()->write(buf_out.str());
usleep(50000);
owner()->read(buf, ACK_TERMINATOR);
cout <<" GET_REFERENCE buf = " << buf<<endl;
buf.resize(buf.size() - TERMINATOR_SIZE);
buf_temp.assign(buf, POSITION_START, buf.size() -POSITION_START);
cout <<" GET_REFERENCE buf = " << buf_temp<<endl;
istringstream buf_ref(buf_temp);
buf_ref>> ref;
cout <<" GET_REFERENCE = " << ref<<endl;
if (ref==0){
buf_out2 << SET_REFERENCE << TERMINATOR;
writeCmd(buf_out2.str());
}
owner()->division=10000;
readParam();
readInfos();
// stop();
}
void RealPIC867Driver::writeParam() {
ostringstream buf_out1;
ostringstream buf_out2;
ostringstream buf_out3;
ostringstream buf_out4;
ostringstream buf_out5;
int32 velocity = owner()->velocity.setpoint();
int32 acceleration = owner()->acceleration.setpoint();
float64 deceleration = owner()->deceleration.setpoint();
// float64 minpos = owner()->minPosition();
// float64 maxpos =owner()->maxPosition();
buf_out5 << SET_VELOCITY << velocity << TERMINATOR;
writeCmd(buf_out5.str());
buf_out4 << SET_ACCELERATION << acceleration << TERMINATOR;
writeCmd(buf_out4.str());
buf_out2 << SET_DECELERATION << deceleration << TERMINATOR;
writeCmd(buf_out2.str());
readParam();
}
void RealPIC867Driver::write() {
ostringstream buf_out1;
}
void RealPIC867Driver::readParam() {
// get velocity
float64 velocity = 0;
float64 acceleration = 0;
float64 deceleration = 0;
float64 minpos = 0;
float64 maxpos = 0;
string buf_in, buf_temp;
string buf_out;
buf_out = GET_VELOCITY;
buf_out.append(TERMINATOR);
owner()->write(buf_out);
owner()->read(buf_in, ACK_TERMINATOR);
buf_in.resize(buf_in.size() - TERMINATOR_SIZE);
buf_temp.assign(buf_in, POSITION_START, buf_in.size() - POSITION_START);
istringstream buf_velocity(buf_temp);
buf_velocity >> velocity;
owner()->velocity = velocity;
buf_out = GET_ACCELERATION;
buf_out.append(TERMINATOR);
owner()->write(buf_out);
owner()->read(buf_in, ACK_TERMINATOR);
buf_in.resize(buf_in.size() - TERMINATOR_SIZE);
buf_temp.assign(buf_in, POSITION_START, buf_in.size() - POSITION_START);
istringstream buf_acceleration(buf_temp);
buf_acceleration>> acceleration;
owner()->acceleration = acceleration;
buf_out = GET_DECELERATION;
buf_out.append(TERMINATOR);
owner()->write(buf_out);
owner()->read(buf_in, ACK_TERMINATOR);
buf_in.resize(buf_in.size() - TERMINATOR_SIZE);
buf_temp.assign(buf_in, POSITION_START, buf_in.size() - POSITION_START);
istringstream buf_deceleration(buf_temp);
buf_deceleration>> deceleration;
owner()->deceleration = deceleration;
buf_out = GET_LIMIT_MIN_MODE;
buf_out.append(TERMINATOR);
owner()->write(buf_out);
owner()->read(buf_in, ACK_TERMINATOR);
buf_in.resize(buf_in.size() - TERMINATOR_SIZE);
buf_temp.assign(buf_in, POSITION_START, buf_in.size() - POSITION_START);
istringstream buf_minpos(buf_temp);
buf_minpos>> minpos;
owner()->minPosition= minpos;
buf_out = GET_LIMIT_MAX_MODE;
buf_out.append(TERMINATOR);
owner()->write(buf_out);
owner()->read(buf_in, ACK_TERMINATOR);
buf_in.resize(buf_in.size() - TERMINATOR_SIZE);
buf_temp.assign(buf_in, POSITION_START, buf_in.size() - POSITION_START);
istringstream buf_maxpos(buf_temp);
buf_maxpos>> maxpos;
owner()->maxPosition = maxpos;
}
/*
* move
*/
void RealPIC867Driver::move() {
string buf_in, buf_temp;
ostringstream buf_out1, buf_out2, buf_out3, buf_out4, buf_out5;
float64 position = owner()->wantedPosition();;
// power "on"
buf_out1 << SET_POWER_ON << TERMINATOR;
writeCmd(buf_out1.str());
// move
buf_out3 << MOVE_ABSOLUTE << position << TERMINATOR;
writeCmd(buf_out3.str());
}
/*
* readInfos
*/
void RealPIC867Driver::readInfos() {
string buf_in, buf_temp;
ostringstream buf_out;
buf_out << GET_VERSION << TERMINATOR;
owner()->write(buf_out.str());
owner()->read(buf_in, ACK_TERMINATOR);
// cout<<"readStatus buf_in "<< buf_in<<endl;
buf_in.resize(buf_in.size() - TERMINATOR_SIZE);
buf_temp.assign(buf_in, INFOS_START, buf_in.size() - INFOS_START);
owner()->version = buf_temp;
}
/*
* read
*/
void RealPIC867Driver::read() {
float64 data = 0;
string buf_in, buf_temp;
ostringstream buf_out;
buf_out << GET_POSITION << TERMINATOR;
owner()->write(buf_out.str());
usleep(50000);
// cout<<" position data "<< buf_out.str()<<endl;
owner()->read(buf_in, ACK_TERMINATOR);
cout <<" GET_POSITION = " << buf_in<<endl;
buf_in.resize(buf_in.size() - TERMINATOR_SIZE);
if (buf_in.size() > 1) {
buf_temp.assign(buf_in, POSITION_START, buf_in.size() - POSITION_START);
cout <<" GET_POSITION = " << buf_temp<<endl;
// cout<<" position data1 "<<endl;
istringstream buf_float64(buf_temp);
buf_float64 >> data;
// cout<<" position data "<< position<<endl;
owner()->actualPosition = data;
}
}
/*
* readStatus
*/
void RealPIC867Driver::readStatus() {
//
int32 status = 0;
int32 data = 0;
ostringstream buf_out;
float64 delta = owner()->wantedPosition() - owner()->actualPosition();
int32 sens;
if (delta >= 0) {
sens = 1;
} else {
sens = -1;
}
if (owner()->m_pauseActivated == false) {
buf_out << READ_STATUS << TERMINATOR;
owner()->write(buf_out.str());
usleep(50000);
string buf_in, buf_temp;
owner()->read(buf_in, ACK_TERMINATOR);
cout <<" READ_STATUS = " << buf_in<<endl;
buf_in.resize(buf_in.size() - TERMINATOR_SIZE);
if (buf_in.size() > 1) {
buf_temp.assign(buf_in, 4, buf_in.size() - 4);
cout <<" READ_STATUS = " << buf_temp<<endl;
data=stoi(buf_temp, 0, 16);
// istringstream buf_float64(buf_temp);
// buf_float64 >> data;
cout <<" READ_STATUS = " << data<<endl;
if (data & pic867::IS_HOMING) {
cout << "IS_MOVING " << endl;
status |= pic867::IS_HOMING;
}
if ((data & pic867::HIGH_HARDSTOP) ) {
cout << " HIGH_HARDSTOP" << endl;
status |= pic867::HIGH_HARDSTOP;
}
if ((data & pic867::LOW_HARDSTOP) ) {
status |= pic867::LOW_HARDSTOP;
cout << " LOW_HARDSTOP" << endl;
}
if (data & pic867::MOTOR_ERROR) {
status |= pic867::MOTOR_ERROR;
cout << " MOTOR_ERROR" << endl;
}
// In precision flag setting
if (owner()->startActivated() == true) {
if (data & pic867::IN_TOLERANCE) {
status |= pic867::IN_TOLERANCE;
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
} else {
status |= pic867::RUNNING;
owner()->calculateProgression();
}
} else {
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
owner()->computeAxisStatus(status);
}
}
}
/*
* reset
*/
void RealPIC867Driver::reset() {
ostringstream buf_out;
string cmd;
cmd = REBOOT_CONTROLLER;
cmd.append(TERMINATOR);
writeCmd(cmd);
}
/*
* stop
*/
void RealPIC867Driver::stop() {
ostringstream buf_out;
buf_out << STOP_MOTOR << TERMINATOR;
writeCmd(buf_out.str());
}
void RealPIC867Driver::flash() {
}
void RealPIC867Driver::writeCmd(const std::string& command) {
string buf;
owner()->write(command);
cout << "Sending --> " << command<< endl;
ostringstream buf_out;
usleep(50000);
buf_out << "ERR?" << TERMINATOR;
owner()->write(buf_out.str());
//writeCmd(buf_out.str());
owner()->read(buf, ACK_TERMINATOR);
cout << "receiving <-- " << buf<< endl;
}
}
/*
* 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.
*/
/* Generated by Together */
#ifndef REALPIC867DRIVER_H
#define REALPIC867DRIVER_H
#include <drivers/pi/pic867/PIC867State.h>
namespace pic867 {
class PIC867Driver;
/*!
* \class RealPIC867Driver
* \brief Real implementation class for the PIC867 Axis device driver
*
* This class is a real implementation of PIC867 Axis device driver.
*/
class RealPIC867Driver: public PIC867State {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
RealPIC867Driver(PIC867Driver* owner);
/*!
* \brief Destructor
*/
~RealPIC867Driver();
/*!
* \brief Initialisation implementation
*/
virtual void init();
/*!
* \brief read infos
*/
virtual void readInfos();
/*!
* \brief Write parameters command implementation
*/
virtual void writeParam();
/*!
* \brief Write encoder value
*/
virtual void write();
/*!
* \brief Read parameters command implementation
*/
virtual void readParam();
/*!
* \brief move command implementation
*/
virtual void move();
/*!
* \brief Read command implementation
*/
virtual void read();
/*!
* \brief Read status command implementation
*/
virtual void readStatus();
/*!
* \brief reset command implementation
*/
virtual void reset();
/*!
* \brief Stop command implementation
*/
virtual void stop();
/*!
* \brief flash command implementation
*/
virtual void flash();
private:
/*!
* \brief wrtie command to lac
* \param[in] command The command std::string
*/
void writeCmd(const std::string& command);
};
}
#endif //REALPIC867DRIVER_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/pi/pic867/PIC867Def.h>
#include <drivers/pi/pic867/PIC867Driver.h>
#include <drivers/pi/pic867/SimulatedPIC867Driver.h>
namespace pic867 {
/*
* Constructor
*/
SimulatedPIC867Driver::SimulatedPIC867Driver(PIC867Driver* owner) :
PIC867State(owner) {
m_lastTime = time(0);
}
/*
* Destructor
*/
SimulatedPIC867Driver::~SimulatedPIC867Driver() {
/* Empty */
}
/*
* reset
*/
void SimulatedPIC867Driver::reset() {
}
/*
* flash
*/
void SimulatedPIC867Driver::flash() {
}
/*
* readInfos
*/
void SimulatedPIC867Driver::readInfos() {
}
/*
* write
*/
void SimulatedPIC867Driver::write() {
}
/*
* readParam
*/
void SimulatedPIC867Driver::readParam() {
}
/*
* writeParam
*/
void SimulatedPIC867Driver::writeParam() {
}
/*
* stop
*/
void SimulatedPIC867Driver::stop() {
}
/*
* readInfos
*/
void SimulatedPIC867Driver::readStatus() {
/*
* status command
*/
bool moveok = true;
bool movewait = false;
uint32 status = 0;
float64 actual = owner()->actualPosition();
float64 wanted = owner()->wantedPosition();
float64 delta = wanted - actual;
if ((owner()->startActivated() == true)
&& (owner()->m_pauseActivated == false)) {
//cout << " SimulatedPIC867Driver::readStatus() 1ter" << endl;
float64 tolerance = owner()->tolerance();
if (tolerance < 0.001) {
tolerance = 0.001;
}
if (fabs(delta) <= tolerance) {
moveok = false;
}
}
if (owner()->startActivated() == true) {
status |= pic867::RUNNING;
}
owner()->computeAxisStatus(status);
if ((moveok == false) || ((owner()->startActivated() == false) )) {
owner()->startActivated = false;
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
}
/*
* read
*/
void SimulatedPIC867Driver::read() {
}
/*
* move
*/
void SimulatedPIC867Driver::move() {
// Move command
m_lastTime = time(0);
owner()->setPointPosition.update(owner()->wantedPosition());
}
void SimulatedPIC867Driver::init() {
owner()->commandProgression = PROGRESSION_END_DEVICE_CONTAINER;
}
}
/*
* 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 SIMULATEDPIC867DRIVER_H
#define SIMULATEDPIC867DRIVER_H
#include <drivers/pi/pic867/PIC867State.h>
#include <ctime>
namespace pic867 {
class PIC867Driver;
/*!
* \class SimulatedPIC867Driver
* \brief simulated implementation class for the PIC867Axis device driver
*
* This class is a simulated implementation of PIC867Axis device driver.
* On start command, all actual values become target's ones after a time as done a real axis.
*/
class SimulatedPIC867Driver: public PIC867State {
public:
/*!
* \brief Constructor
* \param[in] owner The device driver main class link
*/
SimulatedPIC867Driver(PIC867Driver *owner);
/*!
* \brief Destructor
*/
virtual ~SimulatedPIC867Driver();
/*!
* \brief Initialisation implementation
*/
virtual void init();
/*!
* \brief read infos
*/
virtual void readInfos();
/*!
* \brief Write parameters command implementation
*/
virtual void writeParam();
/*!
* \brief Write encoder value
*/
virtual void write();
/*!
* \brief Read parameters command implementation
*/
virtual void readParam();
/*!
* \brief move command implementation
*/
virtual void move();
/*!
* \brief Read command implementation
*/
virtual void read();
/*!
* \brief Read status command implementation
*/
virtual void readStatus();
/*!
* \brief reset command implementation
*/
virtual void reset();
/*!
* \brief Stop command implementation
*/
virtual void stop();
/*!
* \brief flash command implementation
*/
virtual void flash();
private:
/**
* Last sample reading time
*/
time_t m_lastTime;
};
}
#endif //SIMULATEDPIC867DRIVER_H
# Commands
PIC867.writeParam=Write Param
PIC867.manualMove=Manual Move
PIC867.stop=Stop
PIC867.versionPrefix=version:
# Labels
PIC867.maxSpeed=Max Speed
PIC867.wanted_speedPrefix=wanted speed
PIC867.actual_speedPrefix=wanted speed
PIC867.accel=Acceleration
PIC867.decel=Deceleration
PIC867.actualPosition=Actual position
PIC867.wantedPosition=Wanted position
PIC867.maxPosition=High limit
PIC867.minPosition=Low limit
PIC867.tolerance=Tolerance
PIC867.division=Division
PIC867.status=Status
PIC867.offset=Offset
PIC867.ratioUnitPrefix=Ratio
PIC867.ratioPoint=points
PIC867.ratioUnitSuffix=unit
PIC867.unit=Unit
PIC867.writeEncoder=Set
#Group Axis Manual Testing
PIC867.manualMoveTesting=Manual Move Testing
PIC867.manual_direction=Direction
PIC867.downLabel=Down
PIC867.downValue=0
PIC867.upLabel=Up
PIC867.upValue=1
PIC867.man_speed=manual Speed
# Conversion group
PIC867.useRatio=Use Ratio
PIC867.useRatioCheckedValue=1
PIC867.useRatioUncheckedValue=0
PIC867.ratioUnityPrefix=Ratio
PIC867.ratioUnitySuffix=unit
PIC867.ratioSteps=Points
PIC867.slash= /
# Group title
PIC867.motor=Motor
PIC867.axis=Axis Parameters
PIC867.coderParameter=Coder Parameters
PIC867.encoderWrite=Coder value
# Summary
PIC867.inToleranceValue=8
PIC867.lowHardStopValue=524288
PIC867.highHardStopValue=131072
PIC867.moving_posValue=1024
PIC867.moving_negValue=2048
PIC867.inToleranceLabel=In tolerance
PIC867.lowHardStopLabel=Low hard stop
PIC867.highHardStopLabel=High hard stop
PIC867.moving_posLabel=Moving
PIC867.moving_negLabel=Moving