Open Core Interface - MLPI
MLPI-MotionLogicProgrammingInterface(mlpiCore)  1.26.2
mlpiMotionHelper.h
Go to the documentation of this file.
1 #ifndef __MLPIMOTIONHELPER_H__
2 #define __MLPIMOTIONHELPER_H__
3 
4 // -----------------------------------------------------------------------
5 // MLPI - <mlpiMotionHelper.h>
6 // -----------------------------------------------------------------------
7 // Copyright (c) 2013 Bosch Rexroth. All rights reserved.
8 // Redistribution and use in source and binary forms of this MLPI software
9 // (SW) provided to you, with or without modification, are permitted
10 // without prior approval provided that the following conditions are met:
11 //
12 // 1. Redistributions of source code of SW must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // 2. Redistributions in binary form of SW must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the distribution.
18 //
19 // 3. User recognizes and acknowledges that it acquires no right,
20 // title or interest in or to any of the names or trademarks used in
21 // connection with the SW ("names") by virtue of this License and waives
22 // any right to or interest in the names. User recognizes and acknowledges
23 // that names of companies or names or products of companies displayed
24 // in the documentation of SW to indicate the interoperability of products
25 // with the SW are the names of their respective owners. The use of such
26 // names in the documentation of SW does not imply any sponsorship,
27 // approval, or endorsement by such companies of this product.
28 //
29 // 4. Modified code versions, i.e. any addition to or deletion from
30 // the substance or structure of the original code of the SW running
31 // the MLPI must be plainly marked as such and must not be misrepresented
32 // as being original SW.
33 //
34 // 5. The SW may only be used in connection with a Bosch Rexroth product.
35 //
36 // THIS INFORMATION IS PROVIDED BY BOSCH REXROTH CORPORATION "AS IS"
37 // AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING
38 // (BUT NOTLIMITED TO) ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
39 // FITNESS FOR ANY PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WHILE THE
40 // INFORMATION PROVIDED IS BELIEVED TO BE ACCURATE, IT MAY INCLUDE
41 // ERRORS OR INACCURACIES.
42 // SUBJECT TO COMPULSORY STATUTORY PROVISIONS OF THE GERMAN LAW AS
43 // THE APPLICABLE LAW FOR THIS LICENSE BOSCH REXROTH CORPORATION WILL
44 // NOT BE LIABLE FOR ANY DAMAGES OF ANY KIND ARISING FROM THE USE OF
45 // THE SOFTWARE DISTRIBUTED HEREUNDER, INCLUDING BUT NOT LIMITED TO
46 // DIRECT, INDIRECT, INCIDENTAL, PUNITIVE, AND CONSEQUENTIAL DAMAGES.
47 // -----------------------------------------------------------------------
48 //
58 //
59 // -----------------------------------------------------------------------
60 
61 
62 
76 
77 
78 
79 // -----------------------------------------------------------------------
80 // GLOBAL INCLUDES
81 // -----------------------------------------------------------------------
82 #include "targetinfo.h"
83 
84 #if defined (TARGET_OS_VXWORKS)
85 #include <taskLib.h>
86 #elif defined (TARGET_OS_WINNT)
87 #include <windows.h>
88 #elif defined (TARGET_OS_WINCE32)
89 // compiling under WindowsCE 32bit environment
90 #elif defined (TARGET_OS_APPLE)
91 #include <unistd.h>
92 #elif defined (TARGET_OS_ANDROID)
93 #include <unistd.h>
94 #elif defined (TARGET_OS_LINUX)
95 #include <unistd.h>
96 #else
97 #pragma warning "unknown operating system"
98 #endif
99 
100 #include "mlpiGlobal.h"
101 #include "wchar16.h"
102 
103 #include "mlpiApiLib.h"
104 #include "mlpiMotionLib.h"
105 
106 // -----------------------------------------------------------------------
107 // GLOBAL MACROS
108 // -----------------------------------------------------------------------
109 #define MLPI_MOTION_BIT_ACCESS(name, bit) bool name() const {return (_value & (1<<bit)) ? true : false;}
110 
111 // -----------------------------------------------------------------------
112 // GLOBAL CONSTANTS
113 // -----------------------------------------------------------------------
114 
123 typedef enum MlpiAxisCondition
124 {
128 
132 
135 
137 
142 
143 typedef enum MlpiDirections
144 {
145  MLPI_DIRECTION_SHORTEST_WAY = 0,
146  MLPI_DIRECTION_POSITIVE = 1,
147  MLPI_DIRECTION_NEGATIVE = 2
148 }MlpiDirections;
149 
150 typedef enum MlpiScalingType
151 {
152  MLPI_SCALING_TYPE_TRANSLATORY_METER = 0,
153  MLPI_SCALING_TYPE_TRANSLATORY_INCH = 1,
154  MLPI_SCALING_TYPE_ROTATORY = 2,
155  MLPI_SCALING_TYPE_PERCENTAGE = 3,
156  MLPI_SCALING_TYPE_INVALID = 255
157 }MlpiScalingType;
158 
159 typedef enum MlpiScalingDataReference
160 {
161  MLPI_SCALING_REFERENCE_MOTOR_SHAFT = 0,
162  MLPI_SCALING_REFERENCE_LOAD = 1,
163  MLPI_SCALING_REFERENCE_INVALID = 255
164 }MlpiScalingDataReference;
165 
166 typedef enum MlpiScalingFormat
167 {
168  MLPI_SCALING_FORMAT_ABSOLUTE = 0,
169  MLPI_SCALING_FORMAT_MODULO = 1,
170  MLPI_SCALING_FORMAT_INVALID = 255
171 }MlpiScalingFormat;
172 
173 typedef enum MlpiScalingMode
174 {
175  MLPI_SCALING_MODE_PREFERENCE = 0,
176  MLPI_SCALING_MODE_PARAMETER = 1,
177  MLPI_SCALING_MODE_INVALID = 255
178 }MlpiScalingMode;
179 
180 typedef enum MlpiTimeUnit
181 {
182  MLPI_SCALING_TIME_MINUTE = 0,
183  MLPI_SCALING_TIME_SECOND = 1,
184  MLPI_SCALING_TIME_INVALID = 255
185 }MlpiTimeUnit;
186 
187 typedef enum MlpiTorqueUnit
188 {
189  MLPI_SCALING_TORQUE_NEWTON = 0,
190  MLPI_SCALING_TORQUE_POUND_FORCE = 1,
191  MLPI_SCALING_TORQUE_NEWTONMETER = 2,
192  MLPI_SCALING_TORQUE_INCH_POUND_FORCE = 3,
193  MLPI_SCALING_TORQUE_INVALID = 255
194 }MlpiTorqueUnit;
195 
196 
197 
198 // -----------------------------------------------------------------------
199 // GLOBAL TYPEDEFS
200 // -----------------------------------------------------------------------
201 
207 typedef struct MlpiAxisStateDecoder
208 {
209 public:
211  : _value(0) {
212  }
213 
214  MlpiAxisStateDecoder(const ULONG state)
215  : _value(state) {
216  }
217 
218  operator ULONG() const {
219  return _value;
220  }
221 
222  MLPI_MOTION_BIT_ACCESS(CamTab_0, 0);
223  MLPI_MOTION_BIT_ACCESS(CamTab_1, 1);
224  MLPI_MOTION_BIT_ACCESS(CamTab_2, 2);
225  ULONG CamTab() const {return _value&0x7;};
226  MLPI_MOTION_BIT_ACCESS(CamSwitching, 3);
227  MLPI_MOTION_BIT_ACCESS(InVelocity, 4);
228  MLPI_MOTION_BIT_ACCESS(Standstill, 5);
229  MLPI_MOTION_BIT_ACCESS(InPosition, 6);
230  MLPI_MOTION_BIT_ACCESS(InSynchron, 7);
231  MLPI_MOTION_BIT_ACCESS(Warning, 8);
232  MLPI_MOTION_BIT_ACCESS(Error, 9);
233  MLPI_MOTION_BIT_ACCESS(Homed, 10);
234  MLPI_MOTION_BIT_ACCESS(InTorque, 11);
235  MLPI_MOTION_BIT_ACCESS(OperationMode, 12);
236  MLPI_MOTION_BIT_ACCESS(Inbb, 13);
237  MLPI_MOTION_BIT_ACCESS(InAb, 14);
238  MLPI_MOTION_BIT_ACCESS(Power, 15);
239  MLPI_MOTION_BIT_ACCESS(CmdActive, 16);
240  MLPI_MOTION_BIT_ACCESS(ErrInProgress, 17);
241  MLPI_MOTION_BIT_ACCESS(CyclicPosChannelActive, 18);
242  MLPI_MOTION_BIT_ACCESS(InMasterPhaseOffset, 19);
243  MLPI_MOTION_BIT_ACCESS(CyclicTrqChannelActive, 20);
244  MLPI_MOTION_BIT_ACCESS(CyclicVelChannelActive, 21);
245  MLPI_MOTION_BIT_ACCESS(CyclicAnaChannelActive, 22);
246  MLPI_MOTION_BIT_ACCESS(NRTActive, 23);
247  MLPI_MOTION_BIT_ACCESS(Interrupted, 24);
248  MLPI_MOTION_BIT_ACCESS(Modulo, 28);
249  MLPI_MOTION_BIT_ACCESS(Rotatory, 29);
250  MLPI_MOTION_BIT_ACCESS(Valid, 30);
251  MLPI_MOTION_BIT_ACCESS(Decoupled, 31);
252 
253 private:
254  ULONG _value;
256 
257 
264 {
265 public:
267  : _value(0) {
268  }
269 
271  : _value(state) {
272  }
273 
274  operator ULONG() const {
275  return _value;
276  }
277 
278  MLPI_MOTION_BIT_ACCESS(ErrorStop, 0);
279  MLPI_MOTION_BIT_ACCESS(Stopping, 1);
280  MLPI_MOTION_BIT_ACCESS(Homing, 2);
281  MLPI_MOTION_BIT_ACCESS(PowerOn, 3);
282  MLPI_MOTION_BIT_ACCESS(DiscreteMotion, 4);
283  MLPI_MOTION_BIT_ACCESS(ContinuousMotion, 5);
284  MLPI_MOTION_BIT_ACCESS(SynchronizedMotion, 6);
285  MLPI_MOTION_BIT_ACCESS(Standstill, 7);
286  MLPI_MOTION_BIT_ACCESS(CoordinatedMotion, 8);
287 
288 private:
289  const ULONG _value;
291 
292 
293 
299 typedef struct MlpiAxisTypeDecoder
300 {
301 public:
303  : _value(0) {
304  }
305 
306  MlpiAxisTypeDecoder(const USHORT type)
307  : _value(type) {
308  }
309 
310  operator USHORT() const {
311  return _value;
312  }
313 
314  MLPI_MOTION_BIT_ACCESS(InterpolationInControl, 0);
315  MLPI_MOTION_BIT_ACCESS(IsPackProfile, 1);
316  MLPI_MOTION_BIT_ACCESS(IsHydraulicDrive, 2);
317  MLPI_MOTION_BIT_ACCESS(SupportsParametrization, 15);
318  MlpiAxisType Type() const {
319  switch (_value & 0xF8) {
320  case (1<<3): return MLPI_AXISTYPE_REAL;
321  case (1<<4): return MLPI_AXISTYPE_VIRTUAL;
322  case (1<<5): return MLPI_AXISTYPE_ENCODER;
323  case (1<<6): return MLPI_AXISTYPE_LINK;
324  case (1<<7): return MLPI_AXISTYPE_CONTROLLER;
325  }
326  return MLPI_AXISTYPE_VIRTUAL;
327  }
328 private:
329  USHORT _value;
331 
336 typedef struct MlpiAxisConditionDecoder
337 {
338 public:
340  : _value(0) {
341  }
342 
343  MlpiAxisConditionDecoder(const ULONG condition)
344  : _value(condition) {
345  }
346 
347  operator ULONG() const {
348  return _value;
349  }
350 
351  MlpiAxisCondition Condition() const {
352  return static_cast<MlpiAxisCondition>(_value);
353  }
354 
355  bool IsActive() const {
356  switch (_value) {
361  return true;
362  }
363  return false;
364  }
365 
366  bool IsParking() const {
367  switch (_value) {
372  return true;
373  }
374  return false;
375  }
376 
377  bool IsDeactivated() const {
378  switch (_value) {
383  return true;
384  }
385  return false;
386  }
387 
388  bool IsDecoupled() const {
389  switch (_value) {
396  return true;
397  }
398  return false;
399  }
400 
401  bool IsParametrization() const {
402  switch (_value) {
409  return true;
410  }
411  return false;
412  }
413 
414 private:
415  ULONG _value;
417 
418 
426 {
427 public:
429  : _value(0) {
430  }
431 
432  MlpiAxisScalingPosition(const USHORT scaling)
433  : _value(scaling) {
434  }
435 
436  MlpiAxisScalingPosition(const MlpiScalingType type, const MlpiScalingFormat format,
437  const MlpiScalingDataReference dataReference = MLPI_SCALING_REFERENCE_LOAD,
438  const MlpiScalingMode mode = MLPI_SCALING_MODE_PREFERENCE) {
439  _value = 0;
440  switch (type)
441  {
442  case MLPI_SCALING_TYPE_TRANSLATORY_METER:
443  _value |= 0x01;
444  break;
445  case MLPI_SCALING_TYPE_TRANSLATORY_INCH:
446  _value |= 0x11;
447  break;
448  case MLPI_SCALING_TYPE_ROTATORY:
449  _value |= 0x02;
450  break;
451  default:
452  break;
453  }
454  switch (format)
455  {
456  case MLPI_SCALING_FORMAT_ABSOLUTE:
457  _value |= 0x00;
458  break;
459  case MLPI_SCALING_FORMAT_MODULO:
460  _value |= 0x80;
461  break;
462  default:
463  break;
464  }
465 
466  switch (dataReference)
467  {
468  case MLPI_SCALING_REFERENCE_MOTOR_SHAFT:
469  break;
470  case MLPI_SCALING_REFERENCE_LOAD:
471  _value |= 0x40;
472  break;
473  default:
474  break;
475  }
476 
477  switch (mode)
478  {
479  case MLPI_SCALING_MODE_PREFERENCE:
480  break;
481  case MLPI_SCALING_MODE_PARAMETER:
482  _value |= 0x08;
483  break;
484  default:
485  break;
486  }
487  }
488 
489  MlpiScalingType getType() const
490  {
491  switch (_value & 0x13)
492  {
493  case 0x01:
494  return MLPI_SCALING_TYPE_TRANSLATORY_METER;
495  case 0x11:
496  return MLPI_SCALING_TYPE_TRANSLATORY_INCH;
497  case 0x02:
498  return MLPI_SCALING_TYPE_ROTATORY;
499  default:
500  return MLPI_SCALING_TYPE_INVALID;
501  }
502  }
503 
504  const WCHAR16* getTypeString() const
505  {
506  switch (_value & 0x13)
507  {
508  case 0x01 :
509  return L"translatory in mm";
510  case 0x11:
511  return L"translatory in inch";
512  case 0x02:
513  return L"rotatory";
514  default:
515  return L"";
516  }
517  }
518 
519  MlpiScalingFormat getFormat() const
520  {
521  switch (_value & 0x80)
522  {
523  case 0x00 :
524  return MLPI_SCALING_FORMAT_ABSOLUTE;
525  case 0x80:
526  return MLPI_SCALING_FORMAT_MODULO;
527  default:
528  return MLPI_SCALING_FORMAT_INVALID;
529  }
530  }
531 
532  const WCHAR16* getFormatString() const
533  {
534  switch (_value & 0x80)
535  {
536  case 0x00 :
537  return L"absolute";
538  case 0x80:
539  return L"modulo";
540  default:
541  return L"";
542  }
543  }
544 
545  MlpiScalingDataReference getReference() const
546  {
547  switch (_value & 0x40)
548  {
549  case 0x00 :
550  return MLPI_SCALING_REFERENCE_MOTOR_SHAFT;
551  case 0x40:
552  return MLPI_SCALING_REFERENCE_LOAD;
553  default:
554  return MLPI_SCALING_REFERENCE_INVALID;
555  }
556  }
557 
558  const WCHAR16* getReferenceString() const
559  {
560  switch (_value & 0x40)
561  {
562  case 0x00 :
563  return L"with motor shaft reference";
564  case 0x40:
565  return L"with load reference";
566  default:
567  return L"";
568  }
569  }
570 
571  MlpiScalingMode getMode() const
572  {
573  switch (_value & 0x08)
574  {
575  case 0x00 :
576  return MLPI_SCALING_MODE_PREFERENCE;
577  case 0x08:
578  return MLPI_SCALING_MODE_PARAMETER;
579  default:
580  return MLPI_SCALING_MODE_INVALID;
581  }
582  }
583 
584  const WCHAR16* getModeString() const
585  {
586  switch (_value & 0x08)
587  {
588  case 0x00 :
589  return L"in preference mode";
590  case 0x08:
591  return L"parameter mode";
592  default:
593  return L"";
594  }
595  }
596 
597  operator USHORT() const {
598  return _value;
599  }
600 
601  operator USHORT*() {
602  return &_value;
603  }
604 
605 private:
606  USHORT _value;
608 
609 
610 
618 {
619 public:
621  : _value(0) {
622  }
623 
624  MlpiAxisScalingVelocity(const USHORT scaling)
625  : _value(scaling) {
626  }
627 
628  MlpiAxisScalingVelocity(const MlpiScalingType type, const MlpiTimeUnit time,
629  const MlpiScalingDataReference dataReference = MLPI_SCALING_REFERENCE_LOAD, const MlpiScalingMode mode = MLPI_SCALING_MODE_PREFERENCE) {
630  _value = 0;
631  switch (type)
632  {
633  case MLPI_SCALING_TYPE_TRANSLATORY_METER:
634  _value |= 0x01;
635  break;
636  case MLPI_SCALING_TYPE_TRANSLATORY_INCH:
637  _value |= 0x11;
638  break;
639  case MLPI_SCALING_TYPE_ROTATORY:
640  _value |= 0x02;
641  break;
642  default:
643  break;
644  }
645  switch (time)
646  {
647  case MLPI_SCALING_TIME_MINUTE:
648  _value |= 0x00;
649  break;
650  case MLPI_SCALING_TIME_SECOND:
651  _value |= 0x20;
652  break;
653  default:
654  break;
655  }
656 
657  switch (dataReference)
658  {
659  case MLPI_SCALING_REFERENCE_MOTOR_SHAFT:
660  break;
661  case MLPI_SCALING_REFERENCE_LOAD:
662  _value |= 0x40;
663  break;
664  default:
665  break;
666  }
667 
668  switch (mode)
669  {
670  case MLPI_SCALING_MODE_PREFERENCE:
671  break;
672  case MLPI_SCALING_MODE_PARAMETER:
673  _value |= 0x08;
674  break;
675  default:
676  break;
677  }
678  }
679 
680  MlpiScalingType getType() const
681  {
682  switch (_value & 0x13)
683  {
684  case 0x01 :
685  return MLPI_SCALING_TYPE_TRANSLATORY_METER;
686  case 0x11:
687  return MLPI_SCALING_TYPE_TRANSLATORY_INCH;
688  case 0x02:
689  return MLPI_SCALING_TYPE_ROTATORY;
690  default:
691  return MLPI_SCALING_TYPE_INVALID;
692  }
693  }
694 
695  const WCHAR16* getTypeString() const
696  {
697  switch (_value & 0x13)
698  {
699  case 0x01 :
700  return L"translatory in mm";
701  case 0x11:
702  return L"translatory in inch";
703  case 0x02:
704  return L"rotatory";
705  default:
706  return L"";
707  }
708  }
709 
710  MlpiTimeUnit getTime() const
711  {
712  switch (_value & 0x20)
713  {
714  case 0x00 :
715  return MLPI_SCALING_TIME_MINUTE;
716  case 0x20:
717  return MLPI_SCALING_TIME_SECOND;
718  default:
719  return MLPI_SCALING_TIME_INVALID;
720  }
721  }
722 
723  const WCHAR16* getTimeString() const
724  {
725  switch (_value & 0x20)
726  {
727  case 0x00 :
728  return L"in minute";
729  case 0x20:
730  return L"in second";
731  default:
732  return L"";
733  }
734  }
735 
736  MlpiScalingDataReference getReference() const
737  {
738  switch (_value & 0x40)
739  {
740  case 0x00 :
741  return MLPI_SCALING_REFERENCE_MOTOR_SHAFT;
742  case 0x40:
743  return MLPI_SCALING_REFERENCE_LOAD;
744  default:
745  return MLPI_SCALING_REFERENCE_INVALID;
746  }
747  }
748 
749  const WCHAR16* getReferenceString() const
750  {
751  switch (_value & 0x40)
752  {
753  case 0x00 :
754  return L"with motor shaft reference";
755  case 0x40:
756  return L"with load reference";
757  default:
758  return L"";
759  }
760  }
761 
762  MlpiScalingMode getMode() const
763  {
764  switch (_value & 0x08)
765  {
766  case 0x00 :
767  return MLPI_SCALING_MODE_PREFERENCE;
768  case 0x08:
769  return MLPI_SCALING_MODE_PARAMETER;
770  default:
771  return MLPI_SCALING_MODE_INVALID;
772  }
773  }
774 
775  const WCHAR16* getModeString() const
776  {
777  switch (_value & 0x08)
778  {
779  case 0x00 :
780  return L"in preference mode";
781  case 0x08:
782  return L"parameter mode";
783  default:
784  return L"";
785  }
786  }
787 
788  operator USHORT() const {
789  return _value;
790  }
791 
792  operator USHORT*() {
793  return &_value;
794  }
795 
796 private:
797  USHORT _value;
799 
800 
801 
809 {
810 public:
812  : _value(0) {
813  }
814 
815  MlpiAxisScalingAcceleration(const USHORT scaling)
816  : _value(scaling) {
817  }
818 
819  MlpiAxisScalingAcceleration(const MlpiScalingType type,
820  const MlpiScalingDataReference dataReference = MLPI_SCALING_REFERENCE_LOAD, const MlpiScalingMode mode = MLPI_SCALING_MODE_PREFERENCE) {
821  _value = 0;
822  switch (type)
823  {
824  case MLPI_SCALING_TYPE_TRANSLATORY_METER:
825  _value |= 0x01;
826  break;
827  case MLPI_SCALING_TYPE_TRANSLATORY_INCH:
828  _value |= 0x11;
829  break;
830  case MLPI_SCALING_TYPE_ROTATORY:
831  _value |= 0x02;
832  break;
833  default:
834  break;
835  }
836 
837  switch (dataReference)
838  {
839  case MLPI_SCALING_REFERENCE_MOTOR_SHAFT:
840  break;
841  case MLPI_SCALING_REFERENCE_LOAD:
842  _value |= 0x40;
843  break;
844  default:
845  break;
846  }
847 
848  switch (mode)
849  {
850  case MLPI_SCALING_MODE_PREFERENCE:
851  break;
852  case MLPI_SCALING_MODE_PARAMETER:
853  _value |= 0x08;
854  break;
855  default:
856  break;
857  }
858  }
859 
860  MlpiScalingType getType() const
861  {
862  switch (_value & 0x13)
863  {
864  case 0x01:
865  return MLPI_SCALING_TYPE_TRANSLATORY_METER;
866  case 0x11:
867  return MLPI_SCALING_TYPE_TRANSLATORY_INCH;
868  case 0x02:
869  return MLPI_SCALING_TYPE_ROTATORY;
870  default:
871  return MLPI_SCALING_TYPE_INVALID;
872  }
873  }
874 
875  const WCHAR16* getTypeString() const
876  {
877  switch (_value & 0x13)
878  {
879  case 0x01:
880  return L"translatory axis in mm";
881  case 0x11:
882  return L"translatory in inch";
883  case 0x02:
884  return L"rotatory";
885  default:
886  return L"";
887  }
888  }
889 
890  MlpiScalingDataReference getReference() const
891  {
892  switch (_value & 0x40)
893  {
894  case 0x00:
895  return MLPI_SCALING_REFERENCE_MOTOR_SHAFT;
896  case 0x40:
897  return MLPI_SCALING_REFERENCE_LOAD;
898  default:
899  return MLPI_SCALING_REFERENCE_INVALID;
900  }
901  }
902 
903  const WCHAR16* getReferenceString() const
904  {
905  switch (_value & 0x40)
906  {
907  case 0x00:
908  return L"with motor shaft reference";
909  case 0x40:
910  return L"with load reference";
911  default:
912  return L"";
913  }
914  }
915 
916  MlpiScalingMode getMode() const
917  {
918  switch (_value & 0x08)
919  {
920  case 0x00:
921  return MLPI_SCALING_MODE_PREFERENCE;
922  case 0x08:
923  return MLPI_SCALING_MODE_PARAMETER;
924  default:
925  return MLPI_SCALING_MODE_INVALID;
926  }
927  }
928 
929  const WCHAR16* getModeString() const
930  {
931  switch (_value & 0x08)
932  {
933  case 0x00 :
934  return L"in preference mode";
935  case 0x08:
936  return L"parameter mode";
937  default:
938  return L"";
939  }
940  }
941 
942  operator USHORT() const {
943  return _value;
944  }
945 
946  operator USHORT*() {
947  return &_value;
948  }
949 
950 private:
951  USHORT _value;
953 
954 
955 
962 typedef struct MlpiAxisScalingTorque
963 {
964 public:
966  : _value(0) {
967  }
968 
969  MlpiAxisScalingTorque(const USHORT scaling)
970  : _value(scaling) {
971  }
972 
973  MlpiAxisScalingTorque(const MlpiScalingType type,
974  const MlpiScalingDataReference dataReference = MLPI_SCALING_REFERENCE_LOAD, const MlpiScalingMode mode = MLPI_SCALING_MODE_PREFERENCE) {
975  _value = 0;
976  switch (type)
977  {
978  case MLPI_SCALING_TYPE_PERCENTAGE:
979  _value |= 0x00;
980  break;
981  case MLPI_SCALING_TYPE_TRANSLATORY_METER:
982  _value |= 0x01;
983  break;
984  case MLPI_SCALING_TYPE_TRANSLATORY_INCH:
985  _value |= 0x11;
986  break;
987  case MLPI_SCALING_TYPE_ROTATORY:
988  _value |= 0x02;
989  break;
990  default:
991  break;
992  }
993 
994  switch (dataReference)
995  {
996  case MLPI_SCALING_REFERENCE_MOTOR_SHAFT:
997  break;
998  case MLPI_SCALING_REFERENCE_LOAD:
999  _value |= 0x40;
1000  break;
1001  default:
1002  break;
1003  }
1004 
1005  switch (mode)
1006  {
1007  case MLPI_SCALING_MODE_PREFERENCE:
1008  break;
1009  case MLPI_SCALING_MODE_PARAMETER:
1010  _value |= 0x08;
1011  break;
1012  default:
1013  break;
1014  }
1015  }
1016 
1017  MlpiScalingType getType() const
1018  {
1019  switch (_value & 0x13)
1020  {
1021  case 0x00:
1022  return MLPI_SCALING_TYPE_PERCENTAGE;
1023  case 0x01:
1024  return MLPI_SCALING_TYPE_TRANSLATORY_METER;
1025  case 0x11:
1026  return MLPI_SCALING_TYPE_TRANSLATORY_INCH;
1027  case 0x02:
1028  return MLPI_SCALING_TYPE_ROTATORY;
1029  default:
1030  return MLPI_SCALING_TYPE_INVALID;
1031  }
1032  }
1033 
1034  const WCHAR16* getTypeString() const
1035  {
1036  switch (_value & 0x13)
1037  {
1038  case 0x00:
1039  return L"percentage";
1040  case 0x01:
1041  return L"newton";
1042  case 0x11:
1043  return L"pound-force";
1044  case 0x02:
1045  return L"newton meter";
1046  case 0x12:
1047  return L"inch pound-force";
1048  default:
1049  return L"";
1050  }
1051  }
1052 
1053  MlpiScalingDataReference getReference() const
1054  {
1055  switch (_value & 0x40)
1056  {
1057  case 0x00:
1058  return MLPI_SCALING_REFERENCE_MOTOR_SHAFT;
1059  case 0x40:
1060  return MLPI_SCALING_REFERENCE_LOAD;
1061  default:
1062  return MLPI_SCALING_REFERENCE_INVALID;
1063  }
1064  }
1065 
1066  const WCHAR16* getReferenceString() const
1067  {
1068  switch (_value & 0x40)
1069  {
1070  case 0x00:
1071  return L"with motor shaft reference";
1072  case 0x40:
1073  return L"with load reference";
1074  default:
1075  return L"";
1076  }
1077  }
1078 
1079  MlpiScalingMode getMode() const
1080  {
1081  switch (_value & 0x08)
1082  {
1083  case 0x00:
1084  return MLPI_SCALING_MODE_PREFERENCE;
1085  case 0x08:
1086  return MLPI_SCALING_MODE_PARAMETER;
1087  default:
1088  return MLPI_SCALING_MODE_INVALID;
1089  }
1090  }
1091 
1092  const WCHAR16* getModeString() const
1093  {
1094  switch (_value & 0x08)
1095  {
1096  case 0x00 :
1097  return L"in preference mode";
1098  case 0x08:
1099  return L"parameter mode";
1100  default:
1101  return L"";
1102  }
1103  }
1104 
1105  operator USHORT() const {
1106  return _value;
1107  }
1108 
1109  operator USHORT*() {
1110  return &_value;
1111  }
1112 
1113 private:
1114  USHORT _value;
1116 
1117 
1118 // -----------------------------------------------------------------------
1119 // GLOBAL EXPORTS
1120 // -----------------------------------------------------------------------
1121 
1122 
1135 inline MLPIRESULT utilMotionWait(MLPIHANDLE connection, MlpiAxisRef axis, MLPIMOTIONHANDLE motionHandle, ULONG timeout=MLPI_INFINITE)
1136 {
1137  const ULONG REFRESH_TIME = 100;
1138  MlpiMotionStatus status;
1139  memset(&status, 0, sizeof(MlpiMotionStatus));
1140 
1141  ULONG timeGone = 0;
1142 
1143  MLPIRESULT result = MLPI_S_OK;
1144 
1145  if(0 == motionHandle)
1146  return result;
1147 
1148  // wait for complete
1149  result = mlpiMotionGetStatus(connection, axis, motionHandle, &status);
1150  while( !(status.done || status.error) && (timeout==MLPI_INFINITE || timeGone<timeout) )
1151  {
1152  #if defined (TARGET_OS_VXWORKS)
1153  taskDelay(REFRESH_TIME);
1154  #elif defined (TARGET_OS_WINNT)
1155  Sleep(REFRESH_TIME);
1156  #elif defined (TARGET_OS_WINCE32)
1157  Sleep(REFRESH_TIME);
1158  #elif defined (TARGET_OS_APPLE)
1159  usleep(REFRESH_TIME*1000);
1160  #elif defined (TARGET_OS_ANDROID)
1161  usleep(REFRESH_TIME*1000);
1162  #elif defined (TARGET_OS_LINUX)
1163  usleep(REFRESH_TIME*1000);
1164  #else
1165  #pragma warning "unknown operating system"
1166  #endif
1167 
1168  result = mlpiMotionGetStatus(connection, axis, motionHandle, &status);
1169  timeGone += REFRESH_TIME;
1170  }
1171 
1172  if(timeGone >= timeout)
1173  return MLPI_E_TIMEOUT;
1174 
1175  if (status.error)
1176  return status.additional1;
1177 
1178  return result;
1179 }
1180 
1181 
1189 {
1190  const ULONG REFRESH_TIME = 100;
1191  MLPIRESULT result = MLPI_S_OK;
1192  ULONG timeGone = 0;
1193 
1194  // wait for AxisInterrupted to be gone
1195  ULONG axisState = 0;
1196  result = mlpiMotionGetState(connection, axis, &axisState);
1197  MlpiAxisStateDecoder state = axisState;
1198  while(MLPI_SUCCEEDED(result) && state.Interrupted() && (timeout==MLPI_INFINITE || timeGone<timeout))
1199  {
1200  #if defined (TARGET_OS_VXWORKS)
1201  taskDelay(REFRESH_TIME);
1202  #elif defined (TARGET_OS_WINNT)
1203  Sleep(REFRESH_TIME);
1204  #elif defined (TARGET_OS_WINCE32)
1205  Sleep(REFRESH_TIME);
1206  #elif defined (TARGET_OS_APPLE)
1207  usleep(REFRESH_TIME*1000);
1208  #elif defined (TARGET_OS_ANDROID)
1209  usleep(REFRESH_TIME*1000);
1210  #elif defined (TARGET_OS_LINUX)
1211  usleep(REFRESH_TIME*1000);
1212  #else
1213  #pragma warning "unknown operating system"
1214  #endif
1215 
1216  result = mlpiMotionGetState(connection, axis, &axisState);
1217  state = MlpiAxisStateDecoder(axisState);
1218  timeGone += REFRESH_TIME;
1219  }
1220 
1221  if(timeGone >= timeout)
1222  return MLPI_E_TIMEOUT;
1223 
1224  return result;
1225 }
1226 
1227 
1228 #endif /* __MLPIMOTIONHELPER_H__ */
#define MLPI_S_OK
Return code "everything okay".
Definition: mlpiGlobal.h:363
Drive not in Ring; Setpoint calculation not active.
Drive in Ring; Setpoint calculation active.
struct MlpiAxisConditionDecoder MlpiAxisConditionDecoder
The following struct helps to decode the axis condition as given by mlpiMotionGetCondition.
An encoder that is attached to a real drive, no motion possible.
Drive in Ring; Setpoint calculation not active; No setpoint evaluation in drive.
MLPIRESULT mlpiMotionGetStatus(const MLPIHANDLE connection, const MlpiAxisRef axis, const MLPIMOTIONHANDLE motionHandle, MlpiMotionStatus *status)
This function reads the status of a motion command.
The following struct helps to decode the axis type as given by mlpiMotionGetAxisType.
Drive in Ring; Setpoint calculation not active.
An axis that can be used when generating your own controller to operate the drive.
unsigned short USHORT
2 byte unsigned integer
Definition: mlpiGlobal.h:162
struct MlpiAxisStateExtendedDecoder MlpiAxisStateExtendedDecoder
The following struct helps to decode the extended axis state as given by mlpiMotionGetAxisStateExtend...
MLPIRESULT mlpiMotionGetState(const MLPIHANDLE connection, const MlpiAxisRef axis, ULONG *value)
This function reads the state of an axis.
Drive not in Ring; Setpoint calculation not active; No setpoint evaluation in drive.
struct MlpiAxisTypeDecoder MlpiAxisTypeDecoder
The following struct helps to decode the axis type as given by mlpiMotionGetAxisType.
The following struct helps to decode the axis state as given by mlpiMotionGetAxisState or mlpiMotionG...
A link ring axis.
Drive in Ring; Setpoint calculation active; No setpoint evaluation in drive; axis in parameterization...
Drive in Ring; Setpoint calculation not active; axis in parameterization.
Drive in Ring; Setpoint calculation active; No setpoint evaluation in drive.
struct MlpiMotionStatus MlpiMotionStatus
This structure defines the status of a motion command.
wchar_t WCHAR16
UTF16 string.
Definition: mlpiGlobal.h:193
unsigned int ULONG
4 byte unsigned integer
Definition: mlpiGlobal.h:165
Drive in Ring; Setpoint calculation not active; No setpoint evaluation in drive; axis in parameteriza...
#define MLPI_SUCCEEDED(hr)
Returns true if given error code was successful.
Definition: mlpiGlobal.h:406
unsigned long long MLPIMOTIONHANDLE
MLPI-API handle value used for motion functions.
MLPI_MOTION_BIT_ACCESS(CamTab_0, 0)
Bit0 of active CAM table of CamIn command.
#define MLPI_E_TIMEOUT
Timeout during function call.
Definition: mlpiGlobal.h:368
The following struct helps to decode the extended axis state as given by mlpiMotionGetAxisStateExtend...
struct MlpiAxisScalingVelocity MlpiAxisScalingVelocity
The following struct helps to encode or decode the velocity scaling settings of the axis given or set...
Drive in Ring; Setpoint calculation active; axis in parameterization.
Drive not in Ring; Setpoint calculation not active; No setpoint evaluation in drive; axis in paramete...
The following struct helps to encode or decode the torque scaling settings of the axis given or set b...
Drive not in Ring; Setpoint calculation not active; axis in parameterization.
MLPIRESULT utilMotionWait(MLPIHANDLE connection, MlpiAxisRef axis, MLPIMOTIONHANDLE motionHandle, ULONG timeout=MLPI_INFINITE)
This function waits until a given motion command is done or an error occurs. An optional timeout can ...
MlpiAxisType
This enumeration defines the type of axis.
struct MlpiAxisScalingAcceleration MlpiAxisScalingAcceleration
The following struct helps to encode or decode the velocity scaling settings of the axis given or set...
The following struct helps to encode or decode the position scaling settings of the axis given or set...
struct MlpiAxisRef MlpiAxisRef
This structure defines the axis through the definition of control and axis number.
MlpiAxisCondition
This enumeration defines the state of an axis.
Virtual axis, no physical drive attached.
struct MlpiAxisScalingPosition MlpiAxisScalingPosition
The following struct helps to encode or decode the position scaling settings of the axis given or set...
unsigned long MLPIHANDLE
common MLPI-API handle value
Definition: mlpiGlobal.h:206
The following struct helps to encode or decode the velocity scaling settings of the axis given or set...
#define MLPI_INFINITE
Infinite timeout value.
Definition: mlpiApiLib.h:256
MLPIRESULT utilMotionWaitAxisInterrupted(MLPIHANDLE connection, MlpiAxisRef axis, const ULONG timeout=MLPI_INFINITE)
This function waits that the axis is no longer interrupted.
int MLPIRESULT
common MLPI-API return value
Definition: mlpiGlobal.h:198
Real axis, this is the common axis when doing motion.
struct MlpiAxisScalingTorque MlpiAxisScalingTorque
The following struct helps to encode or decode the torque scaling settings of the axis given or set b...
The following struct helps to encode or decode the velocity scaling settings of the axis given or set...