Set a motor device for using it

The motor class has to be adapted if this server wants to be used for checking possible collisions before performing a movement.

Three new properties have to be implemented:

 FlagUseCollisionsSensor. Set to 1 if a CollisionsSensor device wants to be used. Set the default to 0, so the server will run without problems if it is not se at all.
 CollisionsSensorDS. Name of the CollisionsSensor device to be connected. This Server has to be running when a movement wants to be performed, but it is not necessary that it runs at the initialization.
 CollisionsSensorBL. Beamline number as string. It is necessary since the check of the movement depends on the motor and the beamline.
 FlagSendDataToCollisionsSensor. If set to 1, the motor will write in the attributes Value1 and Value2 of the CollisionsSensor device the UnitLimitMax and UnitLimitMin values. This is need for motors which need these values for the move condition.

The call to the function CheckCollisions with the right arguments (beamline number, motor position to be set and motor device name) has to be called before any movement is sent to the hardware. Only if the answer of this function is 0 the movement will be performed. Optionally the ALARM state can be used for informing abour errors in the connection with the CollisionsSensor device.

As an example of the implementation:

 In the header file:
    DeviceProxy *collisions_sensor_device;
    DevVarDoubleStringArray *collisions_sensor_data;

 In the init_device function:
  if(flagUseCollisionsSensor){
    collisions_sensor_data = new DevVarDoubleStringArray();
    collisions_sensor_data->dvalue.length(1);
    collisions_sensor_data->svalue.length(2);
  }

 In the function called when a movement wants to be performed:
  DeviceData dout;
  DeviceData din;
  long iout;

  if(flagUseCollisionsSensor){
    if(collisions_sensor_device == 0){
      try{
	collisions_sensor_device = new Tango::DeviceProxy(collisionsSensorDS);
      } catch(Tango::DevFailed &e){
	set_state(Tango::ALARM);
	set_status("Not connection to CollisionsSensor device. Check CollisionsSensorDS property and device");
	argout = 0;
	goto finish;
      }
    }
       
    if(flagSendDataToCollisionsSensor){ 
      DeviceAttribute *da_write1 = new DeviceAttribute( "Value1", (Tango::DevDouble)attr_UnitLimitMax_write );
      collisions_sensor_device->write_attribute(*da_write1);
      DeviceAttribute *da_write2 = new DeviceAttribute( "Value2", (Tango::DevDouble)attr_UnitLimitMin_write );
      collisions_sensor_device->write_attribute(*da_write2);
    }

    collisions_sensor_data->svalue[0] = collisionsSensorBL.c_str(); // beamline
    collisions_sensor_data->dvalue[0] = (double) argin; // newposition
    collisions_sensor_data->svalue[1] = this->device_name.c_str();
    din << collisions_sensor_data;
    try{
      dout = collisions_sensor_device->command_inout("CheckCollision",din);
    } catch(Tango::DevFailed &e){
      set_state(Tango::ALARM);
      set_status("CheckCollision command failed. Not movement.");
      argout = 0;
      goto finish;
    }
    dout >> iout;
    if(iout){
      argout = 0;
      goto finish;
    }
    if(get_state() == Tango::ALARM){
      set_state(Tango::ON);
      set_status("Device in ON state");
    }
  }

  ...

  Continue with the movement.

  ...