/
vpRobotAfma6.cpp
2303 lines (1827 loc) · 65.5 KB
/
vpRobotAfma6.cpp
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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
*
* ViSP, open source Visual Servoing Platform software.
* Copyright (C) 2005 - 2019 by Inria. All rights reserved.
*
* This software is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file LICENSE.txt at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using ViSP with software that can not be combined with the GNU
* GPL, please contact Inria about acquiring a ViSP Professional
* Edition License.
*
* See http://visp.inria.fr for more information.
*
* This software was developed at:
* Inria Rennes - Bretagne Atlantique
* Campus Universitaire de Beaulieu
* 35042 Rennes Cedex
* France
*
* If you have questions regarding the use of this file, please contact
* Inria at visp@inria.fr
*
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Description:
* Interface for the Irisa's Afma6 robot.
*
* Authors:
* Fabien Spindler
*
*****************************************************************************/
#include <visp3/core/vpConfig.h>
#ifdef VISP_HAVE_AFMA6
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <visp3/core/vpDebug.h>
#include <visp3/core/vpExponentialMap.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpRotationMatrix.h>
#include <visp3/core/vpThetaUVector.h>
#include <visp3/core/vpVelocityTwistMatrix.h>
#include <visp3/robot/vpRobotAfma6.h>
#include <visp3/robot/vpRobotException.h>
/* ---------------------------------------------------------------------- */
/* --- STATIC ----------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
bool vpRobotAfma6::robotAlreadyCreated = false;
/*!
Default positioning velocity in percentage of the maximum
velocity. This value is set to 15. The member function
setPositioningVelocity() allows to change this value.
*/
const double vpRobotAfma6::defaultPositioningVelocity = 15.0;
/* ---------------------------------------------------------------------- */
/* --- EMERGENCY STOP --------------------------------------------------- */
/* ---------------------------------------------------------------------- */
/*!
Emergency stops the robot if the program is interrupted by a SIGINT
(CTRL C), SIGSEGV (segmentation fault), SIGBUS (bus error), SIGKILL
or SIGQUIT signal.
*/
void emergencyStopAfma6(int signo)
{
std::cout << "Stop the Afma6 application by signal (" << signo << "): " << (char)7;
switch (signo) {
case SIGINT:
std::cout << "SIGINT (stop by ^C) " << std::endl;
break;
case SIGBUS:
std::cout << "SIGBUS (stop due to a bus error) " << std::endl;
break;
case SIGSEGV:
std::cout << "SIGSEGV (stop due to a segmentation fault) " << std::endl;
break;
case SIGKILL:
std::cout << "SIGKILL (stop by CTRL \\) " << std::endl;
break;
case SIGQUIT:
std::cout << "SIGQUIT " << std::endl;
break;
default:
std::cout << signo << std::endl;
}
// std::cout << "Emergency stop called\n";
// PrimitiveESTOP_Afma6();
PrimitiveSTOP_Afma6();
std::cout << "Robot was stopped\n";
// Free allocated resources
// ShutDownConnection(); // Some times cannot exit here when Ctrl-C
fprintf(stdout, "Application ");
fflush(stdout);
kill(getpid(), SIGKILL);
exit(1);
}
/* ---------------------------------------------------------------------- */
/* --- CONSTRUCTOR ------------------------------------------------------ */
/* ---------------------------------------------------------------------- */
/*!
The only available constructor.
This contructor calls init() to initialise
the connection with the MotionBox or low level controller, send the
default eMc homogeneous matrix, power on the robot and wait 1 sec
before returning to be sure the initialisation is done.
It also set the robot state to vpRobot::STATE_STOP.
To set the extrinsic camera parameters related to the eMc matrix
obtained with a camera perspective projection model including the
distorsion, use the code below:
\code
vpRobotAfma6 robot;
// Set the extrinsic camera parameters obtained with a perpective
// projection model including a distorsion parameter
robot.init(vpAfma6::TOOL_CCMOP,
vpCameraParameters::perspectiveProjWithDistortion); \endcode
Now, you can get the intrinsic camera parameters of the image I
acquired with the camera, with:
\code
vpCameraParameters cam;
robot.getCameraParameters(cam, I);
// In cam, you get the intrinsic parameters of the projection model
// with distorsion.
\endcode
\sa vpCameraParameters, init(vpAfma6::vpAfma6CameraRobotType,
vpCameraParameters::vpCameraParametersProjType)
*/
vpRobotAfma6::vpRobotAfma6(bool verbose) : vpAfma6(), vpRobot()
{
/*
#define SIGHUP 1 // hangup
#define SIGINT 2 // interrupt (rubout)
#define SIGQUIT 3 // quit (ASCII FS)
#define SIGILL 4 // illegal instruction (not reset when caught)
#define SIGTRAP 5 // trace trap (not reset when caught)
#define SIGIOT 6 // IOT instruction
#define SIGABRT 6 // used by abort, replace SIGIOT in the future
#define SIGEMT 7 // EMT instruction
#define SIGFPE 8 // floating point exception
#define SIGKILL 9 // kill (cannot be caught or ignored)
#define SIGBUS 10 // bus error
#define SIGSEGV 11 // segmentation violation
#define SIGSYS 12 // bad argument to system call
#define SIGPIPE 13 // write on a pipe with no one to read it
#define SIGALRM 14 // alarm clock
#define SIGTERM 15 // software termination signal from kill
*/
signal(SIGINT, emergencyStopAfma6);
signal(SIGBUS, emergencyStopAfma6);
signal(SIGSEGV, emergencyStopAfma6);
signal(SIGKILL, emergencyStopAfma6);
signal(SIGQUIT, emergencyStopAfma6);
setVerbose(verbose);
if (verbose_)
std::cout << "Open communication with MotionBlox.\n";
try {
this->init();
this->setRobotState(vpRobot::STATE_STOP);
} catch (...) {
// vpERROR_TRACE("Error caught") ;
throw;
}
positioningVelocity = defaultPositioningVelocity;
vpRobotAfma6::robotAlreadyCreated = true;
return;
}
/* ------------------------------------------------------------------------ */
/* --- INITIALISATION ----------------------------------------------------- */
/* ------------------------------------------------------------------------ */
/*!
Initialise the connection with the MotionBox or low level
controller, send the default eMc homogeneous matrix, power on the
robot and wait 1 sec before returning to be sure the initialisation
is done.
\warning This method sets the camera extrinsic parameters (matrix
eMc) to the one obtained by calibration with a camera projection
model without distorsion by calling
init(vpAfma6::defaultCameraRobot). If you want to set the extrinsic
camera parameters to those obtained with a camera perspective model
including the distorsion you have to call the
init(vpAfma6::vpAfma6CameraRobotType,
vpCameraParameters::vpCameraParametersProjType) method.
\sa vpCameraParameters, init(vpAfma6::vpAfma6CameraRobotType,
vpCameraParameters::vpCameraParametersProjType)
*/
void vpRobotAfma6::init(void)
{
InitTry;
// Initialise private variables used to compute the measured velocities
q_prev_getvel.resize(6);
q_prev_getvel = 0;
time_prev_getvel = 0;
first_time_getvel = true;
// Initialise private variables used to compute the measured displacement
q_prev_getdis.resize(6);
q_prev_getdis = 0;
first_time_getdis = true;
// Initialize the firewire connection
Try(InitializeConnection(verbose_));
// Connect to the servoboard using the servo board GUID
Try(InitializeNode_Afma6());
Try(PrimitiveRESET_Afma6());
// Update the eMc matrix in the low level controller
init(vpAfma6::defaultTool);
// Look if the power is on or off
UInt32 HIPowerStatus;
UInt32 EStopStatus;
Try(PrimitiveSTATUS_Afma6(NULL, NULL, &EStopStatus, NULL, NULL, NULL, &HIPowerStatus));
CAL_Wait(0.1);
// Print the robot status
if (verbose_) {
std::cout << "Robot status: ";
switch (EStopStatus) {
case ESTOP_AUTO:
case ESTOP_MANUAL:
if (HIPowerStatus == 0)
std::cout << "Power is OFF" << std::endl;
else
std::cout << "Power is ON" << std::endl;
break;
case ESTOP_ACTIVATED:
std::cout << "Emergency stop is activated" << std::endl;
break;
default:
std::cout << "Sorry there is an error on the emergency chain." << std::endl;
std::cout << "You have to call Adept for maintenance..." << std::endl;
// Free allocated resources
}
std::cout << std::endl;
}
// get real joint min/max from the MotionBlox
Try(PrimitiveJOINT_MINMAX_Afma6(_joint_min, _joint_max));
// for (unsigned int i=0; i < njoint; i++) {
// printf("axis %d: joint min %lf, max %lf\n", i, _joint_min[i],
// _joint_max[i]);
// }
// If an error occur in the low level controller, goto here
// CatchPrint();
Catch();
// Test if an error occurs
if (TryStt == -20001)
printf("No connection detected. Check if the robot is powered on \n"
"and if the firewire link exist between the MotionBlox and this "
"computer.\n");
else if (TryStt == -675)
printf(" Timeout enabling power...\n");
if (TryStt < 0) {
// Power off the robot
PrimitivePOWEROFF_Afma6();
// Free allocated resources
ShutDownConnection();
std::cout << "Cannot open connection with the motionblox..." << std::endl;
throw vpRobotException(vpRobotException::constructionError, "Cannot open connection with the motionblox");
}
return;
}
/*!
Initialize the robot kinematics with the extrinsic calibration
parameters associated to a specific camera (set the eMc homogeneous
parameters in the low level controller) and also get the joint
limits from the low-level controller.
The eMc parameters depend on the camera and the projection model in use.
\param tool : Tool to use.
\param projModel : Projection model associated to the camera.
To set the extrinsic camera parameters related to the eMc matrix
obtained with a camera perspective projection model including the
distorsion, use the code below:
\code
vpRobotAfma6 robot;
// Set the extrinsic camera parameters obtained with a perpective
// projection model including a distorsion parameter
robot.init(vpAfma6::TOOL_CCMOP,
vpCameraParameters::perspectiveProjWithDistortion); \endcode
Now, you can get the intrinsic camera parameters of the image \e I
acquired with the camera, with:
\code
vpCameraParameters cam;
robot.getCameraParameters(cam, I);
// In cam, you get the intrinsic parameters of the projection model
// with distorsion.
\endcode
\sa vpCameraParameters, init()
*/
void vpRobotAfma6::init(vpAfma6::vpAfma6ToolType tool, vpCameraParameters::vpCameraParametersProjType projModel)
{
InitTry;
// Read the robot constants from files
// - joint [min,max], coupl_56, long_56
// - camera extrinsic parameters relative to eMc
vpAfma6::init(tool, projModel);
// Set the robot constant (coupl_56, long_56) in the MotionBlox
Try(PrimitiveROBOT_CONST_Afma6(_coupl_56, _long_56));
// Set the camera constant (eMc pose) in the MotionBlox
double eMc_pose[6];
for (unsigned int i = 0; i < 3; i++) {
eMc_pose[i] = _etc[i]; // translation in meters
eMc_pose[i + 3] = _erc[i]; // rotation in rad
}
// Update the eMc pose in the low level controller
Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
// get real joint min/max from the MotionBlox
Try(PrimitiveJOINT_MINMAX_Afma6(_joint_min, _joint_max));
// for (unsigned int i=0; i < njoint; i++) {
// printf("axis %d: joint min %lf, max %lf\n", i, _joint_min[i],
// _joint_max[i]);
// }
setToolType(tool);
CatchPrint();
return;
}
/*!
Set the geometric transformation between the end-effector frame and
the tool frame in the low level controller.
\warning This function overwrite the transformation parameters that were
potentially set using one of the init functions
\param eMc : Transformation between the end-effector frame
and the tool frame.
*/
void vpRobotAfma6::set_eMc(const vpHomogeneousMatrix &eMc)
{
InitTry;
// Set camera extrinsic parameters equal to eMc
this->vpAfma6::set_eMc(eMc);
// Set the camera constant (eMc pose) in the MotionBlox
double eMc_pose[6];
for (unsigned int i = 0; i < 3; i++) {
eMc_pose[i] = _etc[i]; // translation in meters
eMc_pose[i + 3] = _erc[i]; // rotation in rad
}
// Update the eMc pose in the low level controller
Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
CatchPrint();
}
/*!
Initialize the robot kinematics with user defined parameters
(set the eMc homogeneous parameters in the low level controller)
and also get the joint limits from the low-level controller.
\param tool : Tool to use.
\param eMc : Transformation between the end-effector frame
and the tool frame.
To set the transformation parameters related to the \f$^e{\bf
M}_c\f$ matrix, use the code below:
\code
#include <visp3/robot/vpRobotAfma6.h>
int main()
{
#ifdef VISP_HAVE_AFMA6
vpRobotAfma6 robot;
// Set the transformation between the end-effector frame
// and the tool frame.
vpHomogeneousMatrix eMc(0.001, 0.0, 0.1, 0.0, 0.0, M_PI/2);
robot.init(vpAfma6::TOOL_CUSTOM, eMc);
#endif
}
\endcode
\sa vpCameraParameters, init(), init(vpAfma6::vpAfma6ToolType,
vpCameraParameters::vpCameraParametersProjType),
init(vpAfma6::vpAfma6ToolType, const std::string&)
*/
void vpRobotAfma6::init(vpAfma6::vpAfma6ToolType tool, const vpHomogeneousMatrix &eMc)
{
InitTry;
// Read the robot constants from files
// - joint [min,max], coupl_56, long_56
// ans set camera extrinsic parameters equal to eMc
vpAfma6::init(tool, eMc);
// Set the robot constant (coupl_56, long_56) in the MotionBlox
Try(PrimitiveROBOT_CONST_Afma6(_coupl_56, _long_56));
// Set the camera constant (eMc pose) in the MotionBlox
double eMc_pose[6];
for (unsigned int i = 0; i < 3; i++) {
eMc_pose[i] = _etc[i]; // translation in meters
eMc_pose[i + 3] = _erc[i]; // rotation in rad
}
// Update the eMc pose in the low level controller
Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
// get real joint min/max from the MotionBlox
Try(PrimitiveJOINT_MINMAX_Afma6(_joint_min, _joint_max));
setToolType(tool);
CatchPrint();
}
/*!
Initialize the robot kinematics (set the eMc homogeneous
parameters in the low level controller) from a file and
also get the joint limits from the low-level controller.
\param tool : Tool to use.
\param filename : Path of the configuration file containing the
transformation between the end-effector frame and the tool frame.
To set the transformation parameters related to the \f$^e{\bf
M}_c\f$ matrix, use the code below:
\code
#include <visp3/robot/vpRobotAfma6.h>
int main()
{
#ifdef VISP_HAVE_AFMA6
vpRobotAfma6 robot;
// Set the transformation between the end-effector frame
// and the tool frame from a file
std::string filename("./EffectorToolTransformation.cnf");
robot.init(vpAfma6::TOOL_CUSTOM, filename);
#endif
}
\endcode
The configuration file should have the form below:
\code
# Start with any number of consecutive lines
# beginning with the symbol '#'
#
# The 3 following lines contain the name of the camera,
# the rotation parameters of the geometric transformation
# using the Euler angles in degrees with convention XYZ and
# the translation parameters expressed in meters
CAMERA CameraName
eMc_ROT_XYZ 10.0 -90.0 20.0
eMc_TRANS_XYZ 0.05 0.01 0.06
\endcode
\sa init(), init(vpAfma6::vpAfma6ToolType,
vpCameraParameters::vpCameraParametersProjType),
init(vpAfma6::vpAfma6ToolType, const vpHomogeneousMatrix&)
*/
void vpRobotAfma6::init(vpAfma6::vpAfma6ToolType tool, const std::string &filename)
{
InitTry;
// Read the robot constants from files
// - joint [min,max], coupl_56, long_56
// ans set camera extrinsic parameters from file name
vpAfma6::init(tool, filename);
// Set the robot constant (coupl_56, long_56) in the MotionBlox
Try(PrimitiveROBOT_CONST_Afma6(_coupl_56, _long_56));
// Set the camera constant (eMc pose) in the MotionBlox
double eMc_pose[6];
for (unsigned int i = 0; i < 3; i++) {
eMc_pose[i] = _etc[i]; // translation in meters
eMc_pose[i + 3] = _erc[i]; // rotation in rad
}
// Update the eMc pose in the low level controller
Try(PrimitiveCAMERA_CONST_Afma6(eMc_pose));
// get real joint min/max from the MotionBlox
Try(PrimitiveJOINT_MINMAX_Afma6(_joint_min, _joint_max));
setToolType(tool);
CatchPrint();
}
/* ------------------------------------------------------------------------ */
/* --- DESTRUCTOR --------------------------------------------------------- */
/* ------------------------------------------------------------------------ */
/*!
Destructor.
Free allocated resources.
*/
vpRobotAfma6::~vpRobotAfma6(void)
{
InitTry;
setRobotState(vpRobot::STATE_STOP);
// Look if the power is on or off
UInt32 HIPowerStatus;
Try(PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
CAL_Wait(0.1);
// if (HIPowerStatus == 1) {
// fprintf(stdout, "Power OFF the robot\n");
// fflush(stdout);
// Try( PrimitivePOWEROFF_Afma6() );
// }
// Free allocated resources
ShutDownConnection();
vpRobotAfma6::robotAlreadyCreated = false;
CatchPrint();
return;
}
/*!
Change the robot state.
\param newState : New requested robot state.
*/
vpRobot::vpRobotStateType vpRobotAfma6::setRobotState(vpRobot::vpRobotStateType newState)
{
InitTry;
switch (newState) {
case vpRobot::STATE_STOP: {
if (vpRobot::STATE_STOP != getRobotState()) {
Try(PrimitiveSTOP_Afma6());
}
break;
}
case vpRobot::STATE_POSITION_CONTROL: {
if (vpRobot::STATE_VELOCITY_CONTROL == getRobotState()) {
std::cout << "Change the control mode from velocity to position control.\n";
Try(PrimitiveSTOP_Afma6());
} else {
// std::cout << "Change the control mode from stop to position
// control.\n";
}
this->powerOn();
break;
}
case vpRobot::STATE_VELOCITY_CONTROL: {
if (vpRobot::STATE_VELOCITY_CONTROL != getRobotState()) {
std::cout << "Change the control mode from stop to velocity control.\n";
}
this->powerOn();
break;
}
default:
break;
}
CatchPrint();
return vpRobot::setRobotState(newState);
}
/* ------------------------------------------------------------------------ */
/* --- STOP --------------------------------------------------------------- */
/* ------------------------------------------------------------------------ */
/*!
Stop the robot and set the robot state to vpRobot::STATE_STOP.
\exception vpRobotException::lowLevelError : If the low level
controller returns an error during robot stopping.
*/
void vpRobotAfma6::stopMotion(void)
{
InitTry;
Try(PrimitiveSTOP_Afma6());
setRobotState(vpRobot::STATE_STOP);
CatchPrint();
if (TryStt < 0) {
vpERROR_TRACE("Cannot stop robot motion");
throw vpRobotException(vpRobotException::lowLevelError, "Cannot stop robot motion.");
}
}
/*!
Power on the robot.
\exception vpRobotException::lowLevelError : If the low level
controller returns an error during robot power on.
\sa powerOff(), getPowerState()
*/
void vpRobotAfma6::powerOn(void)
{
InitTry;
// Look if the power is on or off
UInt32 HIPowerStatus;
UInt32 EStopStatus;
bool firsttime = true;
unsigned int nitermax = 10;
for (unsigned int i = 0; i < nitermax; i++) {
Try(PrimitiveSTATUS_Afma6(NULL, NULL, &EStopStatus, NULL, NULL, NULL, &HIPowerStatus));
if (EStopStatus == ESTOP_AUTO) {
break; // exit for loop
} else if (EStopStatus == ESTOP_MANUAL) {
break; // exit for loop
} else if (EStopStatus == ESTOP_ACTIVATED) {
if (firsttime) {
std::cout << "Emergency stop is activated! \n"
<< "Check the emergency stop button and push the yellow "
"button before continuing."
<< std::endl;
firsttime = false;
}
fprintf(stdout, "Remaining time %us \r", nitermax - i);
fflush(stdout);
CAL_Wait(1);
} else {
std::cout << "Sorry there is an error on the emergency chain." << std::endl;
std::cout << "You have to call Adept for maintenance..." << std::endl;
// Free allocated resources
ShutDownConnection();
throw(vpRobotException(vpRobotException::lowLevelError, "Error on the emergency chain"));
}
}
if (EStopStatus == ESTOP_ACTIVATED)
std::cout << std::endl;
if (EStopStatus == ESTOP_ACTIVATED) {
std::cout << "Sorry, cannot power on the robot." << std::endl;
throw(vpRobotException(vpRobotException::lowLevelError, "Cannot power on the robot."));
}
if (HIPowerStatus == 0) {
fprintf(stdout, "Power ON the Afma6 robot\n");
fflush(stdout);
Try(PrimitivePOWERON_Afma6());
}
CatchPrint();
if (TryStt < 0) {
vpERROR_TRACE("Cannot power on the robot");
throw(vpRobotException(vpRobotException::lowLevelError, "Cannot power off the robot."));
}
}
/*!
Power off the robot.
\exception vpRobotException::lowLevelError : If the low level
controller returns an error during robot stopping.
\sa powerOn(), getPowerState()
*/
void vpRobotAfma6::powerOff(void)
{
InitTry;
// Look if the power is on or off
UInt32 HIPowerStatus;
Try(PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
CAL_Wait(0.1);
if (HIPowerStatus == 1) {
fprintf(stdout, "Power OFF the Afma6 robot\n");
fflush(stdout);
Try(PrimitivePOWEROFF_Afma6());
}
CatchPrint();
if (TryStt < 0) {
vpERROR_TRACE("Cannot power off the robot");
throw vpRobotException(vpRobotException::lowLevelError, "Cannot power off the robot.");
}
}
/*!
Get the robot power state indication if power is on or off.
\return true if power is on. false if power is off
\exception vpRobotException::lowLevelError : If the low level
controller returns an error.
\sa powerOn(), powerOff()
*/
bool vpRobotAfma6::getPowerState(void)
{
InitTry;
bool status = false;
// Look if the power is on or off
UInt32 HIPowerStatus;
Try(PrimitiveSTATUS_Afma6(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
CAL_Wait(0.1);
if (HIPowerStatus == 1) {
status = true;
}
CatchPrint();
if (TryStt < 0) {
vpERROR_TRACE("Cannot get the power status");
throw vpRobotException(vpRobotException::lowLevelError, "Cannot get the power status.");
}
return status;
}
/*!
Get the twist transformation from camera frame to end-effector
frame. This transformation allows to compute a velocity expressed
in the end-effector frame into the camera frame.
\param cVe : Twist transformation.
*/
void vpRobotAfma6::get_cVe(vpVelocityTwistMatrix &cVe) const
{
vpHomogeneousMatrix cMe;
vpAfma6::get_cMe(cMe);
cVe.buildFrom(cMe);
}
/*!
Get the geometric transformation between the camera frame and the
end-effector frame. This transformation is constant and correspond
to the extrinsic camera parameters estimated by calibration.
\param cMe : Transformation between the camera frame and the
end-effector frame.
*/
void vpRobotAfma6::get_cMe(vpHomogeneousMatrix &cMe) const { vpAfma6::get_cMe(cMe); }
/*!
Get the robot jacobian expressed in the end-effector frame.
To compute eJe, we communicate with the low level controller to get
the articular joint position of the robot.
\param eJe : Robot jacobian expressed in the end-effector frame.
*/
void vpRobotAfma6::get_eJe(vpMatrix &eJe)
{
double position[6];
double timestamp;
InitTry;
Try(PrimitiveACQ_POS_Afma6(position, ×tamp));
CatchPrint();
vpColVector q(6);
for (unsigned int i = 0; i < njoint; i++)
q[i] = position[i];
try {
vpAfma6::get_eJe(q, eJe);
} catch (...) {
vpERROR_TRACE("catch exception ");
throw;
}
}
/*!
Get the robot jacobian expressed in the robot reference frame also
called fix frame.
To compute fJe, we communicate with the low level controller to get
the articular joint position of the robot.
\f[
{^f}J_e = \left(\begin{array}{cccccc}
1 & 0 & 0 & -Ls4 & 0 & 0 \\
0 & 1 & 0 & Lc4 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & c4 & -s4c5 \\
0 & 0 & 0 & 0 & s4 & c4c5 \\
0 & 0 & 0 & 1 & 0 & s5 \\
\end{array}
\right)
\f]
\param fJe : Robot jacobian expressed in the reference frame.
*/
void vpRobotAfma6::get_fJe(vpMatrix &fJe)
{
double position[6];
double timestamp;
InitTry;
Try(PrimitiveACQ_POS_Afma6(position, ×tamp));
CatchPrint();
vpColVector q(6);
for (unsigned int i = 0; i < njoint; i++)
q[i] = position[i];
try {
vpAfma6::get_fJe(q, fJe);
} catch (...) {
vpERROR_TRACE("Error caught");
throw;
}
}
/*!
Set the maximal velocity percentage to use for a position control.
The default positioning velocity is defined by
vpRobotAfma6::defaultPositioningVelocity. This method allows to
change this default positioning velocity
\param velocity : Percentage of the maximal velocity. Values should
be in ]0:100].
\code
vpColVector position(6);
position = 0; // position in meter and rad
vpRobotAfma6 robot;
robot.setRobotState(vpRobot::STATE_POSITION_CONTROL);
// Set the max velocity to 20%
robot.setPositioningVelocity(20);
// Moves the robot to the joint position [0,0,0,0,0,0]
robot.setPosition(vpRobot::ARTICULAR_FRAME, position);
\endcode
\sa getPositioningVelocity()
*/
void vpRobotAfma6::setPositioningVelocity(double velocity) { positioningVelocity = velocity; }
/*!
Get the maximal velocity percentage used for a position control.
\sa setPositioningVelocity()
*/
double vpRobotAfma6::getPositioningVelocity(void) { return positioningVelocity; }
/*!
Move the robot to an absolute cartesian position with a given percent of max
velocity. The percent of max velocity is to set with
setPositioningVelocity(). The position to reach can only be specified in
camera frame or in the reference frame. In joint, an exception is thrown.
\warning This method is blocking. It returns only when the position
is reached by the robot.
\param pose : A six dimension pose vector corresponding to the position
to reach. The three first parameters are the translations in meter, the
three last parameters are the rotations expressed as a theta u vector in
radians. If the position is out of range, an exception is provided.
\param frame : Frame in which the position is expressed.
- In the camera and the reference frame, rotations are
represented by a vpThetaUVector.
- Mixt frame of joint frame is not implemented.
\exception vpRobotException::lowLevelError : vpRobot::MIXT_FRAME,
vpRobot::END_EFFECTOR_FRAME and vpRobot::ARTICULAR_FRAME not implemented.
\exception vpRobotException::positionOutOfRangeError : The requested
position is out of range.
\code
#include <visp3/core/vpPoseVector.h>
#include <visp3/robot/vpRobotAfma6.h>
int main()
{
#ifdef VISP_HAVE_AFMA6
vpPoseVector pose;
// Set positions in the reference frame
pose[0] = 0.1; // x axis, in meter
pose[1] = 0.; // y axis, in meter
pose[2] = 0.3; // z axis, in meter
pose[3] = M_PI/8; // ThetaU rotation around x axis, in rad
pose[4] = M_PI/4; // ThetaU rotation around y axis, in rad
pose[5] = 0.; // ThetaU rotation around z axis, in rad
vpRobotAfma6 robot;
robot.setRobotState(vpRobot::STATE_POSITION_CONTROL);
// Set the max velocity to 20%
robot.setPositioningVelocity(20);
// Moves the robot in the camera frame
robot.setPosition(vpRobot::REFERENCE_FRAME, pose);
return 0;
#endif
}
\endcode
To catch the exception if the position is out of range, modify the code
like:
\code
try {
robot.setPosition(vpRobot::REFERENCE_FRAME, pose);
}
catch (vpRobotException &e) {
if (e.getCode() == vpRobotException::positionOutOfRangeError) {
std::cout << "The position is out of range" << std::endl;
}
}
\endcode