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
;
313 attr
.set_value(_buffer
->get_mode());
316 //+----------------------------------------------------------------------------
318 // method : PseudoAxis::write_mode
320 // description : Write mode attribute values to hardware.
322 //-----------------------------------------------------------------------------
323 void PseudoAxis::write_mode(Tango::WAttribute
&attr
)
325 DEBUG_STREAM
<< "PseudoAxis::write_mode(Tango::WAttribute &attr) entering... "<< endl
;
326 attr
.get_write_value(attr_mode_write
);
328 _buffer
->set_mode(attr_mode_write
);
331 //+----------------------------------------------------------------------------
333 // method : PseudoAxis::read_modeNames
335 // description : Extract real attribute values for modeNames acquisition result.
337 //-----------------------------------------------------------------------------
338 void PseudoAxis::read_modeNames(Tango::Attribute
&attr
)
340 DEBUG_STREAM
<< "PseudoAxis::read_modeNames(Tango::Attribute &attr) entering... "<< endl
;
342 Matrix
<char *> const & img
= _buffer
->get_mode_names();
343 attr
.set_value(img
.data
, img
.xdim
);
347 //+----------------------------------------------------------------------------
349 // method : PseudoAxis::write_IsInitialised
351 // description : Write IsInitialised attribute values to hardware.
353 //-----------------------------------------------------------------------------
354 void PseudoAxis::write_IsInitialised(Tango::WAttribute
&attr
)
356 DEBUG_STREAM
<< "PseudoAxis::write_IsInitialised(Tango::WAttribute &attr) entering... "<< endl
;
357 // Add your own code here
358 attr
.get_write_value(attr_IsInitialised_write
);
360 // need to update the internals before initializing the pseudo
362 _hklAdapter
->update();
364 _hklAdapter
->pseudo_axis_init(_buffer
, attr_IsInitialised_write
);
365 _hklAdapter
->update();
370 //+----------------------------------------------------------------------------
372 // method : PseudoAxis::read_position
374 // description : Extract real attribute values for position acquisition result.
376 //-----------------------------------------------------------------------------
377 void PseudoAxis::read_position(Tango::Attribute
&attr
)
379 DEBUG_STREAM
<< "PseudoAxis::read_position(Tango::Attribute &attr) entering... "<< endl
;
380 // Add your own code here
382 if (_hklAdapter
&& _buffer
) {
383 _hklAdapter
->update();
385 // first the read part
386 *attr_position_read
= _buffer
->get_read();
387 *attr_position_read
+= *attr_offset_read
;
388 // second the write part
389 attr_position_write
= _buffer
->get_write();
390 attr_position_write
+= *attr_offset_read
;
391 // now use Tango to aknowledge for the write part.
392 Tango::WAttribute
& att
= dev_attr
->get_w_attr_by_name(attr
.get_name().c_str());
393 att
.set_write_value(attr_position_write
);
395 attr
.set_value(attr_position_read
);
398 //+----------------------------------------------------------------------------
400 // method : PseudoAxis::write_position
402 // description : Write position attribute values to hardware.
404 //-----------------------------------------------------------------------------
405 void PseudoAxis::write_position(Tango::WAttribute
&attr
)
407 DEBUG_STREAM
<< "PseudoAxis::write_position(Tango::WAttribute &attr) entering... "<< endl
;
408 // Add your own code here
410 attr
.get_write_value(attr_position_write
);
411 if (_hklAdapter
&& _buffer
)
412 _hklAdapter
->pseudo_axis_write(_buffer
, attr_position_write
- *attr_offset_read
);
415 //+----------------------------------------------------------------------------
417 // method : PseudoAxis::read_offset
419 // description : Extract real attribute values for offset acquisition result.
421 //-----------------------------------------------------------------------------
422 void PseudoAxis::read_offset(Tango::Attribute
&attr
)
424 DEBUG_STREAM
<< "PseudoAxis::read_offset(Tango::Attribute &attr) entering... "<< endl
;
425 // Add your own code here
426 attr
.set_value(attr_offset_read
);
429 //+----------------------------------------------------------------------------
431 // method : PseudoAxis::write_offset
433 // description : Write offset attribute values to hardware.
435 //-----------------------------------------------------------------------------
436 void PseudoAxis::write_offset(Tango::WAttribute
&attr
)
438 DEBUG_STREAM
<< "PseudoAxis::write_offset(Tango::WAttribute &attr) entering... "<< endl
;
439 // Add your own code here
440 attr
.get_write_value(attr_offset_write
);
441 *attr_offset_read
= attr_offset_write
;
444 //+----------------------------------------------------------------------------
446 // method : PseudoAxis::read_relativeMove
448 // description : Extract real attribute values for relativeMove acquisition result.
450 //-----------------------------------------------------------------------------
451 void PseudoAxis::read_relativeMove(Tango::Attribute
&attr
)
453 DEBUG_STREAM
<< "PseudoAxis::read_relativeMove(Tango::Attribute &attr) entering... "<< endl
;
454 // Add your own code here
455 attr
.set_value(&attr_relativeMove_write
);
458 //+----------------------------------------------------------------------------
460 // method : PseudoAxis::write_relativeMove
462 // description : Write relativeMove attribute values to hardware.
464 //-----------------------------------------------------------------------------
465 void PseudoAxis::write_relativeMove(Tango::WAttribute
&attr
)
467 DEBUG_STREAM
<< "PseudoAxis::write_relativeMove(Tango::WAttribute &attr) entering... "<< endl
;
468 // Add your own code here
469 attr
.get_write_value(attr_relativeMove_write
);
470 double new_position
= *attr_position_read
+ attr_relativeMove_write
;
472 // Write to the "position" attribute to move the axe.
473 Tango::DeviceProxyHelper
moi(this->device_name
, this);
474 moi
.write_attribute("position", new_position
);
478 //+----------------------------------------------------------------------------
480 // method : PseudoAxis::read_IsInitialised
482 // description : Extract real attribute values for IsInitialised acquisition result.
484 //-----------------------------------------------------------------------------
485 void PseudoAxis::read_IsInitialised(Tango::Attribute
&attr
)
487 DEBUG_STREAM
<< "PseudoAxis::read_IsInitialised(Tango::Attribute &attr) entering... "<< endl
;
488 // Add your own code here
490 attr
.set_value(attr_IsInitialised_read
);
493 //+------------------------------------------------------------------
495 * method: PseudoAxis::motor_off
497 * description: method to execute "MotorOFF"
498 * Disable the pseudoAxis.
502 //+------------------------------------------------------------------
503 void PseudoAxis::motor_off()
505 DEBUG_STREAM
<< "PseudoAxis::motor_off(): entering... !" << endl
;
507 // Add your own code to control device here
510 //+------------------------------------------------------------------
512 * method: PseudoAxis::motor_on
514 * description: method to execute "MotorON"
515 * Activate the pseudoAxis
519 //+------------------------------------------------------------------
520 void PseudoAxis::motor_on()
522 DEBUG_STREAM
<< "PseudoAxis::motor_on(): entering... !" << endl
;
524 // Add your own code to control device here
526 _hklAdapter
->update();
528 _hklAdapter
->pseudo_axis_init(_buffer
, true);
530 _hklAdapter
->update();
534 //+------------------------------------------------------------------
536 * method: PseudoAxis::compute_new_offset
538 * description: method to execute "ComputeNewOffset"
539 * The so smart program computes the offset to goal the user position.
541 * @param argin The new user position
544 //+------------------------------------------------------------------
545 void PseudoAxis::compute_new_offset(Tango::DevDouble argin
)
547 DEBUG_STREAM
<< "PseudoAxis::compute_new_offset(): entering... !" << endl
;
549 // Add your own code to control device here
550 if (_hklAdapter
&& _buffer
) {
551 _hklAdapter
->update();
552 Tango::DeviceProxyHelper
moi(this->device_name
, this);
553 moi
.write_attribute("offset", argin
- _buffer
->get_read());
557 //+------------------------------------------------------------------
559 * method: PseudoAxis::stop
561 * description: method to execute "Stop"
562 * Stop the pseudoAxes and all related axes.
566 //+------------------------------------------------------------------
567 void PseudoAxis::stop()
569 DEBUG_STREAM
<< "PseudoAxis::stop(): entering... !" << endl
;
571 // Add your own code to control device here
572 // FRED here use the _pseudoAxe->relatedAxes to stop the right axes.
573 _hklAdapter
->stop_all_axis();
577 //+------------------------------------------------------------------
579 * method: PseudoAxis::motor_init
581 * description: method to execute "MotorInit"
582 * Some pseudoAxis must be initialized before we can used them.
586 //+------------------------------------------------------------------
587 void PseudoAxis::motor_init()
589 DEBUG_STREAM
<< "PseudoAxis::motor_init(): entering... !" << endl
;
591 // Add your own code to control device here
593 _hklAdapter
->update();
596 _hklAdapter
->pseudo_axis_init(_buffer
, true);
597 _hklAdapter
->update();
602 //+------------------------------------------------------------------
604 * method: PseudoAxis::backward
606 * description: method to execute "Backward"
607 * dummy command for V2 interface
611 //+------------------------------------------------------------------
612 void PseudoAxis::backward()
614 DEBUG_STREAM
<< "PseudoAxis::backward(): entering... !" << endl
;
616 // Add your own code to control device here
620 //+------------------------------------------------------------------
622 * method: PseudoAxis::forward
624 * description: method to execute "Forward"
625 * dummy command for V2 interface
629 //+------------------------------------------------------------------
630 void PseudoAxis::forward()
632 DEBUG_STREAM
<< "PseudoAxis::forward(): entering... !" << endl
;
634 // Add your own code to control device here
638 //+------------------------------------------------------------------
640 * method: PseudoAxis::define_position
642 * description: method to execute "DefinePosition"
643 * dummy command for V2 interface
648 //+------------------------------------------------------------------
649 void PseudoAxis::define_position(Tango::DevDouble argin
)
651 DEBUG_STREAM
<< "PseudoAxis::define_position(): entering... !" << endl
;
653 // Add your own code to control device here
657 //+------------------------------------------------------------------
659 * method: PseudoAxis::initialize_reference_position
661 * description: method to execute "InitializeReferencePosition"
662 * dummy command for V2 interface
666 //+------------------------------------------------------------------
667 void PseudoAxis::initialize_reference_position()
669 DEBUG_STREAM
<< "PseudoAxis::initialize_reference_position(): entering... !" << endl
;
671 // Add your own code to control device here
676 //+------------------------------------------------------------------
678 * method: PseudoAxis::get_mode_parameters
680 * description: method to execute "GetModeParameters"
681 * this command return for the current mode, its parameters.
683 * @return parameters names and values
686 //+------------------------------------------------------------------
687 Tango::DevVarDoubleStringArray
*PseudoAxis::get_mode_parameters()
689 // POGO has generated a method core with argout allocation.
690 // If you would like to use a static reference without copying,
691 // See "TANGO Device Server Programmer's Manual"
692 // (chapter : Writing a TANGO DS / Exchanging data)
693 //------------------------------------------------------------
694 Tango::DevVarDoubleStringArray
*argout
= new Tango::DevVarDoubleStringArray();
695 argout
->dvalue
.length(1);
696 argout
->dvalue
[0] = 0.0;
697 argout
->svalue
.length(1);
698 argout
->svalue
[0] = CORBA::string_dup("dummy");
699 DEBUG_STREAM
<< "PseudoAxis::get_mode_parameters(): entering... !" << endl
;
701 // Add your own code to control device here
703 _buffer
->get_mode_parameters(argout
);
708 //+------------------------------------------------------------------
710 * method: PseudoAxis::set_mode_parameters
712 * description: method to execute "SetModeParameters"
714 * @param argin The parameters to set
717 //+------------------------------------------------------------------
718 void PseudoAxis::set_mode_parameters(const Tango::DevVarDoubleStringArray
*argin
)
720 DEBUG_STREAM
<< "PseudoAxis::set_mode_parameters(): entering... !" << endl
;
722 // Add your own code to control device here
724 _buffer
->set_mode_parameters(argin
);