-
Notifications
You must be signed in to change notification settings - Fork 283
/
vpRobotAfma4.cpp
1750 lines (1383 loc) · 51.2 KB
/
vpRobotAfma4.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 Afma4 robot.
*
* Authors:
* Fabien Spindler
*
*****************************************************************************/
#include <visp3/core/vpConfig.h>
#ifdef VISP_HAVE_AFMA4
#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/vpThetaUVector.h>
#include <visp3/core/vpVelocityTwistMatrix.h>
#include <visp3/robot/vpRobotAfma4.h>
#include <visp3/robot/vpRobotException.h>
/* ---------------------------------------------------------------------- */
/* --- STATIC ----------------------------------------------------------- */
/* ---------------------------------------------------------------------- */
bool vpRobotAfma4::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 vpRobotAfma4::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 emergencyStopAfma4(int signo)
{
std::cout << "Stop the Afma4 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_Afma4();
PrimitiveSTOP_Afma4();
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, 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.
*/
vpRobotAfma4::vpRobotAfma4(bool verbose) : vpAfma4(), 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, emergencyStopAfma4);
signal(SIGBUS, emergencyStopAfma4);
signal(SIGSEGV, emergencyStopAfma4);
signal(SIGKILL, emergencyStopAfma4);
signal(SIGQUIT, emergencyStopAfma4);
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;
vpRobotAfma4::robotAlreadyCreated = true;
return;
}
/* ------------------------------------------------------------------------ */
/* --- INITIALISATION ----------------------------------------------------- */
/* ------------------------------------------------------------------------ */
/*!
Initialise the connection with the MotionBox or low level
controller, power on the
robot and wait 1 sec before returning to be sure the initialisation
is done.
*/
void vpRobotAfma4::init(void)
{
int stt;
InitTry;
// Initialise private variables used to compute the measured velocities
q_prev_getvel.resize(4);
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(4);
q_prev_getdis = 0;
first_time_getdis = true;
// Initialize the firewire connection
Try(stt = InitializeConnection(verbose_));
if (stt != SUCCESS) {
vpERROR_TRACE("Cannot open connection with the motionblox.");
throw vpRobotException(vpRobotException::constructionError, "Cannot open connection with the motionblox");
}
// Connect to the servoboard using the servo board GUID
Try(stt = InitializeNode_Afma4());
if (stt != SUCCESS) {
vpERROR_TRACE("Cannot open connection with the motionblox.");
throw vpRobotException(vpRobotException::constructionError, "Cannot open connection with the motionblox");
}
Try(PrimitiveRESET_Afma4());
// Look if the power is on or off
UInt32 HIPowerStatus;
UInt32 EStopStatus;
Try(PrimitiveSTATUS_Afma4(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_Afma4(_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_Afma4();
// 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;
}
/* ------------------------------------------------------------------------ */
/* --- DESTRUCTOR --------------------------------------------------------- */
/* ------------------------------------------------------------------------ */
/*!
Destructor.
Free allocated resources.
*/
vpRobotAfma4::~vpRobotAfma4(void)
{
InitTry;
setRobotState(vpRobot::STATE_STOP);
// Look if the power is on or off
UInt32 HIPowerStatus;
Try(PrimitiveSTATUS_Afma4(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_Afma4() );
// }
// Free allocated resources
ShutDownConnection();
vpRobotAfma4::robotAlreadyCreated = false;
CatchPrint();
return;
}
/*!
Change the robot state.
\param newState : New requested robot state.
*/
vpRobot::vpRobotStateType vpRobotAfma4::setRobotState(vpRobot::vpRobotStateType newState)
{
InitTry;
switch (newState) {
case vpRobot::STATE_STOP: {
if (vpRobot::STATE_STOP != getRobotState()) {
Try(PrimitiveSTOP_Afma4());
}
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_Afma4());
} 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 vpRobotAfma4::stopMotion(void)
{
InitTry;
Try(PrimitiveSTOP_Afma4());
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 vpRobotAfma4::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_Afma4(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 in 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 Afma4 robot\n");
fflush(stdout);
Try(PrimitivePOWERON_Afma4());
}
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 vpRobotAfma4::powerOff(void)
{
InitTry;
// Look if the power is on or off
UInt32 HIPowerStatus;
Try(PrimitiveSTATUS_Afma4(NULL, NULL, NULL, NULL, NULL, NULL, &HIPowerStatus));
CAL_Wait(0.1);
if (HIPowerStatus == 1) {
fprintf(stdout, "Power OFF the Afma4 robot\n");
fflush(stdout);
Try(PrimitivePOWEROFF_Afma4());
}
CatchPrint();
if (TryStt < 0) {
vpERROR_TRACE("Cannot power off the robot");
throw vpRobotException(vpRobotException::communicationError, "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 vpRobotAfma4::getPowerState(void)
{
InitTry;
bool status = false;
// Look if the power is on or off
UInt32 HIPowerStatus;
Try(PrimitiveSTATUS_Afma4(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 vpRobotAfma4::get_cVe(vpVelocityTwistMatrix &cVe) const
{
vpHomogeneousMatrix cMe;
vpAfma4::get_cMe(cMe);
cVe.buildFrom(cMe);
}
/*!
Get the twist transformation from camera frame to the reference
frame. This transformation allows to compute a velocity expressed
in the reference frame into the camera frame.
\param cVf : Twist transformation.
*/
void vpRobotAfma4::get_cVf(vpVelocityTwistMatrix &cVf) const
{
double position[this->njoint];
double timestamp;
InitTry;
Try(PrimitiveACQ_POS_Afma4(position, ×tamp));
CatchPrint();
vpColVector q(this->njoint);
for (unsigned int i = 0; i < njoint; i++)
q[i] = position[i];
try {
vpAfma4::get_cVf(q, cVf);
} catch (...) {
vpERROR_TRACE("catch exception ");
throw;
}
}
/*!
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 vpRobotAfma4::get_cMe(vpHomogeneousMatrix &cMe) const { vpAfma4::get_cMe(cMe); }
/*!
Get the robot jacobian expressed in the end-effector frame. To have
acces to the analytic form of this jacobian see vpAfma4::get_eJe().
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.
\sa vpAfma4::get_eJe()
*/
void vpRobotAfma4::get_eJe(vpMatrix &eJe)
{
double position[this->njoint];
double timestamp;
InitTry;
Try(PrimitiveACQ_POS_Afma4(position, ×tamp));
CatchPrint();
vpColVector q(this->njoint);
for (unsigned int i = 0; i < njoint; i++)
q[i] = position[i];
try {
vpAfma4::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 have acces to the analytic form of this
jacobian see vpAfma4::get_fJe().
To compute fJe, we communicate with the low level controller to get
the articular joint position of the robot.
\param fJe : Robot jacobian expressed in the reference frame.
\sa vpAfma4::get_fJe()
*/
void vpRobotAfma4::get_fJe(vpMatrix &fJe)
{
double position[6];
double timestamp;
InitTry;
Try(PrimitiveACQ_POS_Afma4(position, ×tamp));
CatchPrint();
vpColVector q(6);
for (unsigned int i = 0; i < njoint; i++)
q[i] = position[i];
try {
vpAfma4::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
vpRobotAfma4::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 q[4]);
q = 0; // position in meter and rad
vpRobotAfma4 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]
robot.setPosition(vpRobot::ARTICULAR_FRAME, q);
\endcode
\sa getPositioningVelocity()
*/
void vpRobotAfma4::setPositioningVelocity(double velocity) { positioningVelocity = velocity; }
/*!
Get the maximal velocity percentage used for a position control.
\sa setPositioningVelocity()
*/
double vpRobotAfma4::getPositioningVelocity(void) { return positioningVelocity; }
/*!
Move to an absolute position with a given percent of max velocity.
The percent of max velocity is to set with setPositioningVelocity().
\warning The position to reach can only be specified in joint space
coordinates.
This method owerloads setPosition(const
vpRobot::vpControlFrameType, const vpColVector &).
\warning This method is blocking. It returns only when the position
is reached by the robot.
\param position : The joint positions to reach. position[0]
corresponds to the first rotation of the turret around the vertical
axis (joint 1 with value \f$q_1\f$), while position[1] corresponds
to the vertical translation (joint 2 with value \f$q_2\f$), while
position[2] and position[3] correspond to the pan and tilt of the
camera (respectively joint 4 and 5 with values \f$q_4\f$ and
\f$q_5\f$). Rotations position[0], position[2] and position[3] are
expressed in radians. The translation q[1] is expressed in meters.
\param frame : Frame in which the position is expressed.
\exception vpRobotException::lowLevelError : vpRobot::MIXT_FRAME and
vpRobot::END_EFFECTOR_FRAME not implemented.
\exception vpRobotException::positionOutOfRangeError : The requested
position is out of range.
\code
// Set positions in the joint space
vpColVector q[4];
double q[0] = M_PI/8; // Joint 1, in radian
double q[1] = 0.2; // Joint 2, in meter
double q[2] = M_PI/4; // Joint 4, in radian
double q[3] = M_PI/8; // Joint 5, in radian
vpRobotAfma4 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::ARTICULAR_FRAME, q);
\endcode
\exception vpRobotException::lowLevelError : If the requested frame
(vpRobot::REFERENCE_FRAME, vpRobot::CAMERA_FRAME, vpRobot::END_EFFECTOR_FRAME
or vpRobot::MIXT_FRAME) are requested since they are not implemented.
\exception vpRobotException::positionOutOfRangeError : The requested
position is out of range.
To catch the exception if the position is out of range, modify the code
like:
\code
try {
robot.setPosition(vpRobot::CAMERA_FRAME, q);
}
catch (vpRobotException &e) {
if (e.getCode() == vpRobotException::positionOutOfRangeError) {
std::cout << "The position is out of range" << std::endl;
}
\endcode
*/
void vpRobotAfma4::setPosition(const vpRobot::vpControlFrameType frame, const vpColVector &position)
{
if (vpRobot::STATE_POSITION_CONTROL != getRobotState()) {
vpERROR_TRACE("Robot was not in position-based control\n"
"Modification of the robot state");
setRobotState(vpRobot::STATE_POSITION_CONTROL);
}
int error = 0;
switch (frame) {
case vpRobot::REFERENCE_FRAME:
throw vpRobotException(vpRobotException::lowLevelError, "Positionning error: "
"Reference frame not implemented.");
break;
case vpRobot::CAMERA_FRAME:
throw vpRobotException(vpRobotException::lowLevelError, "Positionning error: "
"Camera frame not implemented.");
break;
case vpRobot::MIXT_FRAME:
throw vpRobotException(vpRobotException::lowLevelError, "Positionning error: "
"Mixt frame not implemented.");
break;
case vpRobot::END_EFFECTOR_FRAME:
throw vpRobotException(vpRobotException::lowLevelError, "Positionning error: "
"End-effector frame not implemented.");
break;
case vpRobot::ARTICULAR_FRAME: {
break;
}
}
if (position.getRows() != this->njoint) {
vpERROR_TRACE("Positionning error: bad vector dimension.");
throw vpRobotException(vpRobotException::positionOutOfRangeError, "Positionning error: bad vector dimension.");
}
InitTry;
Try(PrimitiveMOVE_Afma4(position.data, positioningVelocity));
Try(WaitState_Afma4(ETAT_ATTENTE_AFMA4, 1000));
CatchPrint();
if (TryStt == InvalidPosition || TryStt == -1023)
std::cout << " : Position out of range.\n";
else if (TryStt < 0)
std::cout << " : Unknown error (see Fabien).\n";
else if (error == -1)
std::cout << "Position out of range.\n";
if (TryStt < 0 || error < 0) {
vpERROR_TRACE("Positionning error.");
throw vpRobotException(vpRobotException::positionOutOfRangeError, "Position out of range.");
}
return;
}
/*!
Move to an absolute position with a given percent of max velocity.
The percent of max velocity is to set with setPositioningVelocity().
\warning The position to reach can only be specified in joint space
coordinates.
This method owerloads setPosition(const
vpRobot::vpControlFrameType, const vpColVector &).
\warning This method is blocking. It returns only when the position
is reached by the robot.
\param q1, q2, q4, q5 : The four joint positions to reach. q1 corresponds to
the first rotation (joint 1 with value \f$q_1\f$) of the turret
around the vertical axis, while q2 corresponds to the vertical
translation (joint 2 with value \f$q_2\f$), while q4 and q5
correspond to the pan and tilt of the camera (respectively joint 4
and 5 with values \f$q_4\f$ and \f$q_5\f$). Rotations q1, q4 and
q5 are expressed in radians. The translation q2 is expressed in
meters.
\param frame : Frame in which the position is expressed.
\exception vpRobotException::lowLevelError : vpRobot::MIXT_FRAME
and vpRobot::END_EFFECTOR_FRAME not implemented.
\exception vpRobotException::positionOutOfRangeError : The requested
position is out of range.
\code
// Set positions in the camera frame
double q1 = M_PI/8; // Joint 1, in radian
double q2 = 0.2; // Joint 2, in meter
double q4 = M_PI/4; // Joint 4, in radian
double q5 = M_PI/8; // Joint 5, in radian
vpRobotAfma4 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::ARTICULAR_FRAME, q1, q2, q4, q5);
\endcode
\sa setPosition()
*/
void vpRobotAfma4::setPosition(const vpRobot::vpControlFrameType frame, const double q1, const double q2,
const double q4, const double q5)
{
try {
vpColVector position(this->njoint);
position[0] = q1;
position[1] = q2;
position[2] = q4;
position[3] = q5;
setPosition(frame, position);
} catch (...) {
vpERROR_TRACE("Error caught");
throw;
}
}
/*!
Move to an absolute joint position with a given percent of max
velocity. The robot state is set to position control. The percent
of max velocity is to set with setPositioningVelocity(). The
position to reach is defined in the position file.
\param filename : Name of the position file to read. The
readPosFile() documentation shows a typical content of such a
position file.
This method has the same behavior than the sample code given below;
\code
vpColVector q;
robot.readPosFile("MyPositionFilename.pos", q);
robot.setRobotState(vpRobot::STATE_POSITION_CONTROL)
robot.setPosition(vpRobot::ARTICULAR_FRAME, q);
\endcode
\exception vpRobotException::lowLevelError : vpRobot::MIXT_FRAME
and vpRobot::END_EFFECTOR_FRAME not implemented.
\exception vpRobotException::positionOutOfRangeError : The requested
position is out of range.
\sa setPositioningVelocity()
*/
void vpRobotAfma4::setPosition(const char *filename)
{
vpColVector q;
bool ret;
ret = this->readPosFile(filename, q);
if (ret == false) {
vpERROR_TRACE("Bad position in \"%s\"", filename);
throw vpRobotException(vpRobotException::lowLevelError, "Bad position in filename.");
}
this->setRobotState(vpRobot::STATE_POSITION_CONTROL);
this->setPosition(vpRobot::ARTICULAR_FRAME, q);
}
/*!
Returns the robot controller current time (in second) since last robot power
on.
*/
double vpRobotAfma4::getTime() const
{
double timestamp;
PrimitiveACQ_TIME_Afma4(×tamp);
return timestamp;
}
/*!
Get the current position of the robot.
\param frame : Control frame type in which to get the position, either :
- in the camera cartesien frame,
- joint (articular) coordinates of each axes
- in a reference or fixed cartesien frame attached to the robot base
- in a mixt cartesien frame (translation in reference
frame, and rotation in camera frame)
\param position : Measured position of the robot:
- in camera cartesien frame, a 6 dimension vector, set to 0.
- in articular, a 4 dimension vector corresponding to the joint position of
each dof. position[0]
corresponds to the first rotation of the turret around the vertical
axis (joint 1 with value \f$q_1\f$), while position[1] corresponds
to the vertical translation (joint 2 with value \f$q_2\f$), while
position[2] and position[3] correspond to the pan and tilt of the
camera (respectively joint 4 and 5 with values \f$q_4\f$ and
\f$q_5\f$). Rotations position[0], position[2] and position[3] are
expressed in radians. The translation q[1] is expressed in meters.
- in reference frame, a 6 dimension vector, the first 3 values correspond to
the translation tx, ty, tz in meters (like a vpTranslationVector), and the
last 3 values to the rx, ry, rz rotation (like a vpRxyzVector). The code
below show how to convert this position into a vpHomogeneousMatrix:
\param timestamp : Time in second since last robot power on.
\code
vpRobotAfma4 robot;
vpColVector r;
robot.getPosition(vpRobot::REFERENCE_FRAME, r);
vpTranslationVector ftc; // reference frame to camera frame translations
vpRxyzVector frc; // reference frame to camera frame rotations
// Update the transformation between reference frame and camera frame
for (int i=0; i < 3; i++) {
ftc[i] = position[i]; // tx, ty, tz
frc[i] = position[i+3]; // ry, ry, rz
}
// Create a rotation matrix from the Rxyz rotation angles
vpRotationMatrix fRc(frc); // reference frame to camera frame rotation
matrix
// Create the camera to fix frame pose in terms of a homogeneous matrix
vpHomogeneousMatrix fMc(fRc, ftc);
\endcode
\exception vpRobotException::lowLevelError : If the position cannot
be get from the low level controller.
\sa setPosition(const vpRobot::vpControlFrameType frame, const
vpColVector & r)
*/
void vpRobotAfma4::getPosition(const vpRobot::vpControlFrameType frame, vpColVector &position, double ×tamp)
{
InitTry;
position.resize(this->njoint);