68 if(this->
verbose) std::cout <<
" [EPOS2] " << text.str() << std::endl;
76 if(this->
verbose) std::cout <<
" [EPOS2] " << text << std::endl;
113 CEpos2::ftdi.set_line_property(BITS_8, STOP_BIT_1, NONE);
125 int32_t result = 0x00000000;
126 int16_t req_frame[4];
127 uint16_t ans_frame[4];
129 req_frame[0] = 0x0210;
130 req_frame[1] = index;
131 req_frame[2] = ((0x0000 | this->
node_id) << 8) | subindex;
132 req_frame[3] = 0x0000;
145 if(ans_frame[3]==0x8090)
146 result = ans_frame[2];
148 result = (ans_frame[3] << 16) | ans_frame[2];
161 int16_t req_frame[6]={0,0,0,0,0,0};
162 uint16_t ans_frame[40]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
164 req_frame[0] = 0x0411;
165 req_frame[1] = index;
166 req_frame[2] = ((0x0000 | this->
node_id) << 8) | subindex;
167 req_frame[3] = data & 0x0000FFFF;
168 req_frame[4] = data >> 16;
169 req_frame[5] = 0x0000;
175 if(ans_frame[3]==0x8090)
176 result = ans_frame[2];
178 result = (ans_frame[3] << 16) | ans_frame[2];
188 uint8_t trans_frame[80];
189 int16_t length = ((frame[0] & 0xFF00) >> 8 ) + 2;
195 trans_frame[0] = 0x90;
196 trans_frame[1] = 0x02;
203 trans_frame[tf_i] = frame[i] & 0x00FF;
204 if( trans_frame[tf_i] == 0x90 )
207 trans_frame[tf_i] = 0x90;
212 trans_frame[tf_i] = (frame[i] & 0xFF00) >> 8;
213 if( trans_frame[tf_i] == 0x90 )
216 trans_frame[tf_i] = 0x90;
223 throw EPOS2IOException(
"Impossible to write Status Word.\nIs the controller powered ?");
232 uint16_t read_desired = 0;
233 uint16_t read_real = 0;
235 uint16_t read_point = 0;
237 bool packet_complete =
false;
240 uint8_t *read_buffer = NULL;
241 uint8_t *data = NULL;
249 read_buffer =
new uint8_t[read_desired];
251 read_real =
CEpos2::ftdi.read(read_buffer, read_desired);
255 delete[] read_buffer;
258 throw EPOS2IOException(
"Impossible to read Status Word.\nIs the controller powered ?");
261 for(uint16_t i=0;i<read_real;i++)
267 if(read_buffer[i] == 0x90)
274 if(read_buffer[i] == 0x02)
285 Len = read_buffer[i];
288 data =
new uint8_t[Len*2];
294 data[read_point] = read_buffer[i];
295 if(data[read_point]==0x90)
299 if(read_point+1 == Len*2)
311 cheksum[1] = read_buffer[i];
312 if(cheksum[1]==0x90){
320 cheksum[0] = read_buffer[i];
321 if(cheksum[0]==0x90){
325 packet_complete =
true;
335 packet_complete =
true;
340 delete[] read_buffer;
342 }
while(!packet_complete);
347 for(
int i = 0; i < Len; i++)
349 ans_frame[i] = 0x0000;
351 ans_frame[i] = data[tf_i];
354 ans_frame[i] = (data[tf_i]<<8) | ans_frame[i];
373 while(numberOfWords--)
379 carry = CRC & 0x8000;
381 if(c & shifter) CRC++;
382 if(carry) CRC ^= 0x1021;
404 s <<
"Estat: " << ans <<
" / std::dec= " <<std::dec<< ans;
409 bits[0]= (ans & 0x0001);
410 bits[1]= (ans & 0x0002);
411 bits[2]= (ans & 0x0004);
412 bits[3]= (ans & 0x0008);
414 bits[4]= (ans & 0x0010);
415 bits[5]= (ans & 0x0020);
416 bits[6]= (ans & 0x0040);
417 bits[7]= (ans & 0x0080);
419 bits[8]= ans & 0x0100;
420 bits[9]= ans & 0x0200;
421 bits[10]= ans & 0x0400;
422 bits[11]= ans & 0x0800;
424 bits[12]= ans & 0x1000;
425 bits[13]= ans & 0x2000;
426 bits[14]= ans & 0x4000;
427 bits[15]= ans & 0x8000;
454 p(
"State: Measure Init");
466 p(
"State: Switch on disabled");
471 p(
"State: Operation Enable");
475 p(
"State: Switched On");
478 p(
"State: Ready to Switch On");
485 p(
"State: Quick Stop Active");
488 p(
"State: Not Ready to Switch On");
493 p(
"State: Fault Reaction Active (Enabled)");
497 p(
"State: Fault Reaction Active (Disabled)");
604 name=
"Profile Position";
607 name=
"Profile Velocity";
610 name=
"Interpolated Profile Position";
634 int estat=0,timeout=0;
635 bool controller_connected =
false;
639 while( !controller_connected && timeout<10 )
665 controller_connected =
true;
733 return((
bool)(ans & 0x0400));
797 int intmode = 0x000F;
807 int intmode = 0x010F;
834 int halt = mode==
HALT ? 0x0100 : 0x0000;
835 int rel = mode==
RELATIVE ? 0x0040 : 0x0000;
836 int nowait = !wait ? 0x0020 : 0x0000;
837 int newsetpoint = new_point ? 0x0010 : 0x0000;
839 int intmode = 0x000F | halt | rel | nowait | newsetpoint;
978 long &vspf,
long &pp,
long &pi,
long &pd,
997 long pp,
long pi,
long pd,
long pv,
long pa)
1016 long pp,
long pi,
long pd,
long pv,
long pa)
1018 std::cout <<
" [EPOS2] Control Parameters:" << std::endl;
1019 std::cout <<
" [EPOS2] Current: P = " << cp <<
" I = " << ci << std::endl;
1020 std::cout <<
" [EPOS2] Velocity: P = " << vp <<
" I = " << vi <<
" SetPointFactorP = " << vspf << std::endl;
1021 std::cout <<
" [EPOS2] Position: P = " << pp <<
" I = " << pi <<
" D = "<< pd << std::endl;
1022 std::cout <<
" [EPOS2] Vff = " << pv <<
" Aff = " << pa << std::endl;
1100 long &qsdec,
long &maxacc,
long &type)
1112 long qsdec,
long maxacc,
long type)
1122 long v,m,a,d,q,ma,t;
1199 long vel_actual,vel_avg,vel_demand;
1200 int cur_actual,cur_avg,cur_demand;
1202 bool verbose_status;
1204 verbose_status = this->
verbose;
1217 printf(
"\r [EPOS2] p: %ld v: %ld vavg: %ld vd: %ld c: %d cavg: %d cd: %d ",pos,vel_actual,vel_avg,vel_demand,cur_actual,cur_avg,cur_demand);
1229 std::stringstream s;
1233 bits[0]= (ans & 0x0001);
1234 bits[1]= (ans & 0x0002);
1235 bits[2]= (ans & 0x0004);
1236 bits[3]= (ans & 0x0008);
1238 bits[4]= (ans & 0x0010);
1239 bits[5]= (ans & 0x0020);
1240 bits[7]= (ans & 0x0080);
1242 if(bits[7]) error_num=6;
1243 if(bits[5]) error_num=5;
1244 if(bits[4]) error_num=4;
1246 if(bits[3]) error_num=3;
1247 if(bits[2]) error_num=2;
1248 if(bits[1]) error_num=1;
1249 if(bits[0]) error_num=0;
1251 s <<
"Error: "<< error_num <<
" " << this->
error_names[(
unsigned char)error_num] <<
1252 " Value: 0x" <<std::hex<< ans <<
" , " <<std::dec<< ans;
1260 std::string error_des;
1262 long number_errors = this->
readObject(0x1003, 0x00);
1263 std::cout <<
" [EPOS2-ERROR] Number of Errors: " << number_errors << std::endl;
1266 for(
int i=1;i<=number_errors;i++){
1271 std::cout <<
" [EPOS2-ERROR] id: " << i <<
" : " << std::hex <<
"0x"<< ans <<
" = " << error_des << std::endl;
1279 std::stringstream s;
1283 while( !found && j < 34 ){
1295 if(!found)
return "No Description for this error";
1296 else return "Error Description";
1497 return(positiu-65536);
1553 usleep(1000000*0.05);
1563 int acc,
int digitalIN)
1583 usleep(1000000*0.05);
1643 std::cout <<
" [EPOS2] Move Load to 0 position and press a key ";
1645 std::cout << std::endl;
1646 std::cout <<
" [EPOS2] Wait until process finishes" << std::endl;
1655 std::cout <<
" [EPOS2] Restart EPOS2 (unplug from current) after that the new home will be set" << std::endl;
1662 "Temperature Error",
1663 "Communication Error",
1664 "Device profile specific",
1708 "Over Current Error",
1709 "Over Voltage Error",
1712 "Supply Voltage (+5V) Too Low",
1713 "Supply Voltage Output Stage Too Low",
1714 "Internal Software Error",
1715 "Software Parameter Error",
1716 "Sensor Position Error",
1717 "CAN Overrun Error (Objects lost)",
1718 "CAN Overrun Error",
1719 "CAN Passive Mode Error",
1720 "CAN Life Guard Error",
1721 "CAN Transmit COB-ID collision",
1723 "CAN Rx Queue Overrun",
1724 "CAN Tx Queue Overrun",
1725 "CAN PDO length Error",
1727 "Hall Sensor Error",
1728 "Index Processing Error",
1729 "Encoder Resolution Error",
1730 "Hallsensor not found Error",
1731 "Negative Limit Error",
1732 "Positive Limit Error",
1733 "Hall Angle detection Error",
1734 "Software Position Limit Error",
1735 "Position Sensor Breach",
1736 "System Overloaded",
1737 "Interpolated Position Mode Error",
1738 "Autotuning Identification Error" long getState()
function to get current controller's state
void setCurrentPGain(long gain)
function to set P Current Gain
void setVelocityIGain(long gain)
function to set I Velocity Gain
long getPositionAFFGain()
function to get Acceleration Feed Forward Position Gain
long readStatusWord()
function to read EPOS2 StatusWord
long getPositionWindowTime()
function to get Position Window Time
long getThermalTimeCtWinding()
function to GET Motor Thermal Time Constant Winding
char readError()
function to read an Error information
void disableOperation()
function to reach switch_on and disables power on motor
void startProfilePosition(epos_posmodes mode, bool blocking=true, bool wait=true, bool new_point=true)
function to move the motor to a position in profile position mode
void setHomePosition(long home_position_qc)
function to set a Home position
long readCurrentDemanded()
function to read current demanded
long getMaxAcceleration(void)
function to GET Max Acceleration
void getControlParameters(long &cp, long &ci, long &vp, long &vi, long &vspf, long &pp, long &pi, long &pd, long &pv, long &pa)
function to get all control parameters
void waitPositionMarker()
wait for marker position reached
void enableMotor(long opmode)
function to facititate transitions from switched on to operation enabled
void setPositionMarker(char polarity=0, char edge_type=0, char mode=0, char digitalIN=2)
Sets the configuration of a marker position.
void setMinPositionLimit(long limit)
function to SET the Min Position Limit
long readVelocitySensorActual()
function to read velocity sensor actual
void setPositionWindow(long window_qc)
function to set Position Window
void setPositionWindowTime(long time_ms)
function to set Position Window Time
int getDigInExecutionMask()
Gives Digital Inputs Execution Mask.
long getMaxFollowingError()
function to GET the Max Following Error
void setVelocitySetPointFactorPGain(long gain)
function to SET Speed Regulator Set Point Factor P Velocity Gain
void setRS232Baudrate(long baudrate)
function to SET the RS232 Baudrate
void getEncoderParameters(long &pulses, long &type, long &polarity)
function to GET encoder parameters
long getUSBFrameTimeout()
function to GET the USB Frame Timeout
long getPositionDimensionIndex()
function to get Position Dimension Index
long getPositionNotationIndex()
function to get Position Notation Index
void shutdown()
function to reach ready_to_switch_on state
void getProfileData(long &vel, long &maxvel, long &acc, long &dec, long &qsdec, long &maxacc, long &type)
function to GET all data of the velocity profile
int16_t computeChecksum(int16_t *pDataArray, int16_t numberOfWords)
function to compute EPOS2 checksum
static Ftdi::Context ftdi
a reference to the FTDI USB device
int32_t readObject(int16_t index, int8_t subindex)
function to read an object from the EPOS2
long getMinPositionLimit()
function to GET the Min Position Limit
long readEncoderCounterAtIndexPulse()
function to read the Encoder Counter at index pulse
long getEncoderPulseNumber()
function to GET the Encoder Pulses
int getDigInPolarity()
Gives Digital Inputs Polarity Mask.
long getVelocityPGain()
function to get P Velocity Gain
void setPositionNotationIndex(long notation)
function to set Position Notation Index
void readErrorHistory(long *error[5])
function to read last 5 errors
void setAnalogOutput1(long voltage_mV)
function to set analog output 1
void setMotorType(long type)
function to SET Motor type
void setMaxPositionLimit(long limit)
function to SET the Max Position Limit
long getMotorType()
function to GET Motor type
void startCurrent()
[OPMODE=current] function to move the motor in current mode
long getPositionIGain()
function to get I Position Gain
void setPositionDGain(long gain)
function to set D Position Gain
long getTargetProfileVelocity()
[OPMODE=profile_velocity] function to get the velocity
void switchOn()
function to reach switch_on state
void setAccelerationDimensionIndex(long Dimension)
function to set Acceleration Dimension Index
long getProfileQuickStopDecel(void)
function to GET the Quick Stop Deceleration in profile
static const std::string error_names[]
Strings of generic error descriptions.
void setVerbose(bool verbose)
void setOperationMode(long opmode)
function to set the operation mode
void setVelocityNotationIndex(long notation)
function to set Velocity Notation Index
void enableOperation()
function to reach operation_enable state and enables power on motor
long getProfileMaxVelocity(void)
function to GET the Max Velocity allowed in Profile
void setMaxAcceleration(long max_acceleration)
function to SET Max Acceleration
long readCurrent()
function to read motor current
long getNegativeLong(long number)
function to make a unsigned long signed
void setProfileType(long type)
function to SET the type in profile
void setVelocityWindow(long window_rm)
function to set Velocity Window
long readVersionSoftware()
function to read the software version
int getDigInStateMask()
Gives Digital Inputs State Mask.
void setThermalTimeCtWinding(long time_ds)
function to SET Motor Thermal Time Constant Winding
long getAccelerationDimensionIndex()
function to get Acceleration Dimension Index
void setPositionAFFGain(long gain)
function to set Acceleration Feed Forward Position Gain
void setVelocityWindowTime(long time_ms)
function to set Velocity Window Time
long getAnalogOutput1()
function to get the value in the Analog Output1
long readVelocityDemand()
function to read velocity demand
long getProfileAcceleration(void)
function to GET the Acceleration in profile
void setRS232FrameTimeout(long timeout)
function to SET the RS232 Frame Timeout
int writeObject(int16_t index, int8_t subindex, int32_t data)
function to write an object to the EPOS2
long getRS232Baudrate()
function to GET the RS232 Baudrate
void faultReset()
function to reach switch_on_disabled state after a FAULT
void setTargetProfileVelocity(long velocity)
[OPMODE=profile_velocity] function to set the velocity
void disablePositionLimits(void)
function to DISABLE Position Limits
void setAccelerationNotationIndex(long notation)
function to set Acceleration Notation Index
long readHallsensorPattern()
function to read the Hall Sensor Pattern
long getPositionPGain()
function to get P Position Gain
void setPositionPGain(long gain)
function to set P Position Gain
void setCurrentIGain(long gain)
function to set I Current Gain
void setProfileDeceleration(long deceleration)
function to SET the Deceleration in profile
long getProfileType(void)
function to GET the type in profile
std::string getOpModeDescription(long opmode)
function to show the name of the operation mode
void printControlParameters(long cp, long ci, long vp, long vi, long vspf, long pp, long pi, long pd, long pv, long pa)
function to show all control parameters
long getVelocitySetPointFactorPGain()
function to GET Speed Regulator Set Point Factor P Velocity Gain
static const std::string error_descriptions[]
error descriptions
void setMotorContinuousCurrentLimit(long current_mA)
function to SET Motor Continous Current Limit
long getOperationMode()
function to know which operation mode is set
void setUSBFrameTimeout(long timeout)
function to SET the USB Frame Timeout
long readCurrentAveraged()
function to read motor averaged current
void startVelocity()
function to move the motor in Velocity mode
void stopProfileVelocity()
[OPMODE=profile_velocity] function to stop the motor
static bool ftdi_initialized
long getVelocityWindowTime()
function to get Velocity Window Time
void restoreDefaultParameters()
function to restore default parameters of EPOS2.
long getCurrentPGain()
function to get P Current Gain
std::string searchErrorDescription(long error_code)
given an error code it returns its description
void setProfileMaxVelocity(long velocity)
function to SET the Max Velocity allowed in Profile
void enableController()
function to facititate transitions from the start of the controller to switch it on ...
long getVelocityNotationIndex()
function to get Velocity Notation Index
void saveParameters()
function to save all parameters in EEPROM
void stopCurrent()
[OPMODE=current] function to stop the motor in current mode
long getHomePosition()
function to get the Home position
void close()
Disconnects hardware.
void quickStop()
function to reach switch_on state
void sendFrame(int16_t *frame)
function send a frame to EPOS2
void disableVoltage()
function to reach switch_on_disabled state
void setTargetCurrent(long current)
[OPMODE=current] function to SET the target current
void setPositionVFFGain(long gain)
function to set Velocity Feed Forward Position Gain
void init()
Connects hardware.
void p(const char *text)
function to make a unsigned long signed
long getProfileDeceleration(void)
function to GET the Deceleration in profile
void setHome()
function to set a Home position with user interaction
long getProfileVelocity(void)
function to GET the velocity of the Velocity Profile
void setProfileVelocity(long velocity)
function to SET the velocity of the Velocity Profile
long getTargetProfilePosition()
function to GET the target position
long readVersionHardware()
function to read the hardware version
long readEncoderCounter()
function to read the Encoder Counter
void receiveFrame(uint16_t *ans_frame)
function receive a frame from EPOS2
long getVelocityDimensionIndex()
function to get Velocity Dimension Index
long getMotorContinuousCurrentLimit()
function to GET Motor Continous Current Limit
long readFollowingError()
function to read the Following Error
long getAccelerationNotationIndex()
function to get Acceleration Notation Index
void setVelocityPGain(long gain)
function to set P Velocity Gain
long getMaxPositionLimit()
function to GET the Max Position Limit
CEpos2(int8_t nodeId=0x00)
Constructor.
void setMotorOutputCurrentLimit(long current_mA)
function to SET Motor Output Current Limit
long getCurrentIGain()
function to get I Current Gain
int32_t readPosition()
function to read motor position
void setProfileAcceleration(long acceleration)
function to SET the Acceleration in profile
void setPositionIGain(long gain)
function to set I Position Gain
long getPositionDGain()
function to get D Position Gain
void setProfileQuickStopDecel(long deceleration)
function to SET the Quick Stop Deceleration in profile
long getPositionVFFGain()
function to get Velocity Feed Forward Position Gain
void setEncoderPulseNumber(long pulses)
function to SET the Encoder Pulses
void setProfileData(long vel, long maxvel, long acc, long dec, long qsdec, long maxacc, long type)
function to SET all data of the velocity profile
void setHoming(int home_method=11, int speed_pos=100, int speed_zero=100, int acc=1000, int digitalIN=2)
Sets the configuration of a homing operation.
long getMotorPolePairNumber()
function to GET Motor Pole Pair Number
void setPositionDimensionIndex(long Dimension)
function to set Position Dimension Index
void stopVelocity()
function to stop the motor in velocity mode
void stopHoming()
stops a homing operation
void setControlParameters(long cp, long ci, long vp, long vi, long vspf, long pp, long pi, long pd, long pv, long pa)
function to set all control parameters
void setTargetVelocity(long velocity)
function to SET the target velocity
long readVelocity()
function to read motor average velocity
void startProfileVelocity()
[OPMODE=profile_velocity] function to move the motor in a velocity
void openDevice()
open EPOS2 device using CFTDI
void setMotorPolePairNumber(char pole_pairs)
function to SET Motor Pole Pair Number
long getTargetVelocity()
function to GET the target velocity This function gets the target velocity of velocity operation mode...
void setEncoderType(long type)
function to SET the Encoder type
void setEncoderPolarity(long polarity)
function to SET the Encoder polarity
void setMaxFollowingError(long follerror)
function to SET the Max Following Error
void doHoming(bool blocking=false)
starts a homing operation
int getDigInFuncMask()
Gives Digital Inputs Functionalities Mask.
bool isTargetReached()
function to know if the motor has reached the target position or velocity
void setVelocityDimensionIndex(long Dimension)
function to set Velocity Dimension Index
void setEncoderParameters(long pulses, long type, long polarity)
function to SET encoder parameters
long getPositionWindow()
function to get Position Window
long readVelocityActual()
function to read velocity sensor actual
long getTargetCurrent()
[OPMODE=current] function to GET the target current
long getMotorOutputCurrentLimit()
function to GET Motor Output Current Limit
long getVelocityWindow()
function to get Velocity Window
long getEncoderPolarity()
function to GET the Encoder Pulses
void getMovementInfo()
prints information about movement
int getDigInState(int digitalIN=2)
Gives the state of a certain digital Input.
long getVelocityIGain()
function to get I Velocity Gain
long getEncoderType()
function to GET the Encoder Pulses
void setTargetProfilePosition(long position)
function to SET the target position
long getRS232FrameTimeout()
function to GET the RS232 Frame Timeout
long getPositionMarker(int buffer=0)
gets the position marked by the sensor
static const int error_codes[]
error integer codes