This file is indexed.

/usr/lib/python2.7/dist-packages/sardana/pool/poolcontrollers/DummyMotorController.py is in python-sardana 1.2.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
##############################################################################
##
## This file is part of Sardana
##
## http://www.tango-controls.org/static/sardana/latest/doc/html/index.html
##
## Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
##
## Sardana is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## Sardana is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with Sardana.  If not, see <http://www.gnu.org/licenses/>.
##
##############################################################################

import time
from math import pow, sqrt

from sardana import State, SardanaValue
from sardana.pool.controller import MotorController
from sardana.pool.controller import DefaultValue, Description, FGet, FSet, Type


class BaseMotion(object):

    def __init__(self):
        self.min_vel = -1
        self.max_vel = -1
        self.accel_time = -1
        self.decel_time = -1
        self.accel = -1
        self.decel = -1

        self.init_pos = -1
        self.final_pos = -1
        self.curr_pos = -1


class Motion(BaseMotion):

    def __init__(self):
        BaseMotion.__init__(self)

        self.dsplmnt_reach_max_vel = -1
        self.dsplmnt_reach_min_vel = -1
        self.dsplmnt = -1

        self.curr_instant = -1
        self.start_instant = -1

        self.positive_dsplmnt = True
        self.small_motion = False

        # position where maximum velocity will be reached
        self.curr_max_vel_pos  = -1

        # necessary displacement to reach maximum velocity
        self.curr_dsplmnt_reach_max_vel = -1

        # necessary displacement to reach minimum velocity
        self.curr_dsplmnt_reach_min_vel = -1

        # maximum velocity possible
        self.curr_max_vel = -1

        # time at maximum velocity
        self.curr_at_max_vel_dsplmnt = -1

        # time to reach maximum velocity
        self.curr_max_vel_time = -1

        # time to reach minimum velocity
        self.curr_min_vel_time = -1

        # time at maximum velocity
        self.curr_at_max_vel_time = -1

        # instant when maximum velocity should be reached
        self.curr_max_vel_instant = -1

        # instant when should start decelerating
        self.curr_min_vel_instant = -1

        # time the motion will take
        self.duration = -1

        # instant the motion will end
        self.final_instant = -1

        # steps per unit
        self.step_per_unit = 1

        self.inMotion = False

        self.lower_ls = float('-inf')
        self.upper_ls = float('+inf')

        self.power = True
        self.enabled = True

        self.__recalculate_acc_constants()

    def setMinVelocity(self,vi):
        """ Sets the minimum velocity in ms^-1. A.k.a. base rate"""
        vi = float(vi)
        if vi < 0:
            raise "Minimum velocity must be >= 0"

        self.min_vel = vi

        if self.max_vel < self.min_vel:
            self.max_vel = self.min_vel

        # force recalculation of accelerations
        if self.accel_time >= 0:
            self.setAccelerationTime(self.accel_time)
        if self.decel_time >= 0:
            self.setDecelerationTime(self.decel_time)

    def getMinVelocity(self):
        return self.min_vel

    def setMaxVelocity(self,vf):
        """ Sets the maximum velocity in ms^-1."""
        vf = float(vf)
        if vf <= 0:
            raise "Maximum velocity must be > 0"

        self.max_vel = vf

        if self.min_vel > self.max_vel:
            self.min_vel = self.max_vel

        # force recalculation of accelerations
        if self.accel_time >= 0:
            self.setAccelerationTime(self.accel_time)
        if self.decel_time >= 0:
            self.setDecelerationTime(self.decel_time)

    def getMaxVelocity(self):
        return self.max_vel

    def setAccelerationTime(self,at):
        """Sets the time to go from minimum velocity to maximum velocity in seconds"""
        at = float(at)
        if at <= 0:
            raise "Acceleration time must be > 0"

        self.accel_time = at
        self.accel = (self.max_vel - self.min_vel) / at

        self.__recalculate_acc_constants()

    def getAccelerationTime(self):
        return self.accel_time

    def setDecelerationTime(self,dt):
        """Sets the time to go from maximum velocity to minimum velocity in seconds"""
        dt = float(dt)
        if dt <= 0:
            raise "Deceleration time must be > 0"

        self.decel_time = dt
        self.decel = (self.min_vel - self.max_vel) / dt

        self.__recalculate_acc_constants()

    def getDecelerationTime(self):
        return self.decel_time

    def setAcceleration(self,a):
        """Sets the acceleration in ms^-2"""
        a = float(a)
        if a < 0:
            raise "Acceleration must be >= 0"

        self.accel = float(a)

        if a > 0:
            self.accel_time = (self.max_vel - self.min_vel) / a
        else:
            self.accel_time = float('INF')

        self.__recalculate_acc_constants()

    def setDeceleration(self,d):
        """Sets the deceleration in ms^-2"""
        d = float(d)
        if d > 0:
            raise "Deceleration must be <= 0"

        self.decel = d

        if d < 0:
            self.decel_time = (self.min_vel - self.max_vel) / d
        else:
            self.decel_time = float('INF')

        self.__recalculate_acc_constants()

    def getStepPerUnit(self):
        return self.step_per_unit

    def setStepPerUnit(self, spu):
        self.step_per_unit = spu

    def __recalculate_acc_constants(self):
        """pre-computations assuming maximum speed can be reached in a motion"""

        self.dsplmnt_reach_max_vel = 0.5 * self.accel * pow(self.accel_time,2)
        self.dsplmnt_reach_max_vel += self.min_vel * self.accel_time

        self.dsplmnt_reach_min_vel = 0.5 * self.decel * pow(self.decel_time,2)
        self.dsplmnt_reach_min_vel += self.max_vel * self.decel_time

    def startMotion(self, initial_user_pos, final_user_pos, start_instant=None):
        """starts a new motion"""

        if not self.power:
            raise Exception("Motor is powered off")

        initial_pos = initial_user_pos * self.step_per_unit
        final_pos = final_user_pos * self.step_per_unit

        if self.inMotion:
            raise Exception("Already in motion")

        if initial_pos == final_pos:
            return

        self.init_pos = initial_pos
        self.final_pos = final_pos
        self.curr_pos = initial_pos
        self.dsplmnt = abs(final_pos - initial_pos)

        start_instant = start_instant or time.time()
        self.curr_instant = start_instant
        self.start_instant = start_instant

        self.positive_dsplmnt = final_pos >= initial_pos

        displmnt_not_cnst = self.dsplmnt_reach_max_vel + self.dsplmnt_reach_min_vel
        self.small_motion = self.dsplmnt < displmnt_not_cnst

        if self.positive_dsplmnt:
            self.curr_accel = self.accel
            self.curr_decel = self.decel
        else:
            self.curr_accel = -self.accel
            self.curr_decel = -self.decel


        if not self.small_motion:

            # necessary displacement to reach maximum velocity
            self.curr_dsplmnt_reach_max_vel = self.dsplmnt_reach_max_vel
            # necessary diplacement to reach minimum velocity
            self.curr_dsplmnt_reach_min_vel = self.dsplmnt_reach_min_vel

            if self.positive_dsplmnt:
                self.curr_max_vel = self.max_vel
                self.curr_min_vel = self.min_vel
                # position where maximum velocity will be reached
                self.curr_max_vel_pos = self.init_pos + self.curr_dsplmnt_reach_max_vel
            else:
                self.curr_max_vel = -self.max_vel
                self.curr_min_vel = -self.min_vel
                # position where maximum velocity will be reached
                self.curr_max_vel_pos = self.init_pos - self.curr_dsplmnt_reach_max_vel

            # displacement at maximum velocity
            self.curr_at_max_vel_dsplmnt = self.dsplmnt - (self.curr_dsplmnt_reach_max_vel + self.curr_dsplmnt_reach_min_vel)

        else:  # Small movement
            # position where maximum velocity will be reached
            self.curr_max_vel_pos  = self.init_pos * self.curr_accel - self.final_pos * self.curr_decel
            self.curr_max_vel_pos /= self.curr_accel - self.curr_decel

            # necessary displacement to reach maximum velocity
            self.curr_dsplmnt_reach_max_vel = abs(self.curr_max_vel_pos - self.init_pos)

            # necessary diplacement to reach minimum velocity
            self.curr_dsplmnt_reach_min_vel = abs(self.final_pos - self.curr_max_vel_pos)

            # maximum velocity possible
            cnst = 2 * self.curr_accel * self.curr_decel * self.dsplmnt / (self.curr_decel - self.curr_accel)
            max_vel_2 = pow(self.min_vel, 2) + cnst

            self.curr_max_vel = sqrt(abs(max_vel_2))

            if self.positive_dsplmnt:
                self.curr_min_vel = self.min_vel
            else:
                self.curr_max_vel = -self.curr_max_vel
                self.curr_min_vel = -self.min_vel

            # displacement at maximum velocity
            self.curr_at_max_vel_dsplmnt = 0.0

        # time to reach maximum velocity
        self.curr_max_vel_time = abs((self.curr_max_vel - self.curr_min_vel) / self.curr_accel)

        # time to reach minimum velocity
        self.curr_min_vel_time = abs((self.curr_min_vel - self.curr_max_vel) / self.curr_decel)

        # time at maximum velocity
        self.curr_at_max_vel_time = abs(self.curr_at_max_vel_dsplmnt / self.curr_max_vel)

        # instant when maximum velocity should be reached
        self.curr_max_vel_instant = self.start_instant + self.curr_max_vel_time

        # instant when should start decelerating
        self.curr_min_vel_instant = self.curr_max_vel_instant + self.curr_at_max_vel_time

        # time the motion will take
        self.duration = self.curr_max_vel_time + self.curr_at_max_vel_time + self.curr_min_vel_time

        # instant the motion will end
        self.final_instant = self.start_instant + self.duration

        # uncomment following line if need output concerning the movement that
        # has just started
        # self.info()

        # ASSERTIONS
        if self.positive_dsplmnt:
            assert(self.curr_max_vel_pos >= self.init_pos)
            assert(self.curr_max_vel_pos <= self.final_pos)
        else:
            assert(self.curr_max_vel_pos <= self.init_pos)
            assert(self.curr_max_vel_pos >= self.final_pos)

        assert(self.curr_dsplmnt_reach_max_vel >= 0.0)
        assert(self.curr_dsplmnt_reach_min_vel >= 0.0)

        assert(self.final_instant >= self.start_instant)
        assert(self.curr_max_vel <= self.max_vel)
        assert(self.start_instant <= self.curr_max_vel_instant)
        assert(self.final_instant >= self.curr_min_vel_instant)

        assert(self.curr_max_vel_time > 0.0)
        assert(self.curr_min_vel_time > 0.0)
        assert(self.duration > 0.0)

        if self.small_motion:
            assert(self.curr_max_vel_instant == self.curr_min_vel_instant)
            assert(self.curr_at_max_vel_time == 0.0)
        else:
            assert(self.curr_max_vel_instant <= self.curr_min_vel_instant)
            assert(self.curr_at_max_vel_time >= 0.0)

        self.inMotion = True

    def abortMotion(self, curr_instant=None):
        curr_instant = curr_instant or time.time()
        if not self.inMotion:
            return self.curr_pos

        self.curr_pos = self.getCurrentPosition(curr_instant)
        self.inMotion = False
        return self.curr_pos

    def isInMotion(self,curr_instant=None):
        curr_instant = curr_instant or time.time()
        #we call getCurrentPosition because inside it updates the inMotion flag
        self.getCurrentPosition(curr_instant)
        return self.inMotion

    def setCurrentPosition(self, curr_pos):
        self.curr_pos = curr_pos
        self.init_pos = curr_pos

    def getCurrentPosition(self, curr_instant=None):
        curr_instant = curr_instant or time.time()
        self.curr_instant = curr_instant
        pos = None
        if self.inMotion:
            # if motion should be ended...
            if self.curr_instant >= self.final_instant:
                self.inMotion = False
                pos = self.final_pos
            else:
                pos  = self.init_pos
                if curr_instant > self.curr_min_vel_instant:
                    if self.positive_dsplmnt:
                        pos += self.curr_dsplmnt_reach_max_vel
                        pos += self.curr_at_max_vel_dsplmnt
                    else:
                        pos -= self.curr_dsplmnt_reach_max_vel
                        pos -= self.curr_at_max_vel_dsplmnt
                    dt = curr_instant - self.curr_min_vel_instant
                    pos += self.curr_max_vel * dt + 0.5 * self.curr_decel * pow(dt,2)
                elif curr_instant > self.curr_max_vel_instant:
                    if self.positive_dsplmnt:
                        pos += self.curr_dsplmnt_reach_max_vel
                    else:
                        pos -= self.curr_dsplmnt_reach_max_vel
                    dt = curr_instant - self.curr_max_vel_instant
                    pos += self.curr_max_vel * dt
                else:
                    dt  = curr_instant - self.start_instant
                    pos += self.curr_min_vel * dt + 0.5 * self.curr_accel * pow(dt,2)
        else:
            pos = self.curr_pos
        if pos <= self.lower_ls:
            pos = self.lower_ls
            self.inMotion = False
        elif pos >= self.upper_ls:
            pos = self.upper_ls
            self.inMotion = False
        self.curr_pos = pos
        return pos

    def setCurrentUserPosition(self, user_pos):
        self.setCurrentPosition(user_pos*self.step_per_unit)

    def getCurrentUserPosition(self, curr_instant=None):
        return self.getCurrentPosition(curr_instant=curr_instant) / self.step_per_unit

    def hitLowerLimit(self):
        user_pos = self.curr_pos / self.step_per_unit
        return user_pos <= self.lower_ls

    def hitUpperLimit(self):
        user_pos = self.curr_pos / self.step_per_unit
        return user_pos >= self.upper_ls

    def getLowerLimitSwitch(self):
        return self.lower_ls

    def setLowerLimitSwitch(self, user_lower_ls):
        self.lower_ls = user_lower_ls

    def getUpperLimitSwitch(self):
        return self.upper_ls

    def setUpperLimitSwitch(self, user_upper_ls):
        self.upper_ls = user_upper_ls

    def turnOn(self):
        self.power = True

    def turnOff(self):
        self.power = False

    def isTurnedOn(self):
        return self.power

    def hasPower(self):
        return self.power

    def setPower(self, power):
        self.power = power

    def info(self):
        print "Small movement =",self.small_motion
        print "length =",self.dsplmnt
        print "position where maximum velocity will be reached =",self.curr_max_vel_pos
        print "necessary displacement to reach maximum velocity =",self.curr_dsplmnt_reach_max_vel
        print "necessary displacement to stop from maximum velocity =",self.curr_dsplmnt_reach_min_vel
        print "maximum velocity possible =",self.curr_max_vel
        print "time at top velocity =",self.curr_at_max_vel_time
        print "displacement at top velocity =",self.curr_at_max_vel_dsplmnt
        print "time to reach maximum velocity =",self.curr_max_vel_time
        print "time to reach minimum velocity =",self.curr_min_vel_time
        print "time the motion will take =",self.duration
        print "instant when maximum velocity should be reached =",self.curr_max_vel_instant
        print "instant when should start decelerating =",self.curr_min_vel_instant
        print "instant the motion will end",self.final_instant
        print ""
        print "For long movements (where top vel is possible), necessary displacement to reach maximum velocity =",self.dsplmnt_reach_max_vel
        print "For long movements (where top vel is possible), necessary displacement to stop from maximum velocity =",self.dsplmnt_reach_min_vel


class BasicDummyMotorController(MotorController):
    """This class represents a basic, dummy Sardana motor controller."""

    gender = "Simulation"
    model  = "Basic"
    organization = "Sardana team"

    MaxDevice = 1024

    def __init__(self, inst, props, *args, **kwargs):
        MotorController.__init__(self, inst, props, *args, **kwargs)
        self.m = self.MaxDevice*[None,]

    def GetAxisAttributes(self, axis):
        axis_attrs = MotorController.GetAxisAttributes(self, axis)
        new_axis_attrs = {}
        for attr in ('Position', 'Limit_switches'):
            new_axis_attrs[attr] = axis_attrs[attr]
        return new_axis_attrs

    def AddDevice(self,axis):
        MotorController.AddDevice(self, axis)
        idx = axis - 1
        if len(self.m) < axis:
            raise Exception("Invalid axis %d" % axis)
        if self.m[idx] is None:
            m = Motion()
            m.setMinVelocity(2)
            m.setMaxVelocity(100)
            m.setAccelerationTime(2)
            m.setDecelerationTime(2)
            m.setCurrentPosition(0)
            self.m[idx] = m

    def DeleteDevice(self, axis):
        MotorController.DeleteDevice(self, axis)
        idx = axis - 1
        if len(self.m) < axis or not self.m[idx]:
            self._log.error("Invalid axis %d" % axis)
        #self.m[idx] = None

    def StateOne(self, axis):
        #self._log.debug("StateOne(%d)", axis)
        #raise Exception("Cannot StateOne %d" % axis)
        idx = axis - 1
        m = self.m[idx]
        state = State.On
        status = "Motor HW is ON"
        if m.isInMotion():
            state = State.Moving
            status = "Motor HW is MOVING"
        m.getCurrentUserPosition()
        switchstate = 0
        if m.hitLowerLimit():
            switchstate |= MotorController.LowerLimitSwitch
            state = State.Alarm
            status = "Motor HW is in ALARM. Hit hardware lower limit switch"
        if m.hitUpperLimit():
            switchstate |= MotorController.UpperLimitSwitch
            state = State.Alarm
            status = "Motor HW is in ALARM. Hit hardware upper limit switch"
        if state != State.Alarm and not m.hasPower():
            state = State.Off
            status = "Motor is powered off"
        #self._log.info("StateOne(%s) = %s", axis, (state, status, switchstate))
        return state, status, switchstate

    def ReadOne(self, axis):
        #self._log.debug("ReadOne(%d)", axis)
        #raise Exception("Cannot ReadOne")
        idx = axis - 1
        m = self.m[idx]
        ts = time.time() #simulate as if we got it from hardware
        return SardanaValue(m.getCurrentUserPosition(), timestamp=ts)
        #return m.getCurrentUserPosition()

    def PreStartAll(self):
        #raise Exception("Cannot move on PreStartAll")
        self.motions = {}

    def PreStartOne(self, axis, pos):
        #raise Exception("Cannot move on PreStartOne")
        idx = axis - 1
        m = self.m[idx]
        return m.hasPower()

    def StartOne(self, axis, pos):
        #raise Exception("Cannot move on StartOne")
        idx = axis - 1
        self.motions[self.m[idx]] = pos

    def StartAll(self):
        #raise Exception("Cannot move on StartAll")
        t = time.time()
        for motion, pos in self.motions.items():
            motion.startMotion(motion.getCurrentUserPosition(t), pos, t)

    def AbortOne(self, axis):
        self._log.info("AbortOne(%d)", axis)
        idx = axis - 1
        self.m[idx].abortMotion()

    def SendToCtrl(self, stream):
        return stream

class FastDummyMotorController(MotorController):

    gender = "Simulation"
    model  = "Basic"
    organization = "Sardana team"

    MaxDevice = 1024

    def __init__(self, inst, props, *args, **kwargs):
        MotorController.__init__(self, inst, props, *args, **kwargs)
        self.m = self.MaxDevice*[None,]

    def GetAxisAttributes(self, axis):
        axis_attrs = MotorController.GetAxisAttributes(self, axis)
        new_axis_attrs = {}
        for attr in ('Position', 'Limit_switches'):
            new_axis_attrs[attr] = axis_attrs[attr]
        return new_axis_attrs

    def AddDevice(self,axis):
        MotorController.AddDevice(self, axis)
        idx = axis - 1
        if len(self.m) < axis:
            raise Exception("Invalid axis %d" % axis)
        if self.m[idx] is None:
            self.m[idx] = BaseMotion()

    def DeleteDevice(self, axis):
        MotorController.DeleteDevice(self, axis)
        idx = axis - 1
        if len(self.m) < axis or not self.m[idx]:
            self._log.error("Invalid axis %d" % axis)
        #self.m[idx] = None

    def StateOne(self, axis):
        #self._log.debug("StateOne(%d)", axis)
        state = State.On
        status = "Motor HW is ON"
        switchstate = 0
        return state, status, switchstate

    def ReadOne(self, axis):
        self._log.debug("ReadOne(%d)", axis)
        idx = axis - 1
        m = self.m[idx]
        return m.curr_pos

    def PreStartAll(self):
        self.motions = {}

    def PreStartOne(self, axis, pos):
        return True

    def StartOne(self, axis, pos):
        idx = axis - 1
        self.motions[self.m[idx]] = pos

    def StartAll(self):
        for motion, pos in self.motions.items():
            motion.curr_pos = pos

    def AbortOne(self, axis):
        pass


class DiscreteDummyMotorController(BasicDummyMotorController):
    """This class represents a discrete, dummy Sardana motor controller."""

    def __init__(self, inst, props, *args, **kwargs):
        BasicDummyMotorController.__init__(self, inst, props, *args, **kwargs)

    def GetAxisAttributes(self, axis):
        axis_attrs = MotorController.GetAxisAttributes(self, axis)
        new_axis_attrs = dict(Position=axis_attrs['Position'])
        new_axis_attrs['Position'][Type] = int
        return new_axis_attrs

    def AddDevice(self, axis):
        BasicDummyMotorController.AddDevice(self, axis)
        idx = axis - 1
        m = self.m[idx]
        m.setMinVelocity(0)
        m.setMaxVelocity(1)
        m.setAccelerationTime(0.01)
        m.setDecelerationTime(0.01)
        m.setCurrentPosition(0)

    def ReadOne(self, axis):
        pos = BasicDummyMotorController.ReadOne(self, axis)
        return int(pos)

    
class DummyMotorController(BasicDummyMotorController):
    """This class represents a dummy Sardana motor controller."""

    ctrl_features = []

    model = "Best"

    ctrl_attributes = {
        'LowerLimitSwitch' : { Type : float,
                               Description : 'lower limit switch position',
                               FGet : 'getLowerLimitSwitch',
                               FSet : 'setLowerLimitSwitch',
                               DefaultValue: -9999.9999, },
        'UpperLimitSwitch' : { Type : float,
                               Description : 'upper limit switch position',
                               DefaultValue: 8888.8888 }
    }

    axis_attributes = {
        'LowerLimitSwitch' : { Type : float,
                               Description : 'lower limit switch position',
                               FGet : 'getLLS',
                               FSet : 'setLLS',
                               DefaultValue: -9999.9999 },
        'UpperLimitSwitch' : { Type : float,
                               Description : 'upper limit switch position',
                               FGet : 'getULS',
                               FSet : 'setULS',
                               DefaultValue: 8888.8888 },
        'Power'            : { Type : bool,
                               Description : 'motor power',
                               FGet : 'getPower',
                               FSet : 'setPower',
                               DefaultValue: True },
    }

    ctrl_properties = {
        'Prop1' : { Type : str,
                    Description  : 'demo property 1',
                    DefaultValue : 'test property 1'},
        'Prop2' : { Type : int,
                    Description  : 'demo property 1',
                    DefaultValue : 531},
    }

    def __init__(self, inst, props, *args, **kwargs):
        BasicDummyMotorController.__init__(self, inst, props, *args, **kwargs)
        self._lowerLS = float("-inf")
        self._upperLS = float("+inf")

    def GetAxisAttributes(self, axis):
        return MotorController.GetAxisAttributes(self, axis)

    def SetAxisPar(self, axis, name, value):
        idx = axis - 1
        m = self.m[idx]
        name = name.lower()
        if name == "acceleration":
            m.setAccelerationTime(value)
        elif name == "deceleration":
            m.setDecelerationTime(value)
        elif name == "base_rate":
            m.setMinVelocity(value)
        elif name == "velocity":
            m.setMaxVelocity(value)
        elif name == "step_per_unit":
            m.setStepPerUnit(value)

    def GetAxisPar(self, axis, name):
        idx = axis - 1
        m = self.m[idx]
        name = name.lower()
        if name == "acceleration":
            v = m.getAccelerationTime()
        elif name == "deceleration":
            v = m.getDecelerationTime()
        elif name == "base_rate":
            v = m.getMinVelocity()
        elif name == "velocity":
            v = m.getMaxVelocity()
        elif name == "step_per_unit":
            v = m.getStepPerUnit()
        return v

    def DefinePosition(self, axis, position):
        idx = axis - 1
        m = self.m[idx]
        m.offset = position - m.getCurrentUserPosition()
        m.setCurrentUserPosition(position)

    def getLowerLimitSwitch(self):
        return self._lowerLS

    def setLowerLimitSwitch(self, value):
        self._lowerLS = value

    def getUpperLimitSwitch(self):
        return self._upperLS

    def setUpperLimitSwitch(self, value):
        self._upperLS = value

    def getLLS(self, axis):
        return self.m[axis - 1].getLowerLimitSwitch()

    def setLLS(self, axis, ls):
        self.m[axis - 1].setLowerLimitSwitch(ls)

    def getULS(self, axis):
        return self.m[axis - 1].getUpperLimitSwitch()

    def setULS(self, axis, ls):
        self.m[axis - 1].setUpperLimitSwitch(ls)

    def getPower(self, axis):
        return self.m[axis - 1].hasPower()

    def setPower(self, axis, power):
        self.m[axis - 1].setPower(power)