IOC Robotic's Lab

PAGE IN PROGRESS

EcSlaveHCS02

The EcSlaveHCS02 cointains the implementation to drive a Rexroth Servo using a HCS02 controller. This slave device supports the SoE (Sercos over EtherCAT) protocol. The communication between the master and the slaves can be acyclic or cyclic (MDT/AT).

The main functions are inherited from EcSlave base class.

  • Preconfigure: configures the basic parameters specified by the user using a XML file.
  • Configure: configures and checks the parameters specified by the user in the demo and the XML.
  • Start: the drivers are switched on, ready to send commands to motors.
  • Update: update the state values of the slaves (MDT input) and send a signal with the most important (status,position,velocity,torque and timestamp).
  • Stop: the drives are shut down.


SERCOS state machine in the HCS02

P0/P1: In this state the drive will check internally the connection between the master and the slave. When the drive is power on it will go automatically to P0 (the display shows P0). Nothing more could be done in this state. To switch to the next state, P2, the function master.preconfigure() has to be called in the demo.

P2: In this state the communication between the master and the slave has been correctly configured and the exchange of data will be possible (acyclic communication only with the function ec_SoEwrite ). All the parameters could be modify in this state but only a group would be checked by the drive during the switch to P3 to confirm that are corruptly set up. To switch to the next state, P3, the function master.configure() has to be called in the demo.

P3: the library that has been constructed does not permit to stop in the state P3 because the drive will go to P4 automatically with the use of function configure once it has pass the P3 state, where a few IDN will be checked to ensure their correctly set up.

P4: during the switch to this state the cyclic communication will be started and once in P4 the display will show Ab, or bb if the motor is off. Although the drive is in operational mode and is possible to use the cyclic communication the control of it will be impossible until the drive goes to AF. To change to the AF it is necessary to use the function master.start.


Acyclic communication with ec_SoEwrite/ec_SoEread function

In order to make acyclic communication with the drive while in P2 (once you have use the function master.preconfigure, but before use the master.configure function) the use of the function ec_SoEwite/ec_SoEread will be necessary. With those functions it is possible to write or read the value stored in an IDN.

ec_SoEwrite (uint16 slave, uint8 driveNo, uint elementflags, uint idn, int psize, void* p, int timeout)  
ec_SoEread(uint16 slave, uint8 driveNo, uint8 elementflags, uint16 idn, int* psize, void* p, int timeout)    

Where:
slave is the number of the slave in which you want to write.
driveNo has to be 0.
elementflags could be one of the following options, but normaly it will be 0x40 in order to show the value stored in the parameter.

0x01Data status
0x02Name
0x04Attribute
0x08Unit
0x10Min
0x20Max
0x40Value
0x80Default value

idn is the idn number that will be written or read.
psize is the size of the value stored in the idn.
p is the value to store or where the value is stored.\\

timeout is the maximum time to get out of the function, standard is EC_TIMEOUTRXM.


Set up of the modes of operation

The HCS02 has different modes of operation. These operation modes are related to the position, velocity or torque control and they are easily configured throw the function modeSetUp of the EcSlave, this function could be called from the demo.
In this function it is possible to set up the mode and the position of it in the list of modes that could be used during the cyclic data transfer period (It is possible to configurate up to 4 modes at the same time, and it is possible to change between the modes on the fly during the cyclic data transfer period using the controlword)
The actual control modes that could be configured are:

Operation modesName in the functionExplanation
Torque ControlTORQUE_CONTROLIt is used to control the drive using only torque commands. It is important to know that in this mode there are several limits that are not going to work.
Velocity ControlVELOCITY_CONTROLIt is used to control the dive via velocity commands only
Position controlPOSITION_CONTROLIt is used to control the drive via position commands that have to be send point by point. The difference between two consecutive points can not exceed a maximum distance that is related to the maximum velocity allowed in the drive. It is possible to use your own profile in this mode.
Position control with drive internal interpolationINTERPOLATION_CONTROLIt is used to control the drive via position commands, the drive will move to the desired position stablished via the position command with a profile calculated, internally, by the drive

The next example will show how to correctly set up the modes of operation in a demo:
All these lines have to be write between the master.preconfigure() function call and the master.configure() function call in the demo.

((cpp4ec::EcSlaveTrack*) drivers[0]) -> modeSetUp(INTERPOLATION_CONTROL,0);
((cpp4ec::EcSlaveTrack*) drivers[0]) -> modeSetUp(TORQUE_CONTROL,1);
In this case the drive internal interpolation mode has been set in the primary mode and the torque control has been set in the secondary mode, it will be possible to switch between the modes during operation.
How to use each mode correctly will be explained later.


Modes of operation

In this section the operation modes, their corresponding IDNs and the correct configuration are going to be explain in more detail.

Torque control

Velocity control

This mode is used to control the velocity of the drive directly. A velocity will be set in the drive and it will accelerate until it reach the set velocity,then it will stay in that velocity.

The most important IDN for the correct use of this mode are the following ones. (These IDNs are not the only ones that could be reconfigured in this mode, for more advanced settings you will need to take a look at the users manual and the parameters description document):

IDNDescriptionMDTAT
S-0-0036Velocity command value✔✘
S-0-0091Bipolar velocity limit value✔✘
P-0-1201Acceleration ramp✔✘
S-0-0051Position feedback value✘✔
S-0-0040Velocity feedback value✘✔
S-0-0164Acceleration feedback value✘✔

Position control

As has been said in the set up mode section, this mode is used to control the position of the drive but it is needed to send cyclical data of the position to achieve the desired position. In each cycle it is possible to send only a little increment of the position, if a longer increment is set and it exceed the maximum increment in a cycle an error will appear and the system will suddenly stop. Later, in this section, it will be explained how to know the maximum increment that the drives could take in a cycle without problems.

This mode is the best one to define your own profile for the motion of the drive.

The most important IDNs for the correct use of this operation mode are the following ones (These IDNs are not the only ones that could be reconfigured in this mode, for more advanced settings you will need to take a look at the users manual and the parameters description document):

IDNDescriptionMDTAT
S-0-0047Position command value✔✘
S-0-0091Bipolar velocity limit value✔✘
S-0-0138Bipolar acceleration limit value✔✘
S-0-0051Position feedback value✘✔
S-0-0040Velocity feedback value✘✔
S-0-0164Acceleration feedback value✘✔

The most important IDN between all the IDN in the table is the S-0-0047 because in this IDN you will set the position that the drive have to reach in each cycle. So the velocity that the drive will reach is related to the difference between the consecutive positions and never will be set in a IDN. The only velocity that will be configured in this mode is the maximum velocity that is possible to set in the S-0-0091. And the same conclusion is possible to extrapolate to the acceleration and the IDN S-0-0138.
The maximum step that the drive could take in a cycle is related to the maximum velocity that the drive could reach, velocity that are set in the S-0-0091 IDN, if the velocity needed to move from a position to the next one, stored in the S-0-0047, in a cycle time exceeds the maximum velocity the error F2037 will appear in the display and the drive will stop immediately.

Position control with drive internal interpolation

This mode is used to control the position, but the difference with the previous one is that now is not necessary to send the position cyclically during the time that the drives goes to the final position. Only the final position is needed to set up in the drive and it will move to the position while following a profile that the drive calculates by himself.\\ The profile takes the acceleration value to make a ramp of increasing velocity up to the velocity value during the acceleration process and the same values to make the deceleration, so if you set up a really elevated acceleration the profile will seem more like a velocity step than a velocity ramp.
The most important IDNs for the correct use of this operation mode are the following ones (These IDNs are not the only ones that could be reconfigured in this mode, for more advanced settings you will need to take a look at the users manual and the parameters description document):

IDNDescriptionMDTAT
S-0-0258Target position✔✘
S-0-0259Positioning velocity✔✘
S-0-0260Positioning acceleration✔✘
S-0-0051Position feedback value✘✔
S-0-0040Velocity feedback value✘✔
S-0-0164Acceleration feedback value✘✔

In this mode you could set the velocity and the acceleration that the drive will use during the profile independently of the maximum limit of velocity and acceleration set in the drive.


Telegram set up

It is possible to select between 7 preconfigured telegram types or you could configure your own telegram.
The telegrams types are explained in the next table.

Telegram typeMDT preconfigured IDNsAT preconfigured IDN
VZ0no cyclic datano cyclic data
VZ1S-0-0080, Torque/force command valueno cyclic data
VZ2S-0-0036, Velocity command valueS-0-0040, Velocity feedback value
VZ3S-0-0047, Position command valueS-0-0051/S-0-0053 Position feedback 1/2 value
VZ4S-0-0047, Position command valueS-0-0051/S-0-0053 Position feedback 1/2 value
VZ5S-0-0047, Position command value and S-0-0036, Velocity command valueS-0-0051/S-0-0053 Position feedback 1/2 value S-0-0040, Velocity feedback value
VZ6S-0-0036, Velocity command valueno cyclic data
VZ7ConfigurableConfigurable

The telegram type could be choose and configured (if VZ7 is selected) directly in the demo with the next lines: All these lines have to be between the master.preconfigure() and the master.configure()

This function is used to selected the telegram type

((cpp4ec::EcSlaveTrack*) drivers[0]) -> TelegramType(VZ7);

Only if VZ7 telegram has been set is necessary to use the following lines.
To now how to obtain the IDN number see section IDN.
A vector with the IDN (In that case, the IDNs configured are the S-0-0258, S-0-0259 and S-0-0260) that will be in the MDT is created and in the next line is configured in the drive

std::vector<int> idnlistMDT={258,259,260};
((cpp4ec::EcSlaveTrack*) drivers[0]) -> setMDT(idnlistMDT);

A vector with the IDN (In that case, the IDNs configured are the S-0-0051, S-0-0040 and S-0-0437) that will be in the AT is created and in the next line is configured in the drive

std::vector<int> idnlistAT={51,40,437};
((cpp4ec::EcSlaveTrack*) drivers[0]) -> setAT(idnlistAT);

It is possible to configure up to fifteen IDN in the MDT and fifteen more in the AT but is not possible to configure any IDN in the MDT or the AT, there is a list of IDNs that are configurable in the MDT and a list of IDNs that are configurable in the AT. The IDN S-0-0187 will contain the ones that could be configured in the AT and the IDN S-0-0188 will contain those that are configurable in the MDT. If a non-configurable IDN is configured in the AT the error C0106 will be shown in the drive's display and if the non-configurable IDN is configured in the MDT the error that will be shown is the C0104.


XML File and the basic parameters

In the XML the basic parameters of the configuration will be stored to guaranteed that parameters such as maximum velocity or acceleration, position limits, cycle time and other important parameters, that will be commonly set at the same value, are correctly set in the drive to avoid possible accidents that could cause breaking of the system or even injuries or death of the people around the system.

The structure of the XML is the following one:

  <structure>
    <param type="string" name="description">NC cycle time (TNcyc)</param>
    <param type="string" name="name">NCcycletime(TNcyc)</param>
    <param type="integer" name="idn">1</param>
    <param type="integer" name="elementflags">0x40</param>
    <param type="integer" name="size">2</param>
    <param type="string" name="editability">P2</param>
    <param type="integer" name="value">1000</param>
  </structure>

By now the parameters that have been configured in the XML all these ones:
S-0-0001 NC cycle time
S-0-0002 SERCOS cycle time
The following two IDN have to be set to 0 to ensure that the value limit that takes effect is the one stored in the S-0-0091
S-0-0038 Positive velocity limit value
S-0-0039 Negative velocity limit value
The following two IDN are really important because they will limit the travel range of the system. If the track goes farther that the limits it will disconnect the cyclic communication and the brake will actuate at maximum torque.\\ S-0-0049 Positive limit value of position
S-0-0051 Negative limit value of position
S-0-0091 Bipolar velocity limit value
S-0-0138 Max acceleration
S-0-0359 Max deceleration\\


IDN

IDN number

The number of a IDN is represented by a letter followed of one digit and followed by a number of 4 digits. The letter could be either a S or a P. The S means standard parameter and the P means product parameter, what means that this IDN is only for that system and not for all the systems with SERCOS.
Example: S-0-0001
To use an IDN in the program it will be necessary to convert that sequence to a decimal number. To make that conversion there are some rules.

The values of the lettwers are:
S=0 \\ P=0x8000

The middle number with one digit could be a 0 or a 7 and the corresponding values are:
0=0
7=0x7000

Finally the four digit number has the same value in decimal than the number in the sequence.

To obtain the final number you have to plus all the values obtained.
Examples:
S-0-0101=0+0+101=101
P-0-0101=0x8000+0+101=32768+0+101=32869
P-7-0101=0x8000+0x7000+101=32768+28672+101=61541

Most important IDN

Here, some of the most important IDN will be shown and explained in order to facilitate the understanding of them.


Examples

Some examples will be shown and explained in this section in order to make easier the work of create a program to move the track.

#include "EcMaster.h"
#include "EcSlaveTrack.h"
#include "EcSlave.h"

#include <iostream>
#include <vector>
#+0+include <fstream>
#include <string>

#define MAXPOSITION 1700
#define MINPOSITION  300
#define VELOCITY 1666 //mm/s

cpp4ec::EcMaster master("rteth1",1000000,true); // 1ms and with DC
std::vector<cpp4ec::EcSlave*> drivers;

int main ()
{
    int position, initialPosition;
    try
    {
      drivers.resize(0);
      master.preconfigure();
      //The slaves vector is get, in this demo, three EcSlaveSGDV are conected in the net
      drivers = master.getSlaves();
      // Default parameters stored in the XML are loaded to the drive with the following line
      ((cpp4ec::EcSlaveTrack*) drivers[0]) -> DefaultParameters();
       // Drive internal interpolation mode is set in the drive via the following line
      ((cpp4ec::EcSlaveTrack*) drivers[0]) -> modeSetUp(DRIVEINTERNALINTERPOLATION_CONTROL,0);
      //Telegram type VZ7 are selected in the drive which means that a configuration of the IDN will be necessary
      ((cpp4ec::EcSlaveTrack*) drivers[0]) -> TelegramType(VZ7);
      //Configuration of the MDT and AT
      std::vector<int> idnlistMDT={258,259,260};
      ((cpp4ec::EcSlaveTrack*) drivers[0]) -> setMDT(idnlistMDT);
      std::vector<int> idnlistAT={51,40,437};
      ((cpp4ec::EcSlaveTrack*) drivers[0]) -> setAT(idnlistAT);
      //Here the maximum acceleration during the positioning are lowered in order to smooth trajectories at the start and the end.
      int value=500000;
      ec_SoEwrite(1, 0, 0x40, 138, 4, &value,EC_TIMEOUTRXM);
      //The master and slaves are configured. The drive will go to Ab (P4 of SERCOS state machine)
      master.configure();
      //((cpp4ec::EcSlaveTrack*) drivers[0]) -> ClearError(); //Clear error to clear the error F2174 Motor Encoder Loss
      usleep(250000); //Little waiting to avoid the error F2025
      //The master and slaves are started. The drive will go to AF mode and will be totally operational
      master.start();
      int targetPosition=1000;
      bool finish = false;
      while (targetPosition != 0 )
      {
          std::cout<<"Enter a position between "<<MAXPOSITION<<"mm and "<<MINPOSITION<<"mm or 0 to exit "<<std::endl;
          std::cin>>targetPosition;
          if((targetPosition < MAXPOSITION) && (targetPosition > MINPOSITION))
          {
              targetPosition = targetPosition*10000;
              ((cpp4ec::EcSlaveTrack*) drivers[0]) -> writeMDT(SECOND_ENTRY,targetPosition);
              ((cpp4ec::EcSlaveTrack*) drivers[0]) -> writeMDT(THIRD_ENTRY,VELOCITY*60*1000);
              master.update();
              finish = false;
              while (!finish)
              {
                  ((cpp4ec::EcSlaveTrack*) drivers[0]) -> readAT(SECOND_ENTRY,position);
                  if(abs(position - targetPosition) < 10000 )
                      finish = true;
                  usleep(1000);
              }
          }
      }
      usleep(1000000);
      master.stop();
      master.reset();
  }
  catch (EcError& e)
  {
    //if there are any spected error it would be printed on the screen
    std::cout<<e.what()<<std::endl;  
  }
  return (0);
}