1 //===================================================================
3 // The following table gives the correspondence
4 // between commands and method name.
6 // Command name | Method name
7 // ----------------------------------------
9 // Status | dev_status()
11 // MotorOFF | motor_off()
12 // MotorON | motor_on()
13 // MotorInit | motor_init()
14 // ComputeNewOffset | compute_new_offset()
15 // Backward | backward()
16 // Forward | forward()
17 // DefinePosition | define_position()
18 // InitializeReferencePosition | initialize_reference_position()
19 // GetModeParameters | get_mode_parameters()
20 // SetModeParameters | set_mode_parameters()
22 //===================================================================
25 #include <PseudoAxis.h>
26 #include <PseudoAxisClass.h>
27 #include <PogoHelper.h>
29 #include <TangoExceptionsHelper.h>
32 #include <TangoExceptionsHelper.h>
33 #include <PseudoAxis.h>
34 #include <PseudoAxisClass.h>
35 #include <PogoHelper.h>
38 #include <DeviceProxyHelper.h>
40 #include <hkl/hkl-pseudoaxis.h>
43 #include "PseudoAxis.h"
44 #include "PseudoAxisClass.h"
45 #include "TangoHKLAdapterFactory.h"
47 namespace PseudoAxis_ns
50 //+----------------------------------------------------------------------------
52 // method : PseudoAxis::PseudoAxis(string &s)
54 // description : constructor for simulated PseudoAxis
56 // in : - cl : Pointer to the DeviceClass object
59 //-----------------------------------------------------------------------------
60 PseudoAxis::PseudoAxis(Tango::DeviceClass
*cl
,string
&s
)
61 :Tango::Device_3Impl(cl
,s
.c_str())
66 PseudoAxis::PseudoAxis(Tango::DeviceClass
*cl
,const char *s
)
67 :Tango::Device_3Impl(cl
,s
)
72 PseudoAxis::PseudoAxis(Tango::DeviceClass
*cl
,const char *s
,const char *d
)
73 :Tango::Device_3Impl(cl
,s
,d
)
77 //+----------------------------------------------------------------------------
79 // method : PseudoAxis::delete_device()
81 // description : will be called at device destruction or at init command.
83 //-----------------------------------------------------------------------------
84 void PseudoAxis::delete_device()
86 DEBUG_STREAM
<< "PseudoAxis::delete_device() entering... " << std::endl
;
88 DELETE_SCALAR_ATTRIBUTE(attr_position_read
);
89 DELETE_SCALAR_ATTRIBUTE(attr_IsInitialised_read
);
90 DELETE_SCALAR_ATTRIBUTE(attr_offset_read
);
91 DELETE_DEVSTRING_ATTRIBUTE(attr_mode_read
);
97 //+----------------------------------------------------------------------------
99 // method : PseudoAxis::init_device()
101 // description : will be called at device initialization.
103 //-----------------------------------------------------------------------------
104 void PseudoAxis::init_device()
106 DEBUG_STREAM
<< "PseudoAxis::init_device() entering... " << std::endl
;
108 // Initialise variables to default values
109 //--------------------------------------------
110 this->get_device_property();
112 CREATE_SCALAR_ATTRIBUTE(attr_position_read
);
113 CREATE_SCALAR_ATTRIBUTE(attr_IsInitialised_read
);
114 CREATE_SCALAR_ATTRIBUTE(attr_offset_read
);
115 CREATE_DEVSTRING_ATTRIBUTE(attr_mode_read
, 1, "");
121 //+----------------------------------------------------------------------------
123 // method : PseudoAxis::get_device_property()
125 // description : Read the device properties from database.
127 //-----------------------------------------------------------------------------
128 void PseudoAxis::get_device_property()
130 DEBUG_STREAM
<< "PseudoAxis::get_device_property() entering... " << std::endl
;
132 // Initialize your default values here (if not done with POGO).
133 //------------------------------------------------------------------
135 // Read device properties from database.(Automatic code generation)
136 //------------------------------------------------------------------
137 Tango::DbData dev_prop
;
138 dev_prop
.push_back(Tango::DbDatum("DiffractometerProxy"));
139 dev_prop
.push_back(Tango::DbDatum("PseudoAxisName"));
141 // Call database and extract values
142 //--------------------------------------------
143 if (Tango::Util::instance()->_UseDb
==true)
144 get_db_device()->get_property(dev_prop
);
145 Tango::DbDatum def_prop
, cl_prop
;
146 PseudoAxisClass
*ds_class
=
147 (static_cast<PseudoAxisClass
*>(get_device_class()));
150 // Try to initialize DiffractometerProxy from class property
151 cl_prop
= ds_class
->get_class_property(dev_prop
[++i
].name
);
152 if (cl_prop
.is_empty()==false) cl_prop
>> diffractometerProxy
;
154 // Try to initialize DiffractometerProxy from default device value
155 def_prop
= ds_class
->get_default_device_property(dev_prop
[i
].name
);
156 if (def_prop
.is_empty()==false) def_prop
>> diffractometerProxy
;
158 // And try to extract DiffractometerProxy value from database
159 if (dev_prop
[i
].is_empty()==false) dev_prop
[i
] >> diffractometerProxy
;
161 // Try to initialize PseudoAxisName from class property
162 cl_prop
= ds_class
->get_class_property(dev_prop
[++i
].name
);
163 if (cl_prop
.is_empty()==false) cl_prop
>> pseudoAxisName
;
165 // Try to initialize PseudoAxisName from default device value
166 def_prop
= ds_class
->get_default_device_property(dev_prop
[i
].name
);
167 if (def_prop
.is_empty()==false) def_prop
>> pseudoAxisName
;
169 // And try to extract PseudoAxisName value from database
170 if (dev_prop
[i
].is_empty()==false) dev_prop
[i
] >> pseudoAxisName
;
174 // End of Automatic code generation
175 //------------------------------------------------------------------
180 //+------------------------------------------------------------------
182 * method: PseudoAxe::dev_state
184 * description: method to execute "State"
185 * This command gets the device state (stored in its <i>device_state</i> data member) and returns it to the caller.
192 //+------------------------------------------------------------------
193 Tango::DevState
PseudoAxis::dev_state()
195 DEBUG_STREAM
<< "PseudoAxis::dev_state(): entering... !" << endl
;
197 Tango::DevState state
;
200 if (!_hklAdapter
|| !_buffer
)
201 state
= Tango::FAULT
;
203 _hklAdapter
->update();
204 state
= _buffer
->get_state();
205 status
= _buffer
->get_status();
207 this->set_state(state
);
208 this->set_status(status
);
209 return this->device_state
;
212 //+------------------------------------------------------------------
214 * method: PseudoAxe::dev_status
216 * description: method to execute "Status"
217 * This command gets the device state (stored in its <i>device_state</i> data member) and returns it to the caller.
224 //+------------------------------------------------------------------
225 Tango::ConstDevString
PseudoAxis::dev_status()
227 DEBUG_STREAM
<< "PseudoAxis::dev_status(): entering... !" << endl
;
230 this->device_state
= Tango::FAULT
;
231 if (diffractometerProxy
== "")
232 this->device_status
= "Please set a correct \"diffractometerProxy\" propertie";
234 this->device_status
= "The Diffractometer device " + diffractometerProxy
+ " is not ready or do not existe!\n";
235 this->device_status
+= "Please start the Diffractometer or check the \"diffractometerProxy\" Propertie";
239 this->device_state
= Tango::FAULT
;
240 if (pseudoAxisName
== "")
241 this->device_status
= "Please set a correct \"pseudoAxisName\" : ";
243 this->device_status
= "Cannot find the pseudoAxe \"" + pseudoAxisName
+ "\" in the " + diffractometerProxy
+ " Diffractometer device : ";
245 this->device_status
+= "Set \"pseudoAxisName\" propertie with one of these possible values : ";
246 std::vector
<std::string
> const names
= _hklAdapter
->pseudo_axis_get_names();
247 std::vector
<std::string
>::const_iterator iter
= names
.begin();
248 std::vector
<std::string
>::const_iterator end
= names
.end();
249 this->device_status
+= " " + *iter
;
252 this->device_status
+= ", " + *iter
;
258 _hklAdapter
->update();
259 this->device_state
= _buffer
->get_state();
260 this->device_status
= _buffer
->get_status();
264 this->device_state
= Tango::FAULT
;
265 this->device_status
= " One motor Device does not respond ";
269 return this->device_status
.c_str();
272 //+----------------------------------------------------------------------------
274 // method : PseudoAxis::always_executed_hook()
276 // description : method always executed before any command is executed
278 //-----------------------------------------------------------------------------
279 void PseudoAxis::always_executed_hook()
281 DEBUG_STREAM
<< "PseudoAxis::always_executed_hook() entering... " << std::endl
;
282 // here we are looking for the intance of the related Diffractometer to get the right hkladapter instance.
284 _hklAdapter
= Diffractometer_ns::TangoHKLAdapterFactory::instance()->get_diffractometer_adapter(diffractometerProxy
);
286 if(_hklAdapter
&& !_buffer
)
287 _buffer
= _hklAdapter
->pseudo_axis_buffer_new(pseudoAxisName
.c_str());
290 //+----------------------------------------------------------------------------
292 // method : PseudoAxis::read_attr_hardware
294 // description : Hardware acquisition for attributes.
296 //-----------------------------------------------------------------------------
297 void PseudoAxis::read_attr_hardware(vector
<long> &attr_list
)
299 DEBUG_STREAM
<< "PseudoAxis::read_attr_hardware(vector<long> &attr_list) entering... "<< endl
;
300 // Add your own code here
302 //+----------------------------------------------------------------------------
304 // method : PseudoAxis::read_mode
306 // description : Extract real attribute values for mode acquisition result.
308 //-----------------------------------------------------------------------------
309 void PseudoAxis::read_mode(Tango::Attribute
&attr
)
311 DEBUG_STREAM
<< "PseudoAxis::read_mode(Tango::Attribute &attr) entering... "<< endl
;
314 attr
.set_value(_buffer
->get_mode());
317 //+----------------------------------------------------------------------------
319 // method : PseudoAxis::write_mode
321 // description : Write mode attribute values to hardware.
323 //-----------------------------------------------------------------------------
324 void PseudoAxis::write_mode(Tango::WAttribute
&attr
)
326 DEBUG_STREAM
<< "PseudoAxis::write_mode(Tango::WAttribute &attr) entering... "<< endl
;
327 attr
.get_write_value(attr_mode_write
);
329 _buffer
->set_mode(attr_mode_write
);
332 //+----------------------------------------------------------------------------
334 // method : PseudoAxis::read_modeNames
336 // description : Extract real attribute values for modeNames acquisition result.
338 //-----------------------------------------------------------------------------
339 void PseudoAxis::read_modeNames(Tango::Attribute
&attr
)
341 DEBUG_STREAM
<< "PseudoAxis::read_modeNames(Tango::Attribute &attr) entering... "<< endl
;
343 Matrix
<char *> const & img
= _buffer
->get_mode_names();
344 attr
.set_value(img
.data
, img
.xdim
);
348 //+----------------------------------------------------------------------------
350 // method : PseudoAxis::write_IsInitialised
352 // description : Write IsInitialised attribute values to hardware.
354 //-----------------------------------------------------------------------------
355 void PseudoAxis::write_IsInitialised(Tango::WAttribute
&attr
)
357 DEBUG_STREAM
<< "PseudoAxis::write_IsInitialised(Tango::WAttribute &attr) entering... "<< endl
;
358 // Add your own code here
359 attr
.get_write_value(attr_IsInitialised_write
);
361 _buffer
->set_is_initialised(attr_IsInitialised_write
);
363 // need to after the internals before initializing the pseudo
365 _hklAdapter
->update();
369 //+----------------------------------------------------------------------------
371 // method : PseudoAxis::read_position
373 // description : Extract real attribute values for position acquisition result.
375 //-----------------------------------------------------------------------------
376 void PseudoAxis::read_position(Tango::Attribute
&attr
)
378 DEBUG_STREAM
<< "PseudoAxis::read_position(Tango::Attribute &attr) entering... "<< endl
;
379 // Add your own code here
381 if (_hklAdapter
&& _buffer
) {
382 _hklAdapter
->update();
384 // first the read part
385 *attr_position_read
= _buffer
->get_read();
386 *attr_position_read
+= *attr_offset_read
;
387 // second the write part
388 attr_position_write
= _buffer
->get_write();
389 attr_position_write
+= *attr_offset_read
;
390 // now use Tango to aknowledge for the write part.
391 Tango::WAttribute
& att
= dev_attr
->get_w_attr_by_name(attr
.get_name().c_str());
392 att
.set_write_value(attr_position_write
);
394 attr
.set_value(attr_position_read
);
397 //+----------------------------------------------------------------------------
399 // method : PseudoAxis::write_position
401 // description : Write position attribute values to hardware.
403 //-----------------------------------------------------------------------------
404 void PseudoAxis::write_position(Tango::WAttribute
&attr
)
406 DEBUG_STREAM
<< "PseudoAxis::write_position(Tango::WAttribute &attr) entering... "<< endl
;
407 // Add your own code here
409 attr
.get_write_value(attr_position_write
);
410 if (_hklAdapter
&& _buffer
)
411 _hklAdapter
->pseudo_axis_write(_buffer
, attr_position_write
- *attr_offset_read
);
414 //+----------------------------------------------------------------------------
416 // method : PseudoAxis::read_offset
418 // description : Extract real attribute values for offset acquisition result.
420 //-----------------------------------------------------------------------------
421 void PseudoAxis::read_offset(Tango::Attribute
&attr
)
423 DEBUG_STREAM
<< "PseudoAxis::read_offset(Tango::Attribute &attr) entering... "<< endl
;
424 // Add your own code here
425 attr
.set_value(attr_offset_read
);
428 //+----------------------------------------------------------------------------
430 // method : PseudoAxis::write_offset
432 // description : Write offset attribute values to hardware.
434 //-----------------------------------------------------------------------------
435 void PseudoAxis::write_offset(Tango::WAttribute
&attr
)
437 DEBUG_STREAM
<< "PseudoAxis::write_offset(Tango::WAttribute &attr) entering... "<< endl
;
438 // Add your own code here
439 attr
.get_write_value(attr_offset_write
);
440 *attr_offset_read
= attr_offset_write
;
443 //+----------------------------------------------------------------------------
445 // method : PseudoAxis::read_relativeMove
447 // description : Extract real attribute values for relativeMove acquisition result.
449 //-----------------------------------------------------------------------------
450 void PseudoAxis::read_relativeMove(Tango::Attribute
&attr
)
452 DEBUG_STREAM
<< "PseudoAxis::read_relativeMove(Tango::Attribute &attr) entering... "<< endl
;
453 // Add your own code here
454 attr
.set_value(&attr_relativeMove_write
);
457 //+----------------------------------------------------------------------------
459 // method : PseudoAxis::write_relativeMove
461 // description : Write relativeMove attribute values to hardware.
463 //-----------------------------------------------------------------------------
464 void PseudoAxis::write_relativeMove(Tango::WAttribute
&attr
)
466 DEBUG_STREAM
<< "PseudoAxis::write_relativeMove(Tango::WAttribute &attr) entering... "<< endl
;
467 // Add your own code here
468 attr
.get_write_value(attr_relativeMove_write
);
469 double new_position
= *attr_position_read
+ attr_relativeMove_write
;
471 // Write to the "position" attribute to move the axe.
472 Tango::DeviceProxyHelper
moi(this->device_name
, this);
473 moi
.write_attribute("position", new_position
);
477 //+----------------------------------------------------------------------------
479 // method : PseudoAxis::read_IsInitialised
481 // description : Extract real attribute values for IsInitialised acquisition result.
483 //-----------------------------------------------------------------------------
484 void PseudoAxis::read_IsInitialised(Tango::Attribute
&attr
)
486 DEBUG_STREAM
<< "PseudoAxis::read_IsInitialised(Tango::Attribute &attr) entering... "<< endl
;
487 // Add your own code here
490 *attr_IsInitialised_read
= _buffer
->get_is_initialised();
491 attr
.set_value(attr_IsInitialised_read
);
494 //+------------------------------------------------------------------
496 * method: PseudoAxis::motor_off
498 * description: method to execute "MotorOFF"
499 * Disable the pseudoAxis.
503 //+------------------------------------------------------------------
504 void PseudoAxis::motor_off()
506 DEBUG_STREAM
<< "PseudoAxis::motor_off(): entering... !" << endl
;
508 // Add your own code to control device here
511 //+------------------------------------------------------------------
513 * method: PseudoAxis::motor_on
515 * description: method to execute "MotorON"
516 * Activate the pseudoAxis
520 //+------------------------------------------------------------------
521 void PseudoAxis::motor_on()
523 DEBUG_STREAM
<< "PseudoAxis::motor_on(): entering... !" << endl
;
525 // Add your own code to control device here
530 //+------------------------------------------------------------------
532 * method: PseudoAxis::compute_new_offset
534 * description: method to execute "ComputeNewOffset"
535 * The so smart program computes the offset to goal the user position.
537 * @param argin The new user position
540 //+------------------------------------------------------------------
541 void PseudoAxis::compute_new_offset(Tango::DevDouble argin
)
543 DEBUG_STREAM
<< "PseudoAxis::compute_new_offset(): entering... !" << endl
;
545 // Add your own code to control device here
546 if (_hklAdapter
&& _buffer
) {
547 _hklAdapter
->update();
548 Tango::DeviceProxyHelper
moi(this->device_name
, this);
549 moi
.write_attribute("offset", argin
- _buffer
->get_read());
553 //+------------------------------------------------------------------
555 * method: PseudoAxis::stop
557 * description: method to execute "Stop"
558 * Stop the pseudoAxes and all related axes.
562 //+------------------------------------------------------------------
563 void PseudoAxis::stop()
565 DEBUG_STREAM
<< "PseudoAxis::stop(): entering... !" << endl
;
567 // Add your own code to control device here
568 // FRED here use the _pseudoAxe->relatedAxes to stop the right axes.
569 _hklAdapter
->stop_all_axis();
573 //+------------------------------------------------------------------
575 * method: PseudoAxis::motor_init
577 * description: method to execute "MotorInit"
578 * Some pseudoAxis must be initialized before we can used them.
582 //+------------------------------------------------------------------
583 void PseudoAxis::motor_init()
585 DEBUG_STREAM
<< "PseudoAxis::motor_init(): entering... !" << endl
;
588 // Add your own code to control device here
590 _buffer
->set_is_initialised(true);
592 _hklAdapter
->update();
595 //+------------------------------------------------------------------
597 * method: PseudoAxis::backward
599 * description: method to execute "Backward"
600 * dummy command for V2 interface
604 //+------------------------------------------------------------------
605 void PseudoAxis::backward()
607 DEBUG_STREAM
<< "PseudoAxis::backward(): entering... !" << endl
;
609 // Add your own code to control device here
613 //+------------------------------------------------------------------
615 * method: PseudoAxis::forward
617 * description: method to execute "Forward"
618 * dummy command for V2 interface
622 //+------------------------------------------------------------------
623 void PseudoAxis::forward()
625 DEBUG_STREAM
<< "PseudoAxis::forward(): entering... !" << endl
;
627 // Add your own code to control device here
631 //+------------------------------------------------------------------
633 * method: PseudoAxis::define_position
635 * description: method to execute "DefinePosition"
636 * dummy command for V2 interface
641 //+------------------------------------------------------------------
642 void PseudoAxis::define_position(Tango::DevDouble argin
)
644 DEBUG_STREAM
<< "PseudoAxis::define_position(): entering... !" << endl
;
646 // Add your own code to control device here
650 //+------------------------------------------------------------------
652 * method: PseudoAxis::initialize_reference_position
654 * description: method to execute "InitializeReferencePosition"
655 * dummy command for V2 interface
659 //+------------------------------------------------------------------
660 void PseudoAxis::initialize_reference_position()
662 DEBUG_STREAM
<< "PseudoAxis::initialize_reference_position(): entering... !" << endl
;
664 // Add your own code to control device here
669 //+------------------------------------------------------------------
671 * method: PseudoAxis::get_mode_parameters
673 * description: method to execute "GetModeParameters"
674 * this command return for the current mode, its parameters.
676 * @return parameters names and values
679 //+------------------------------------------------------------------
680 Tango::DevVarDoubleStringArray
*PseudoAxis::get_mode_parameters()
682 // POGO has generated a method core with argout allocation.
683 // If you would like to use a static reference without copying,
684 // See "TANGO Device Server Programmer's Manual"
685 // (chapter : Writing a TANGO DS / Exchanging data)
686 //------------------------------------------------------------
687 Tango::DevVarDoubleStringArray
*argout
= new Tango::DevVarDoubleStringArray();
688 argout
->dvalue
.length(1);
689 argout
->dvalue
[0] = 0.0;
690 argout
->svalue
.length(1);
691 argout
->svalue
[0] = CORBA::string_dup("dummy");
692 DEBUG_STREAM
<< "PseudoAxis::get_mode_parameters(): entering... !" << endl
;
694 // Add your own code to control device here
696 _buffer
->get_mode_parameters(argout
);
701 //+------------------------------------------------------------------
703 * method: PseudoAxis::set_mode_parameters
705 * description: method to execute "SetModeParameters"
707 * @param argin The parameters to set
710 //+------------------------------------------------------------------
711 void PseudoAxis::set_mode_parameters(const Tango::DevVarDoubleStringArray
*argin
)
713 DEBUG_STREAM
<< "PseudoAxis::set_mode_parameters(): entering... !" << endl
;
715 // Add your own code to control device here
717 _buffer
->set_mode_parameters(argin
);