Epos2.cpp
Go to the documentation of this file.
1 // Copyright (C) 2009-2010 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
2 // Author Martí Morta Garriga (mmorta@iri.upc.edu)
3 // All rights reserved.
4 //
5 // Copyright (C) 2013 Jochen Sprickerhof <jochen@sprickerhof.de>
6 //
7 // This file is part of IRI EPOS2 Driver
8 // IRI EPOS2 Driver is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Lesser General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21 #include <iostream>
22 #include <cstdio>
23 #include <sstream>
24 #include "Epos2.h"
25 //#define DEBUG
26 
27 // ----------------------------------------------------------------------------
28 // CLASS
29 // ----------------------------------------------------------------------------
30 // CONSTRUCTOR
31 // ----------------------------------------------------------------------------
32 
33 CEpos2::CEpos2(int8_t nodeId) : node_id(nodeId), verbose(false)
34 { }
35 
36 // DESTRUCTOR
37 // ----------------------------------------------------------------------------
38 
40 {
41 }
42 
43 // ----------------------------------------------------------------------------
44 // OPERATION
45 // ----------------------------------------------------------------------------
46 // INIT
47 // ----------------------------------------------------------------------------
48 
50 {
51  this->openDevice();
52  this->readStatusWord();
53 }
54 
55 // CLOSE
56 // ----------------------------------------------------------------------------
57 
59 {
60  this->disableVoltage();
61 }
62 
63 // P (print for debug) (stringstream)
64 // ----------------------------------------------------------------------------
65 
66 void CEpos2::p(const std::stringstream& text)
67 {
68  if(this->verbose) std::cout << " [EPOS2] " << text.str() << std::endl;
69 }
70 
71 // P (char *)
72 // ----------------------------------------------------------------------------
73 
74 void CEpos2::p(const char *text)
75 {
76  if(this->verbose) std::cout << " [EPOS2] " << text << std::endl;
77 }
78 
79 // GET VERBOSE
80 // ----------------------------------------------------------------------------
81 
83 {
84  return(this->verbose);
85 }
86 
87 // SET VERBOSE
88 // ----------------------------------------------------------------------------
89 
91 {
92  this->verbose=verbose;
93 }
94 
95 
96 //----------------------------------------------------------------------------
97 // COMMUNICATION
98 // ----------------------------------------------------------------------------
99 // OPEN DEVICE
100 // ----------------------------------------------------------------------------
101 
102 bool CEpos2::ftdi_initialized = false;
103 Ftdi::Context CEpos2::ftdi;
104 
106 {
108  return;
109  if(CEpos2::ftdi.open(0x403, 0xa8b0) != 0)
110  throw EPOS2OpenException("No FTDI devices connected");
111 
112  CEpos2::ftdi.set_baud_rate(1000000);
113  CEpos2::ftdi.set_line_property(BITS_8, STOP_BIT_1, NONE);
114  CEpos2::ftdi.set_usb_read_timeout(10000);
115  CEpos2::ftdi.set_usb_write_timeout(10000);
116  CEpos2::ftdi.set_latency(1);
118 }
119 
120 // READ OBJECT
121 // ----------------------------------------------------------------------------
122 
123 int32_t CEpos2::readObject(int16_t index, int8_t subindex)
124 {
125  int32_t result = 0x00000000;
126  int16_t req_frame[4];
127  uint16_t ans_frame[4];
128 
129  req_frame[0] = 0x0210; // header (LEN,OPCODE)
130  req_frame[1] = index; // data
131  req_frame[2] = ((0x0000 | this->node_id) << 8) | subindex; // node_id subindex
132  req_frame[3] = 0x0000; // CRC
133 
134  //p("readObject: sendFrame");
135  this->sendFrame(req_frame);
136 
137  //printf("RF: %.2X %.2X %.2X %.2X\n",req_frame[0],req_frame[1],req_frame[2],req_frame[3]);
138 
139  //p("readObject: receiveFrame");
140  this->receiveFrame(ans_frame);
141 
142  //printf("AF: %.2X %.2X %.2X %.2X\n",ans_frame[0],ans_frame[1],ans_frame[2],ans_frame[3]);
143 
144  // if 0x8090, its 16 bit answer else is 32 bit
145  if(ans_frame[3]==0x8090)
146  result = ans_frame[2];
147  else
148  result = (ans_frame[3] << 16) | ans_frame[2];
149 
150  //printf("result: %d %d -> %d\n",ans_frame[3],ans_frame[2],result);
151 
152  return result;
153 }
154 
155 // WRITE OBJECT
156 // ----------------------------------------------------------------------------
157 
158 int32_t CEpos2::writeObject(int16_t index, int8_t subindex, int32_t data)
159 {
160  int32_t result = 0;
161  int16_t req_frame[6]={0,0,0,0,0,0};
162  uint16_t ans_frame[40]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
163 
164  req_frame[0] = 0x0411; // header (LEN,OPCODE)
165  req_frame[1] = index; // data
166  req_frame[2] = ((0x0000 | this->node_id) << 8) | subindex;
167  req_frame[3] = data & 0x0000FFFF;
168  req_frame[4] = data >> 16;
169  req_frame[5] = 0x0000; // checksum
170 
171  this->sendFrame(req_frame);
172  this->receiveFrame(ans_frame);
173 
174  // if 0x8090, its 16 bit answer else is 32 bit
175  if(ans_frame[3]==0x8090)
176  result = ans_frame[2];
177  else
178  result = (ans_frame[3] << 16) | ans_frame[2];
179 
180  return result;
181 }
182 
183 // SEND FRAME
184 // ----------------------------------------------------------------------------
185 
186 void CEpos2::sendFrame(int16_t *frame)
187 {
188  uint8_t trans_frame[80]; // transmission frame
189  int16_t length = ((frame[0] & 0xFF00) >> 8 ) + 2; // frame length
190 
191  // Add checksum to the frame
192  frame[length-1] = this->computeChecksum(frame,length);
193 
194  // add SYNC characters (DLE and STX)
195  trans_frame[0] = 0x90;
196  trans_frame[1] = 0x02;
197 
198  // Stuffing
199  int8_t i=0, tf_i=2;
200  while( i < length )
201  {
202  // LSB
203  trans_frame[tf_i] = frame[i] & 0x00FF;
204  if( trans_frame[tf_i] == 0x90 )
205  {
206  tf_i++;
207  trans_frame[tf_i] = 0x90;
208  }
209  tf_i++;
210 
211  // MSB
212  trans_frame[tf_i] = (frame[i] & 0xFF00) >> 8;
213  if( trans_frame[tf_i] == 0x90 )
214  {
215  tf_i++;
216  trans_frame[tf_i] = 0x90;
217  }
218  tf_i++;
219  i++;
220  }
221 
222  if(CEpos2::ftdi.write(trans_frame, tf_i) < 0)
223  throw EPOS2IOException("Impossible to write Status Word.\nIs the controller powered ?");
224 }
225 
226 // RECEIVE FRAME
227 // ----------------------------------------------------------------------------
228 
229 void CEpos2::receiveFrame(uint16_t* ans_frame)
230 {
231  // length variables
232  uint16_t read_desired = 0; // length of data that must read
233  uint16_t read_real = 0; // length of data read actually
234  uint16_t Len = 0; // Len header part in epos2 usb frame
235  uint16_t read_point = 0; // Position of the data read
236  uint16_t state = 0; // state of the parsing state machine
237  bool packet_complete = false;
238 
239  // data holders
240  uint8_t *read_buffer = NULL; // frame buffer stuffed
241  uint8_t *data = NULL; // frame buffer unstuffed
242  uint8_t cheksum[2];
243 
244  // get data packet
245  do{
246 
247  read_desired = CEpos2::ftdi.read_chunk_size();
248 
249  read_buffer = new uint8_t[read_desired];
250 
251  read_real = CEpos2::ftdi.read(read_buffer, read_desired);
252 
253  if(read_real < 0)
254  {
255  delete[] read_buffer;
256  if(data!=NULL)
257  delete[] data;
258  throw EPOS2IOException("Impossible to read Status Word.\nIs the controller powered ?");
259  }
260 
261  for(uint16_t i=0;i<read_real;i++)
262  {
263  switch (state)
264  {
265  case 0:
266  // no sync
267  if(read_buffer[i] == 0x90)
268  state = 1;
269  else
270  state = 0;
271  break;
272  case 1:
273  // sync stx
274  if(read_buffer[i] == 0x02)
275  state = 2;
276  else
277  state = 0;
278  break;
279  case 2:
280  // opcode
281  state = 3;
282  break;
283  case 3:
284  // len (16 bits)
285  Len = read_buffer[i];
286  if(data!=NULL)
287  delete[] data;
288  data = new uint8_t[Len*2];
289  read_point = -1;
290  state = 4;
291  break;
292  case 4:
293  read_point++;
294  data[read_point] = read_buffer[i];
295  if(data[read_point]==0x90)
296  {
297  state = 5;
298  }else{
299  if(read_point+1 == Len*2)
300  state = 6;
301  else
302  state = 4;
303  }
304  break;
305  case 5:
306  // destuffing
307  state = 4;
308  break;
309  case 6:
310  // checksum 1
311  cheksum[1] = read_buffer[i];
312  if(cheksum[1]==0x90){
313  state = 8;
314  }else{
315  state = 7;
316  }
317  break;
318  case 7:
319  // checksum 0
320  cheksum[0] = read_buffer[i];
321  if(cheksum[0]==0x90){
322  state = 9;
323  }else{
324  state = 0;
325  packet_complete = true;
326  }
327  break;
328  case 8:
329  // destuff checksum 1
330  state = 7;
331  break;
332  case 9:
333  // destuff checksum 0
334  state = 0;
335  packet_complete = true;
336  break;
337  }
338  }
339 
340  delete[] read_buffer;
341 
342  }while(!packet_complete);
343 
344 
345  // parse data
346  int tf_i = 0;
347  for(int i = 0; i < Len; i++)
348  {
349  ans_frame[i] = 0x0000;
350  // LSB to 0x__··
351  ans_frame[i] = data[tf_i];
352  tf_i++;
353  // MSB to 0x··__
354  ans_frame[i] = (data[tf_i]<<8) | ans_frame[i];
355  tf_i++;
356  }
357 
358  if(data!=NULL)
359  delete[] data;
360 
361 }
362 
363 // COMPUTE CHECKSUM
364 // ----------------------------------------------------------------------------
365 
366 int16_t CEpos2::computeChecksum(int16_t *pDataArray, int16_t numberOfWords)
367 {
368  uint16_t shifter, c;
369  uint16_t carry;
370  uint16_t CRC = 0;
371 
372  //Calculate pDataArray Word by Word
373  while(numberOfWords--)
374  {
375  shifter = 0x8000; //Initialize BitX to Bit15
376  c = *pDataArray++; //Copy next DataWord to c
377  do
378  {
379  carry = CRC & 0x8000; //Check if Bit15 of CRC is set
380  CRC <<= 1; //CRC = CRC * 2
381  if(c & shifter) CRC++; //CRC = CRC + 1, if BitX is set in c
382  if(carry) CRC ^= 0x1021; //CRC = CRC XOR G(x), if carry is true
383  shifter >>= 1; //Set BitX to next lower Bit, shifter = shifter/2
384  } while(shifter);
385  }
386 
387  return (int16_t)CRC;
388 }
389 
390 
391 //----------------------------------------------------------------------------
392 // MANAGEMENT
393 // ----------------------------------------------------------------------------
394 // Get State
395 // ----------------------------------------------------------------------------
396 
398 {
399 
400 
401  long ans = this->readObject(0x6041, 0x00);
402 
403  std::stringstream s;
404  s << "Estat: " << ans << " / std::dec= " <<std::dec<< ans;
405  p(s);
406 
407  // OBTENIR EL NUMERO D'ESTAT
408  bool bits[16];
409  bits[0]= (ans & 0x0001);
410  bits[1]= (ans & 0x0002);
411  bits[2]= (ans & 0x0004);
412  bits[3]= (ans & 0x0008);
413 
414  bits[4]= (ans & 0x0010);
415  bits[5]= (ans & 0x0020);
416  bits[6]= (ans & 0x0040);
417  bits[7]= (ans & 0x0080);
418 
419  bits[8]= ans & 0x0100;
420  bits[9]= ans & 0x0200;
421  bits[10]= ans & 0x0400;
422  bits[11]= ans & 0x0800;
423 
424  bits[12]= ans & 0x1000;
425  bits[13]= ans & 0x2000;
426  bits[14]= ans & 0x4000;
427  bits[15]= ans & 0x8000;
428 
429 
430 
431  #ifdef DEBUG
432  std::cout
433  << bits[15]
434  << bits[14]
435  << bits[13]
436  << bits[12]
437  << bits[11]
438  << bits[10]
439  << bits[9]
440  << bits[8]
441  << bits[7]
442  << bits[6]
443  << bits[5]
444  << bits[4]
445  << bits[3]
446  << bits[2]
447  << bits[1]
448  << bits[0]
449  << std::endl;
450  #endif
451 
452  if(bits[14]){
453  if(bits[4]){
454  p("State: Measure Init");
455  return(MEASURE_INIT);
456  }else{
457  p("State: Refresh");
458  return(REFRESH);
459  }
460  }else{
461  if(!bits[8]){
462  p("State: Start");
463  return(START);
464  }else{
465  if(bits[6]){
466  p("State: Switch on disabled");
467  return(SWITCH_ON_DISABLED);
468  }else{
469  if(bits[5]){
470  if(bits[4]){
471  p("State: Operation Enable");
472  return(OPERATION_ENABLE);
473  }else{
474  if(bits[1]){
475  p("State: Switched On");
476  return(SWITCH_ON);
477  }else{
478  p("State: Ready to Switch On");
479  return(READY_TO_SWITCH_ON);
480  }
481  }
482  }else{
483  if(!bits[3]){
484  if(bits[2]){
485  p("State: Quick Stop Active");
486  return(QUICK_STOP);
487  }else{
488  p("State: Not Ready to Switch On");
489  return(NOT_READY_TO_SWITCH_ON);
490  }
491  }else{
492  if(bits[4]){
493  p("State: Fault Reaction Active (Enabled)");
494  return(QUICK_STOP_ACTIVE_ENABLE);
495  }else{
496  if(bits[2]){
497  p("State: Fault Reaction Active (Disabled)");
499  }else{
500  p("State: Fault");
501  return(FAULT);
502  }
503  }
504  }
505  }
506  }
507  }
508  }
509  // Error
510  std::cout << this->searchErrorDescription( this->readError() ) << std::endl;
512 }
513 
514 // SHUTDOWN (transition)
515 // ----------------------------------------------------------------------------
516 
518 {
519  this->writeObject(0x6040, 0x00, 0x06);
520 }
521 
522 // SWITCH ON (transition)
523 // ----------------------------------------------------------------------------
524 
526 {
527  this->writeObject(0x6040, 0x00, 0x07);
528 }
529 
530 // DISABLE VOLTAGE (transition)
531 // ----------------------------------------------------------------------------
532 
534 {
535  this->writeObject(0x6040, 0x00, 0x00);
536 }
537 
538 // QUICK STOP (transition)
539 // ----------------------------------------------------------------------------
540 
542 {
543  this->writeObject(0x6040, 0x00, 0x02);
544 }
545 
546 // DISABLE OPERATION (transition)
547 // ----------------------------------------------------------------------------
548 
550 {
551  this->writeObject(0x6040, 0x00, 0x07);
552 }
553 
554 // ENABLE OPERATION (transition)
555 // ----------------------------------------------------------------------------
556 
558 {
559  this->writeObject(0x6040, 0x00, 0x0F);
560 }
561 
562 // FAULT RESET (transition)
563 // ----------------------------------------------------------------------------
564 
566 {
567  this->writeObject(0x6040, 0x00, 0x80);
568 }
569 
570 //----------------------------------------------------------------------------
571 // OPERATION MODES
572 // ----------------------------------------------------------------------------
573 // GET OPERATION MODE
574 // ----------------------------------------------------------------------------
575 
577 {
578  long ans = this->readObject(0x6061, 0x00);
579 
580  // Rectificacio
582  //ans = this->getNegativeLong(ans);
583 
584  return(ans);
585 }
586 
587 // GET OPERATION MODE DESCRIPTION
588 // ----------------------------------------------------------------------------
589 
590 std::string CEpos2::getOpModeDescription(long opmode)
591 {
592 
593  std::stringstream s;
594  std::string name;
595 
596  switch(opmode){
597  case VELOCITY:
598  name="Velocity";
599  break;
600  case POSITION:
601  name="Position";
602  break;
603  case PROFILE_POSITION:
604  name="Profile Position";
605  break;
606  case PROFILE_VELOCITY:
607  name="Profile Velocity";
608  break;
610  name="Interpolated Profile Position";
611  break;
612  case HOMING:
613  name="Homing";
614  break;
615  }
616 
617  return(name);
618 
619 }
620 
621 // SET OPERATION MODE
622 // ----------------------------------------------------------------------------
623 
624 void CEpos2::setOperationMode(long opmode)
625 {
626  this->writeObject(0x6060, 0x00,opmode);
627 }
628 
629 // ENABLE CONTROLLER
630 // ----------------------------------------------------------------------------
631 
633 {
634  int estat=0,timeout=0;
635  bool controller_connected = false;
636 
637  estat = this->getState();
638 
639  while( !controller_connected && timeout<10 )
640  {
641  switch(estat)
642  {
643  case 0:
644  // FAULT
645  this->faultReset();
646  timeout++;
647  break;
648  case 1:
649  // START
650  break;
651  case 2:
652  // NOT_READY_TO_SWITCH_ON
653  break;
654  case 3:
655  // SWITCH_ON_DISABLED
656  timeout++;
657  this->shutdown();
658  break;
659  case 4:
660  // READY_TO_SWITCH_ON
661  this->switchOn();
662  break;
663  case 5:
664  // SWITCH_ON
665  controller_connected = true;
666  break;
667  case 6:
668  // REFRESH
669  break;
670  case 7:
671  // MEASURE_INIT
672  break;
673  case 8:
674  // OPERATION_ENABLE
675  this->disableOperation();
676  break;
677  case 9:
678  // QUICK_STOP
679  this->disableVoltage();
680  break;
681  case 10:
682  // QUICK_STOP_ACTIVE_DISABLE
683  break;
684  case 11:
685  // QUICK_STOP_ACTIVE_ENABLE
686  break;
687  }
688  estat = this->getState();
689  }
690 
691 }
692 
693 // ENABLE MOTOR
694 // ----------------------------------------------------------------------------
695 
696 void CEpos2::enableMotor(long opmode)
697 {
698  int estat;
699 
700  estat = this->getState();
701 
702  if( estat == SWITCH_ON )
703  {
704  this->enableOperation();
705  }
706 
707  if( opmode != NO_OPERATION )
708  {
709  if( this->getOperationMode() != opmode )
710  {
711  this->setOperationMode(opmode);
712  }
713  }
714 }
715 
716 
717 // IS TARGET REACHED ? (Shared between modes)
718 // ----------------------------------------------------------------------------
719 
721 {
722 
723  long ans = this->readObject(0x6041, 0x00);
724  std::stringstream s;
725 
726  //s << "Estat: std::hex=" <<std::hex<< ans << " / std::dec=" <<std::dec << ans;
727  //this->p(s);
728  // OBTENIR EL NUMERO D'ESTAT
729 
730  // bit10 = 0 , not reached
731  // bit10 = 1 , reached
732 
733  return((bool)(ans & 0x0400));
734 }
735 
736 //----------------------------------------------------------------------------
737 // MODE VELOCITY
738 // ----------------------------------------------------------------------------
739 // GET TARGET VELOCITY
740 // ----------------------------------------------------------------------------
741 
743 {
744  return this->readObject(0x206B, 0x00);
745 }
746 
747 // SET TARGET VELOCITY
748 // ----------------------------------------------------------------------------
749 
750 void CEpos2::setTargetVelocity(long velocity)
751 {
752  this->writeObject(0x206B, 0x00,velocity);
753 }
754 
755 // START VELOCITY
756 // ----------------------------------------------------------------------------
757 
759 {
760  this->writeObject(0x6040, 0x00, 0x010f);
761 }
762 
763 // STOP VELOCITY
764 // ----------------------------------------------------------------------------
765 
767 {
768  // just velocity command = 0
769  this->writeObject(0x206B, 0x00,0x0000);
770 }
771 
772 //----------------------------------------------------------------------------
773 // MODE PROFILE VELOCITY
774 // ----------------------------------------------------------------------------
775 // GET TARGET PROFILE VELOCITY
776 // ----------------------------------------------------------------------------
777 
779 {
780 
781  return this->readObject(0x60FF, 0x00);
782 }
783 
784 // SET TARGET PROFILE VELOCITY
785 // ----------------------------------------------------------------------------
786 
788 {
789  this->writeObject(0x60FF, 0x00, velocity);
790 }
791 
792 // START PROFILE VELOCITY
793 // ----------------------------------------------------------------------------
794 
796 {
797  int intmode = 0x000F;
798 
799  this->writeObject(0x6040, 0x00,intmode);
800 }
801 
802 // STOP PROFILE VELOCITY
803 // ----------------------------------------------------------------------------
804 
806 {
807  int intmode = 0x010F;
808  this->writeObject(0x6040, 0x00,intmode);
809 }
810 
811 //----------------------------------------------------------------------------
812 // MODE PROFILE POSITION
813 // ----------------------------------------------------------------------------
814 // GET TARGET PROFILE POSITION
815 // ----------------------------------------------------------------------------
816 
818 {
819  return this->readObject(0x607A, 0x00);
820 }
821 
822 // SET TARGET PROFILE POSITION
823 // ----------------------------------------------------------------------------
824 
826 {
827  this->writeObject(0x607A, 0x00,position);
828 }
829 
830 // 0 halt, 1 abs, 2 rel
831 void CEpos2::startProfilePosition(epos_posmodes mode, bool blocking, bool wait, bool new_point)
832  {
833 
834  int halt = mode==HALT ? 0x0100 : 0x0000;
835  int rel = mode==RELATIVE ? 0x0040 : 0x0000;
836  int nowait = !wait ? 0x0020 : 0x0000;
837  int newsetpoint = new_point ? 0x0010 : 0x0000;
838 
839  int intmode = 0x000F | halt | rel | nowait | newsetpoint;
840 
841  this->writeObject(0x6040, 0x00,intmode);
842 
843  if( blocking ){
844 
845  while( !this->isTargetReached() )
846  {
847  if(this->verbose) this->getMovementInfo();
848  else usleep(1000);
849  }
850  }
851 
852 }
853 
854 
855 
856 // Current
857 
858 long CEpos2::getTargetCurrent(){return 1;}
859 
860 void CEpos2::setTargetCurrent(long current){}
861 
863 
865 
866 
867 
868 //----------------------------------------------------------------------------
869 // CONTROL PARAMETERS
870 // ----------------------------------------------------------------------------
871 
873 {
874  return this->readObject(0x60F6, 0x01);
875 }
876 
877 void CEpos2::setCurrentPGain(long gain)
878 {
879  this->writeObject(0x60F6, 0x01,gain);
880 }
881 
883 {
884  return this->readObject(0x60F6, 0x02);
885 }
886 
887 void CEpos2::setCurrentIGain(long gain)
888 {
889  this->writeObject(0x60F6, 0x02,gain);
890 }
891 
892 // Velocity
893 
895 {
896  return this->readObject(0x60F9, 0x01);
897 }
898 
900 {
901  this->writeObject(0x60F9, 0x01,gain);
902 }
903 
905 {
906  return this->readObject(0x60F9, 0x02);
907 }
908 
910 {
911  this->writeObject(0x60F9, 0x03,gain);
912 }
913 
915 {
916  return this->readObject(0x60F9, 0x03);
917 }
918 
920 {
921  this->writeObject(0x60F9, 0x03,gain);
922 }
923 
924 // Position
925 
927 {
928  return this->readObject(0x60FB, 0x01);
929 }
930 
932 {
933  this->writeObject(0x60FB, 0x01,gain);
934 }
935 
937 {
938  return this->readObject(0x60FB, 0x02);
939 }
940 
942 {
943  this->writeObject(0x60FB, 0x02,gain);
944 }
945 
947 {
948 
949  return this->readObject(0x60FB, 0x03);
950 }
951 
953 {
954  this->writeObject(0x60FB, 0x03,gain);
955 }
956 
958 {
959  return this->readObject(0x60FB, 0x04);
960 }
961 
963 {
964  this->writeObject(0x60FB, 0x04,gain);
965 }
966 
968 {
969  return this->readObject(0x60FB, 0x05);
970 }
971 
973 {
974  this->writeObject(0x60FB, 0x05,gain);
975 }
976 
977 void CEpos2::getControlParameters(long &cp,long &ci,long &vp,long &vi,
978  long &vspf, long &pp,long &pi,long &pd,
979  long &pv,long &pa)
980 {
981  cp = this->getCurrentPGain();
982  ci = this->getCurrentIGain();
983  vp = this->getVelocityPGain();
984  vi = this->getVelocityIGain();
985  vspf = this->getVelocitySetPointFactorPGain();
986  pp = this->getPositionPGain();
987  pi = this->getPositionIGain();
988  pd = this->getPositionDGain();
989  pv = this->getPositionVFFGain();
990  pa = this->getPositionAFFGain();
991 
992  if(this->verbose) this->printControlParameters(cp,ci,vp,vi,vspf,pp,pi,pd,pv,pa);
993 
994 }
995 
996 void CEpos2::setControlParameters(long cp,long ci,long vp,long vi,long vspf,
997  long pp,long pi,long pd,long pv,long pa)
998 {
999  this->setCurrentPGain(cp);
1000  this->setCurrentIGain(ci);
1001  this->setVelocityPGain(vp);
1002  this->setVelocityIGain(vi);
1003  this->setVelocitySetPointFactorPGain(vspf);
1004  this->setPositionPGain(pp);
1005  this->setPositionIGain(pi);
1006  this->setPositionDGain(pd);
1007  this->setPositionVFFGain(pv);
1008  this->setPositionAFFGain(pa);
1009 
1010 
1011  this->getControlParameters(cp,ci,vp,vi,vspf,pp,pi,pd,pv,pa);
1012 
1013 }
1014 
1015 void CEpos2::printControlParameters(long cp,long ci,long vp,long vi,long vspf,
1016  long pp,long pi,long pd,long pv,long pa)
1017 {
1018  std::cout << " [EPOS2] Control Parameters:" << std::endl;
1019  std::cout << " [EPOS2] Current: P = " << cp << " I = " << ci << std::endl;
1020  std::cout << " [EPOS2] Velocity: P = " << vp << " I = " << vi << " SetPointFactorP = " << vspf << std::endl;
1021  std::cout << " [EPOS2] Position: P = " << pp << " I = " << pi << " D = "<< pd << std::endl;
1022  std::cout << " [EPOS2] Vff = " << pv << " Aff = " << pa << std::endl;
1023 }
1024 
1025 //----------------------------------------------------------------------------
1026 // PROFILE PARAMETERS
1027 // ----------------------------------------------------------------------------
1028 
1030 {
1031  return this->readObject(0x6081, 0x00);
1032 }
1033 
1034 void CEpos2::setProfileVelocity(long velocity)
1035 {
1036  this->writeObject(0x6081, 0x00,velocity);
1037 }
1038 
1040 {
1041  return this->readObject(0x607F, 0x00);
1042 }
1043 
1045 {
1046  this->writeObject(0x607F, 0x00,velocity);
1047 }
1048 
1050 {
1051  return this->readObject(0x6083, 0x00);
1052 }
1053 
1054 void CEpos2::setProfileAcceleration(long acceleration)
1055 {
1056  this->writeObject(0x6083, 0x00,acceleration);
1057 }
1058 
1060 {
1061  return this->readObject(0x6084, 0x00);
1062 }
1063 
1064 void CEpos2::setProfileDeceleration(long deceleration)
1065 {
1066  this->writeObject(0x6084, 0x00,deceleration);
1067 }
1068 
1070 {
1071  return this->readObject(0x6085, 0x00);
1072 }
1073 
1074 void CEpos2::setProfileQuickStopDecel(long deceleration)
1075 {
1076  this->writeObject(0x6085, 0x00,deceleration);
1077 }
1078 
1080 {
1081  return this->readObject(0x6086, 0x00);
1082 }
1083 
1084 void CEpos2::setProfileType(long type)
1085 {
1086  this->writeObject(0x6086, 0x00,type);
1087 }
1088 
1090 {
1091  return this->readObject(0x60C5, 0x00);
1092 }
1093 
1094 void CEpos2::setMaxAcceleration(long max_acceleration)
1095 {
1096  this->writeObject(0x60C5, 0x00,max_acceleration);
1097 }
1098 
1099 void CEpos2::getProfileData(long &vel,long &maxvel,long &acc,long &dec,
1100  long &qsdec, long &maxacc, long &type)
1101 {
1102  vel = this->getProfileVelocity();
1103  maxvel = this->getProfileMaxVelocity();
1104  acc = this->getProfileAcceleration();
1105  dec = this->getProfileDeceleration();
1106  qsdec = this->getProfileQuickStopDecel();
1107  maxacc = this->getMaxAcceleration();
1108  type = this->getProfileType();
1109 }
1110 
1111 void CEpos2::setProfileData(long vel,long maxvel,long acc,long dec,
1112  long qsdec,long maxacc,long type)
1113 {
1114  this->setProfileVelocity(vel);
1115  this->setProfileMaxVelocity(maxvel);
1116  this->setProfileAcceleration(acc);
1117  this->setProfileDeceleration(dec);
1118  this->setProfileQuickStopDecel(qsdec);
1119  this->setMaxAcceleration(maxacc);
1120  this->setProfileType(type);
1121 
1122  long v,m,a,d,q,ma,t;
1123  this->getProfileData(v,m,a,d,q,ma,t);
1124 }
1125 
1126 //----------------------------------------------------------------------------
1127 // READ INFORMATION
1128 // ----------------------------------------------------------------------------
1129 
1131 {
1132  return this->readObject(0x2028, 0x00);
1133 }
1134 
1136 {
1137  return this->readObject(0x6069, 0x00);
1138 }
1139 
1141 {
1142  return this->readObject(0x606B, 0x00);
1143 }
1144 
1146 {
1147  return this->readObject(0x606C, 0x00);
1148 }
1149 
1151 {
1152  long ans = this->readObject(0x6078, 0x00);
1153  return this->getNegativeLong(ans);
1154 }
1155 
1157 {
1158  long ans = this->readObject(0x2027, 0x00);
1159  return this->getNegativeLong(ans);
1160 }
1161 
1163 {
1164  return this->readObject(0x2031, 0x00);
1165 }
1166 
1168 {
1169  return this->readObject(0x6064, 0x00);
1170 }
1171 
1173 {
1174  return this->readObject(0x6041, 0x00);
1175 }
1176 
1178 {
1179  return this->readObject(0x2020, 0x00);
1180 }
1181 
1183 {
1184  return this->readObject(0x2021, 0x00);
1185 }
1186 
1188 {
1189  return this->readObject(0x2022, 0x00);
1190 }
1191 
1193 {
1194  return this->readObject(0x20F4, 0x00);
1195 }
1196 
1198 {
1199  long vel_actual,vel_avg,vel_demand;
1200  int cur_actual,cur_avg,cur_demand;
1201  int32_t pos;
1202  bool verbose_status;
1203 
1204  verbose_status = this->verbose;
1205  this->setVerbose(false);
1206  vel_actual = this->readVelocityActual();
1207  vel_avg = this->readVelocity();
1208  vel_demand = this->readVelocityDemand();
1209 
1210  cur_actual = this->readCurrent();
1211  cur_avg = this->readCurrentAveraged();
1212  cur_demand = this->readCurrentDemanded();
1213 
1214  pos = this->readPosition();
1215  this->setVerbose(verbose_status);
1216 
1217  printf("\r [EPOS2] p: %ld v: %ld vavg: %ld vd: %ld c: %d cavg: %d cd: %d ",pos,vel_actual,vel_avg,vel_demand,cur_actual,cur_avg,cur_demand);
1218  fflush(stdout);
1219 
1220 }
1221 
1222 //----------------------------------------------------------------------------
1223 // ERRORS
1224 // ----------------------------------------------------------------------------
1225 
1227 {
1228  char error_num=0;
1229  std::stringstream s;
1230  long ans = this->readObject(0x1001, 0x00);
1231 
1232  bool bits[8];
1233  bits[0]= (ans & 0x0001);
1234  bits[1]= (ans & 0x0002);
1235  bits[2]= (ans & 0x0004);
1236  bits[3]= (ans & 0x0008);
1237 
1238  bits[4]= (ans & 0x0010);
1239  bits[5]= (ans & 0x0020);
1240  bits[7]= (ans & 0x0080);
1241 
1242  if(bits[7]) error_num=6; // Motion Error
1243  if(bits[5]) error_num=5; // Device profile specific
1244  if(bits[4]) error_num=4; // Communication Error
1245 
1246  if(bits[3]) error_num=3; // Temperature Error
1247  if(bits[2]) error_num=2; // Voltage Error
1248  if(bits[1]) error_num=1; // Current Error
1249  if(bits[0]) error_num=0; // Generic Error
1250 
1251  s << "Error: "<< error_num << " " << this->error_names[(unsigned char)error_num] <<
1252  " Value: 0x" <<std::hex<< ans << " , " <<std::dec<< ans;
1253  p(s);
1254 
1255  return(error_num);
1256 }
1257 
1258 void CEpos2::readErrorHistory(long *error[5])
1259 {
1260  std::string error_des;
1261 
1262  long number_errors = this->readObject(0x1003, 0x00);
1263  std::cout << " [EPOS2-ERROR] Number of Errors: " << number_errors << std::endl;
1264 
1265  // Read Errors
1266  for(int i=1;i<=number_errors;i++){
1267  long ans = this->readObject(0x1003, i);
1268  error[i] = &ans;
1269  error_des = this->searchErrorDescription(ans);
1270 
1271  std::cout << " [EPOS2-ERROR] id: " << i << " : " << std::hex <<"0x"<< ans << " = " << error_des << std::endl;
1272  }
1273 }
1274 
1275 std::string CEpos2::searchErrorDescription(long error_code)
1276 {
1277  int j=0;
1278  bool found = false;
1279  std::stringstream s;
1280 
1281  // error_codes length = 34
1282 
1283  while( !found && j < 34 ){
1284  if( error_code == this->error_codes[j] ){
1285  found = true;
1286 
1287  s << "Error Description "<< this->error_descriptions[j] << std::endl;
1288  p(s);
1289  return this->error_descriptions[j];
1290 
1291  }else{
1292  j++;
1293  }
1294  }
1295  if(!found) return "No Description for this error";
1296  else return "Error Description";
1297 }
1298 
1299 //----------------------------------------------------------------------------
1300 // VERSIONS
1301 // ----------------------------------------------------------------------------
1302 
1304 {
1305  return this->readObject(0x2003, 0x01);
1306 }
1307 
1309 {
1310  return this->readObject(0x2003, 0x02);
1311 }
1312 
1313 
1314 
1315  // SENSOR CONFIGURATION
1316 
1318 {
1319  return this->readObject(0x2210, 0x01);
1320 }
1321 
1323 {
1324  this->writeObject(0x2210, 0x01, pulses);
1325 }
1326 
1328 {return 1;}
1329 
1330 void CEpos2::setEncoderType(long type)
1331 {}
1332 
1334 {return 1;}
1335 
1336 void CEpos2::setEncoderPolarity(long polarity)
1337 {}
1338 
1339 void CEpos2::getEncoderParameters(long &pulses, long &type, long &polarity)
1340 {}
1341 
1342 void CEpos2::setEncoderParameters(long pulses, long type, long polarity)
1343 {}
1344 
1345 // Motor
1346 
1347 long CEpos2::getMotorType(){return 1;}
1348 
1349 void CEpos2::setMotorType(long type){}
1350 
1352 
1354 
1356 
1357 void CEpos2::setMotorOutputCurrentLimit(long current_mA){}
1358 
1360 
1361 void CEpos2::setMotorPolePairNumber(char pole_pairs){}
1362 
1364 
1366 
1367 //----------------------------------------------------------------------------
1368 // UTILITIES
1369 // ----------------------------------------------------------------------------
1370 
1372 {
1373  return this->readObject(0x6065, 0x00);
1374 }
1375 
1377 {
1378  this->writeObject(0x6065, 0x00,error);
1379 }
1380 
1382 {
1383  return this->readObject(0x607D, 0x01);
1384 }
1385 
1387 {
1388  this->writeObject(0x607D, 0x01,limit);
1389 }
1390 
1391 
1393 {
1394  return this->readObject(0x607D, 0x02);
1395 }
1396 
1398 {
1399  this->writeObject(0x607D, 0x02,limit);
1400 }
1401 
1403 {
1404  // min
1405  // -2147483647-1
1406  this->writeObject(0x607D, 0x01, -2147483647-1);
1407  // max
1408  this->writeObject(0x607D, 0x02, 2147483647);
1409 }
1410 
1411 long CEpos2::getPositionWindow(){return 1;}
1412 
1413 void CEpos2::setPositionWindow(long window_qc){}
1414 
1416 
1417 void CEpos2::setPositionWindowTime(long time_ms){}
1418 
1419 long CEpos2::getVelocityWindow(){return 1;}
1420 
1421 void CEpos2::setVelocityWindow(long window_rm){}
1422 
1424 
1425 void CEpos2::setVelocityWindowTime(long time_ms){}
1426 
1428 
1430 
1432 
1434 
1436 
1438 
1440 
1442 
1444 
1446 
1448 
1450 
1451 
1453 {
1454  this->writeObject(0x1010, 0x01, 0x65766173);
1455 
1456 }
1457 
1459 {
1460  this->writeObject(0x1011, 0x01, 0x64616F6C);
1461 
1462 }
1463 
1465 {
1466  return this->readObject(0x2002, 0x00);
1467 }
1468 
1469 void CEpos2::setRS232Baudrate(long baudrate)
1470 {
1471  this->writeObject(0x2002, 0x00, baudrate);
1472 }
1473 
1475 {
1476  return this->readObject(0x2005, 0x00);
1477 }
1478 
1480 {
1481  this->writeObject(0x2005, 0x00, timeout);
1482 }
1483 
1485 {
1486  return this->readObject(0x2006, 0x00);
1487 }
1488 
1489 void CEpos2::setUSBFrameTimeout(long timeout)
1490 {
1491  this->writeObject(0x2006, 0x00, timeout);
1492 }
1493 
1494 long CEpos2::getNegativeLong(long positiu)
1495 {
1496  if(positiu>32767){
1497  return(positiu-65536);
1498  }else{
1499  return(positiu);
1500  }
1501 }
1502 
1503 
1504 // ############################# I/O ######################################
1505 
1506 long CEpos2::getAnalogOutput1(){return 1;}
1507 
1508 void CEpos2::setAnalogOutput1(long voltage_mV){}
1509 
1510 // ############################# MARKER POSITION ##########################
1511 
1513 {
1514  int obj;
1515  switch(buffer)
1516  {
1517  case 0:
1518  obj = 1;
1519  break;
1520  case 1:
1521  obj = 5;
1522  break;
1523  case 2:
1524  obj = 6;
1525  break;
1526  }
1527  return this->readObject(0x2074, obj);
1528 }
1529 
1530 void CEpos2::setPositionMarker(char mode, char polarity, char edge_type, char digitalIN)
1531 {
1532  // set the digital input as position marker & options
1533  this->writeObject(0x2070, digitalIN, 4);
1534  // mask (which functionalities are active) (bit 3 0x0008)
1535  this->writeObject(0x2071, 0x02, 0x0008);
1536  // execution (if set the function executes) (bit 3 0x0008)
1537  this->writeObject(0x2071, 0x04, 0x0008);
1538 
1539  // options
1540  this->writeObject(0x2071, 0x03, polarity);
1541  this->writeObject(0x2074, 0x02, edge_type);
1542  this->writeObject(0x2074, 0x03, mode);
1543 
1544 }
1545 
1547 {
1548  long markpos = this->getPositionMarker();
1549 
1550  while(markpos == this->getPositionMarker())
1551  {
1552  // minimum freq = 0.05s = 20Hz
1553  usleep(1000000*0.05);
1554  }
1555 }
1556 
1557 
1558 // ############################# HOMING ###################################
1559 
1560 
1561 
1562 void CEpos2::setHoming(int home_method, int speed_pos, int speed_zero,
1563  int acc, int digitalIN)
1564 {
1565  // set digital input as home switch
1566  this->writeObject(0x2070, digitalIN, 3);
1567  // mask
1568  this->writeObject(0x2071, 0x02, 0x0004);
1569  this->writeObject(0x2071, 0x04, 0x000C);
1570  // options
1571  this->writeObject(0x6098, 0x00, home_method);
1572  this->writeObject(0x6099, 0x01, speed_pos);
1573  this->writeObject(0x6099, 0x02, speed_zero);
1574  this->writeObject(0x609A, 0x00, acc);
1575 }
1576 
1578 {
1579  this->writeObject(0x6040, 0x00, 0x001F);
1580  if(blocking)
1581  {
1582  while(!this->isTargetReached())
1583  usleep(1000000*0.05);
1584  }
1585 }
1586 
1588 {
1589  this->writeObject(0x6040, 0x00, 0x010F);
1590 }
1591 
1592 // ############################# DIG IN ###################################
1593 
1594 
1595 
1596 
1597 
1598 int CEpos2::getDigInState(int digitalIN)
1599 {
1600  return this->readObject(0x2070, digitalIN);
1601 }
1602 
1604 {
1605  return this->readObject(0x2071, 0x01);
1606 }
1607 
1609 {
1610  return this->readObject(0x2071, 0x02);
1611 }
1612 
1614 {
1615  return this->readObject(0x2071, 0x03);
1616 }
1617 
1619 {
1620  return this->readObject(0x2071, 0x04);
1621 }
1622 
1623 
1624 // deprecated
1625 
1626 
1627 void CEpos2::setHomePosition(long home_position_qc)
1628 {
1629  this->writeObject(0x2081, 0x00,home_position_qc);
1630 }
1632 {
1633  return this->readObject(0x2081, 0x00);
1634 }
1635 
1637 {
1638  char c;
1639  int32_t home_pos=0;
1640 
1641  long mode_anterior = this->getOperationMode();
1642  this->disableOperation();
1643  std::cout << " [EPOS2] Move Load to 0 position and press a key ";
1644  std::cin >> c;
1645  std::cout << std::endl;
1646  std::cout << " [EPOS2] Wait until process finishes" << std::endl;
1647  this->enableOperation();
1648  home_pos = this->readPosition();
1649  this->setOperationMode(HOMING);
1650  this->getOperationMode();
1651  this->setHomePosition(home_pos);
1652  this->getHomePosition();
1653  this->setOperationMode(mode_anterior);
1654  this->getOperationMode();
1655  std::cout << " [EPOS2] Restart EPOS2 (unplug from current) after that the new home will be set" << std::endl;
1656 }
1657 
1658 const std::string CEpos2::error_names[] = {
1659  "Generic Error",
1660  "Current Error",
1661  "Voltage Error",
1662  "Temperature Error",
1663  "Communication Error",
1664  "Device profile specific",
1665  "Motion Error"
1666 };
1667 
1668 const int CEpos2::error_codes[]={
1669  0x0000,
1670  0x1000,
1671  0x2310,
1672  0x3210,
1673  0x3220,
1674  0x4210,
1675  0x5113,
1676  0x5114,
1677  0x6100,
1678  0x6320,
1679  0x7320,
1680  0x8110,
1681  0x8111,
1682  0x8120,
1683  0x8130,
1684  0x8150,
1685  0x81FD,
1686  0x81FE,
1687  0x81FF,
1688  0x8210,
1689  0x8611,
1690  0xFF01,
1691  0xFF02,
1692  0xFF03,
1693  0xFF04,
1694  0xFF05,
1695  0xFF06,
1696  0xFF07,
1697  0xFF08,
1698  0xFF09,
1699  0xFF0A,
1700  0xFF0B,
1701  0xFF0C,
1702  0xFF0D
1703 };
1704 
1705 const std::string CEpos2::error_descriptions[]={
1706  "No Error",
1707  "Generic Error",
1708  "Over Current Error",
1709  "Over Voltage Error",
1710  "Under Voltage",
1711  "Over Temperature",
1712  "Supply Voltage (+5V) Too Low",
1713  "Supply Voltage Output Stage Too Low",
1714  "Internal Software Error",
1715  "Software Parameter Error",
1716  "Sensor Position Error",
1717  "CAN Overrun Error (Objects lost)",
1718  "CAN Overrun Error",
1719  "CAN Passive Mode Error",
1720  "CAN Life Guard Error",
1721  "CAN Transmit COB-ID collision",
1722  "CAN Bus Off",
1723  "CAN Rx Queue Overrun",
1724  "CAN Tx Queue Overrun",
1725  "CAN PDO length Error",
1726  "Following Error",
1727  "Hall Sensor Error",
1728  "Index Processing Error",
1729  "Encoder Resolution Error",
1730  "Hallsensor not found Error",
1731  "Negative Limit Error",
1732  "Positive Limit Error",
1733  "Hall Angle detection Error",
1734  "Software Position Limit Error",
1735  "Position Sensor Breach",
1736  "System Overloaded",
1737  "Interpolated Position Mode Error",
1738  "Autotuning Identification Error"
1739 };
long getState()
function to get current controller&#39;s state
Definition: Epos2.cpp:397
void setCurrentPGain(long gain)
function to set P Current Gain
Definition: Epos2.cpp:877
void setVelocityIGain(long gain)
function to set I Velocity Gain
Definition: Epos2.cpp:909
long getPositionAFFGain()
function to get Acceleration Feed Forward Position Gain
Definition: Epos2.cpp:967
long readStatusWord()
function to read EPOS2 StatusWord
Definition: Epos2.cpp:1172
long getPositionWindowTime()
function to get Position Window Time
Definition: Epos2.cpp:1415
long getThermalTimeCtWinding()
function to GET Motor Thermal Time Constant Winding
Definition: Epos2.cpp:1363
char readError()
function to read an Error information
Definition: Epos2.cpp:1226
void disableOperation()
function to reach switch_on and disables power on motor
Definition: Epos2.cpp:549
void startProfilePosition(epos_posmodes mode, bool blocking=true, bool wait=true, bool new_point=true)
function to move the motor to a position in profile position mode
Definition: Epos2.cpp:831
void setHomePosition(long home_position_qc)
function to set a Home position
Definition: Epos2.cpp:1627
long readCurrentDemanded()
function to read current demanded
Definition: Epos2.cpp:1162
long getMaxAcceleration(void)
function to GET Max Acceleration
Definition: Epos2.cpp:1089
void getControlParameters(long &cp, long &ci, long &vp, long &vi, long &vspf, long &pp, long &pi, long &pd, long &pv, long &pa)
function to get all control parameters
Definition: Epos2.cpp:977
void waitPositionMarker()
wait for marker position reached
Definition: Epos2.cpp:1546
bool blocking
Definition: configtest.cpp:59
void enableMotor(long opmode)
function to facititate transitions from switched on to operation enabled
Definition: Epos2.cpp:696
void setPositionMarker(char polarity=0, char edge_type=0, char mode=0, char digitalIN=2)
Sets the configuration of a marker position.
Definition: Epos2.cpp:1530
void setMinPositionLimit(long limit)
function to SET the Min Position Limit
Definition: Epos2.cpp:1386
long readVelocitySensorActual()
function to read velocity sensor actual
Definition: Epos2.cpp:1135
void setPositionWindow(long window_qc)
function to set Position Window
Definition: Epos2.cpp:1413
void setPositionWindowTime(long time_ms)
function to set Position Window Time
Definition: Epos2.cpp:1417
int getDigInExecutionMask()
Gives Digital Inputs Execution Mask.
Definition: Epos2.cpp:1618
long getMaxFollowingError()
function to GET the Max Following Error
Definition: Epos2.cpp:1371
void setVelocitySetPointFactorPGain(long gain)
function to SET Speed Regulator Set Point Factor P Velocity Gain
Definition: Epos2.cpp:919
void setRS232Baudrate(long baudrate)
function to SET the RS232 Baudrate
Definition: Epos2.cpp:1469
void getEncoderParameters(long &pulses, long &type, long &polarity)
function to GET encoder parameters
Definition: Epos2.cpp:1339
long getUSBFrameTimeout()
function to GET the USB Frame Timeout
Definition: Epos2.cpp:1484
long getPositionDimensionIndex()
function to get Position Dimension Index
Definition: Epos2.cpp:1439
long getPositionNotationIndex()
function to get Position Notation Index
Definition: Epos2.cpp:1427
void shutdown()
function to reach ready_to_switch_on state
Definition: Epos2.cpp:517
void getProfileData(long &vel, long &maxvel, long &acc, long &dec, long &qsdec, long &maxacc, long &type)
function to GET all data of the velocity profile
Definition: Epos2.cpp:1099
int16_t computeChecksum(int16_t *pDataArray, int16_t numberOfWords)
function to compute EPOS2 checksum
Definition: Epos2.cpp:366
static Ftdi::Context ftdi
a reference to the FTDI USB device
Definition: Epos2.h:80
int32_t readObject(int16_t index, int8_t subindex)
function to read an object from the EPOS2
Definition: Epos2.cpp:123
long getMinPositionLimit()
function to GET the Min Position Limit
Definition: Epos2.cpp:1381
long readEncoderCounterAtIndexPulse()
function to read the Encoder Counter at index pulse
Definition: Epos2.cpp:1182
long getEncoderPulseNumber()
function to GET the Encoder Pulses
Definition: Epos2.cpp:1317
int getDigInPolarity()
Gives Digital Inputs Polarity Mask.
Definition: Epos2.cpp:1613
long getVelocityPGain()
function to get P Velocity Gain
Definition: Epos2.cpp:894
void setPositionNotationIndex(long notation)
function to set Position Notation Index
Definition: Epos2.cpp:1429
void readErrorHistory(long *error[5])
function to read last 5 errors
Definition: Epos2.cpp:1258
void setAnalogOutput1(long voltage_mV)
function to set analog output 1
Definition: Epos2.cpp:1508
void setMotorType(long type)
function to SET Motor type
Definition: Epos2.cpp:1349
~CEpos2()
Destructor.
Definition: Epos2.cpp:39
void setMaxPositionLimit(long limit)
function to SET the Max Position Limit
Definition: Epos2.cpp:1397
long getMotorType()
function to GET Motor type
Definition: Epos2.cpp:1347
void startCurrent()
[OPMODE=current] function to move the motor in current mode
Definition: Epos2.cpp:862
long getPositionIGain()
function to get I Position Gain
Definition: Epos2.cpp:936
void setPositionDGain(long gain)
function to set D Position Gain
Definition: Epos2.cpp:952
long getTargetProfileVelocity()
[OPMODE=profile_velocity] function to get the velocity
Definition: Epos2.cpp:778
void switchOn()
function to reach switch_on state
Definition: Epos2.cpp:525
bool getVerbose()
Definition: Epos2.cpp:82
void setAccelerationDimensionIndex(long Dimension)
function to set Acceleration Dimension Index
Definition: Epos2.cpp:1449
long getProfileQuickStopDecel(void)
function to GET the Quick Stop Deceleration in profile
Definition: Epos2.cpp:1069
static const std::string error_names[]
Strings of generic error descriptions.
Definition: Epos2.h:1148
void setVerbose(bool verbose)
Definition: Epos2.cpp:90
void setOperationMode(long opmode)
function to set the operation mode
Definition: Epos2.cpp:624
void setVelocityNotationIndex(long notation)
function to set Velocity Notation Index
Definition: Epos2.cpp:1433
void enableOperation()
function to reach operation_enable state and enables power on motor
Definition: Epos2.cpp:557
epos_posmodes
Definition: Epos2.h:341
long getProfileMaxVelocity(void)
function to GET the Max Velocity allowed in Profile
Definition: Epos2.cpp:1039
void setMaxAcceleration(long max_acceleration)
function to SET Max Acceleration
Definition: Epos2.cpp:1094
int8_t node_id
Definition: Epos2.h:65
long readCurrent()
function to read motor current
Definition: Epos2.cpp:1150
long getNegativeLong(long number)
function to make a unsigned long signed
Definition: Epos2.cpp:1494
void setProfileType(long type)
function to SET the type in profile
Definition: Epos2.cpp:1084
void setVelocityWindow(long window_rm)
function to set Velocity Window
Definition: Epos2.cpp:1421
long readVersionSoftware()
function to read the software version
Definition: Epos2.cpp:1303
int getDigInStateMask()
Gives Digital Inputs State Mask.
Definition: Epos2.cpp:1603
void setThermalTimeCtWinding(long time_ds)
function to SET Motor Thermal Time Constant Winding
Definition: Epos2.cpp:1365
long getAccelerationDimensionIndex()
function to get Acceleration Dimension Index
Definition: Epos2.cpp:1447
void setPositionAFFGain(long gain)
function to set Acceleration Feed Forward Position Gain
Definition: Epos2.cpp:972
void setVelocityWindowTime(long time_ms)
function to set Velocity Window Time
Definition: Epos2.cpp:1425
long getAnalogOutput1()
function to get the value in the Analog Output1
Definition: Epos2.cpp:1506
long readVelocityDemand()
function to read velocity demand
Definition: Epos2.cpp:1140
long getProfileAcceleration(void)
function to GET the Acceleration in profile
Definition: Epos2.cpp:1049
void setRS232FrameTimeout(long timeout)
function to SET the RS232 Frame Timeout
Definition: Epos2.cpp:1479
int writeObject(int16_t index, int8_t subindex, int32_t data)
function to write an object to the EPOS2
Definition: Epos2.cpp:158
long getRS232Baudrate()
function to GET the RS232 Baudrate
Definition: Epos2.cpp:1464
void faultReset()
function to reach switch_on_disabled state after a FAULT
Definition: Epos2.cpp:565
void setTargetProfileVelocity(long velocity)
[OPMODE=profile_velocity] function to set the velocity
Definition: Epos2.cpp:787
void disablePositionLimits(void)
function to DISABLE Position Limits
Definition: Epos2.cpp:1402
void setAccelerationNotationIndex(long notation)
function to set Acceleration Notation Index
Definition: Epos2.cpp:1437
long readHallsensorPattern()
function to read the Hall Sensor Pattern
Definition: Epos2.cpp:1187
long getPositionPGain()
function to get P Position Gain
Definition: Epos2.cpp:926
void setPositionPGain(long gain)
function to set P Position Gain
Definition: Epos2.cpp:931
void setCurrentIGain(long gain)
function to set I Current Gain
Definition: Epos2.cpp:887
void setProfileDeceleration(long deceleration)
function to SET the Deceleration in profile
Definition: Epos2.cpp:1064
long getProfileType(void)
function to GET the type in profile
Definition: Epos2.cpp:1079
std::string getOpModeDescription(long opmode)
function to show the name of the operation mode
Definition: Epos2.cpp:590
void printControlParameters(long cp, long ci, long vp, long vi, long vspf, long pp, long pi, long pd, long pv, long pa)
function to show all control parameters
Definition: Epos2.cpp:1015
long getVelocitySetPointFactorPGain()
function to GET Speed Regulator Set Point Factor P Velocity Gain
Definition: Epos2.cpp:914
static const std::string error_descriptions[]
error descriptions
Definition: Epos2.h:1154
void setMotorContinuousCurrentLimit(long current_mA)
function to SET Motor Continous Current Limit
Definition: Epos2.cpp:1353
long getOperationMode()
function to know which operation mode is set
Definition: Epos2.cpp:576
void setUSBFrameTimeout(long timeout)
function to SET the USB Frame Timeout
Definition: Epos2.cpp:1489
long readCurrentAveraged()
function to read motor averaged current
Definition: Epos2.cpp:1156
void startVelocity()
function to move the motor in Velocity mode
Definition: Epos2.cpp:758
void stopProfileVelocity()
[OPMODE=profile_velocity] function to stop the motor
Definition: Epos2.cpp:805
static bool ftdi_initialized
Definition: Epos2.h:81
long getVelocityWindowTime()
function to get Velocity Window Time
Definition: Epos2.cpp:1423
void restoreDefaultParameters()
function to restore default parameters of EPOS2.
Definition: Epos2.cpp:1458
long getCurrentPGain()
function to get P Current Gain
Definition: Epos2.cpp:872
std::string searchErrorDescription(long error_code)
given an error code it returns its description
Definition: Epos2.cpp:1275
void setProfileMaxVelocity(long velocity)
function to SET the Max Velocity allowed in Profile
Definition: Epos2.cpp:1044
void enableController()
function to facititate transitions from the start of the controller to switch it on ...
Definition: Epos2.cpp:632
long getVelocityNotationIndex()
function to get Velocity Notation Index
Definition: Epos2.cpp:1431
void saveParameters()
function to save all parameters in EEPROM
Definition: Epos2.cpp:1452
void stopCurrent()
[OPMODE=current] function to stop the motor in current mode
Definition: Epos2.cpp:864
long getHomePosition()
function to get the Home position
Definition: Epos2.cpp:1631
void close()
Disconnects hardware.
Definition: Epos2.cpp:58
void quickStop()
function to reach switch_on state
Definition: Epos2.cpp:541
void sendFrame(int16_t *frame)
function send a frame to EPOS2
Definition: Epos2.cpp:186
void disableVoltage()
function to reach switch_on_disabled state
Definition: Epos2.cpp:533
void setTargetCurrent(long current)
[OPMODE=current] function to SET the target current
Definition: Epos2.cpp:860
void setPositionVFFGain(long gain)
function to set Velocity Feed Forward Position Gain
Definition: Epos2.cpp:962
void init()
Connects hardware.
Definition: Epos2.cpp:49
void p(const char *text)
function to make a unsigned long signed
Definition: Epos2.cpp:74
long getProfileDeceleration(void)
function to GET the Deceleration in profile
Definition: Epos2.cpp:1059
void setHome()
function to set a Home position with user interaction
Definition: Epos2.cpp:1636
long getProfileVelocity(void)
function to GET the velocity of the Velocity Profile
Definition: Epos2.cpp:1029
void setProfileVelocity(long velocity)
function to SET the velocity of the Velocity Profile
Definition: Epos2.cpp:1034
bool verbose
Definition: Epos2.h:165
long getTargetProfilePosition()
function to GET the target position
Definition: Epos2.cpp:817
long readVersionHardware()
function to read the hardware version
Definition: Epos2.cpp:1308
long readEncoderCounter()
function to read the Encoder Counter
Definition: Epos2.cpp:1177
void receiveFrame(uint16_t *ans_frame)
function receive a frame from EPOS2
Definition: Epos2.cpp:229
long getVelocityDimensionIndex()
function to get Velocity Dimension Index
Definition: Epos2.cpp:1443
long getMotorContinuousCurrentLimit()
function to GET Motor Continous Current Limit
Definition: Epos2.cpp:1351
long readFollowingError()
function to read the Following Error
Definition: Epos2.cpp:1192
long getAccelerationNotationIndex()
function to get Acceleration Notation Index
Definition: Epos2.cpp:1435
void setVelocityPGain(long gain)
function to set P Velocity Gain
Definition: Epos2.cpp:899
long getMaxPositionLimit()
function to GET the Max Position Limit
Definition: Epos2.cpp:1392
CEpos2(int8_t nodeId=0x00)
Constructor.
Definition: Epos2.cpp:33
void setMotorOutputCurrentLimit(long current_mA)
function to SET Motor Output Current Limit
Definition: Epos2.cpp:1357
long getCurrentIGain()
function to get I Current Gain
Definition: Epos2.cpp:882
int32_t readPosition()
function to read motor position
Definition: Epos2.cpp:1167
void setProfileAcceleration(long acceleration)
function to SET the Acceleration in profile
Definition: Epos2.cpp:1054
void setPositionIGain(long gain)
function to set I Position Gain
Definition: Epos2.cpp:941
long getPositionDGain()
function to get D Position Gain
Definition: Epos2.cpp:946
void setProfileQuickStopDecel(long deceleration)
function to SET the Quick Stop Deceleration in profile
Definition: Epos2.cpp:1074
long getPositionVFFGain()
function to get Velocity Feed Forward Position Gain
Definition: Epos2.cpp:957
void setEncoderPulseNumber(long pulses)
function to SET the Encoder Pulses
Definition: Epos2.cpp:1322
void setProfileData(long vel, long maxvel, long acc, long dec, long qsdec, long maxacc, long type)
function to SET all data of the velocity profile
Definition: Epos2.cpp:1111
void setHoming(int home_method=11, int speed_pos=100, int speed_zero=100, int acc=1000, int digitalIN=2)
Sets the configuration of a homing operation.
Definition: Epos2.cpp:1562
long getMotorPolePairNumber()
function to GET Motor Pole Pair Number
Definition: Epos2.cpp:1359
void setPositionDimensionIndex(long Dimension)
function to set Position Dimension Index
Definition: Epos2.cpp:1441
void stopVelocity()
function to stop the motor in velocity mode
Definition: Epos2.cpp:766
void stopHoming()
stops a homing operation
Definition: Epos2.cpp:1587
void setControlParameters(long cp, long ci, long vp, long vi, long vspf, long pp, long pi, long pd, long pv, long pa)
function to set all control parameters
Definition: Epos2.cpp:996
void setTargetVelocity(long velocity)
function to SET the target velocity
Definition: Epos2.cpp:750
long readVelocity()
function to read motor average velocity
Definition: Epos2.cpp:1130
void startProfileVelocity()
[OPMODE=profile_velocity] function to move the motor in a velocity
Definition: Epos2.cpp:795
void openDevice()
open EPOS2 device using CFTDI
Definition: Epos2.cpp:105
void setMotorPolePairNumber(char pole_pairs)
function to SET Motor Pole Pair Number
Definition: Epos2.cpp:1361
long getTargetVelocity()
function to GET the target velocity This function gets the target velocity of velocity operation mode...
Definition: Epos2.cpp:742
void setEncoderType(long type)
function to SET the Encoder type
Definition: Epos2.cpp:1330
void setEncoderPolarity(long polarity)
function to SET the Encoder polarity
Definition: Epos2.cpp:1336
void setMaxFollowingError(long follerror)
function to SET the Max Following Error
Definition: Epos2.cpp:1376
void doHoming(bool blocking=false)
starts a homing operation
Definition: Epos2.cpp:1577
int getDigInFuncMask()
Gives Digital Inputs Functionalities Mask.
Definition: Epos2.cpp:1608
bool isTargetReached()
function to know if the motor has reached the target position or velocity
Definition: Epos2.cpp:720
void setVelocityDimensionIndex(long Dimension)
function to set Velocity Dimension Index
Definition: Epos2.cpp:1445
void setEncoderParameters(long pulses, long type, long polarity)
function to SET encoder parameters
Definition: Epos2.cpp:1342
long getPositionWindow()
function to get Position Window
Definition: Epos2.cpp:1411
long readVelocityActual()
function to read velocity sensor actual
Definition: Epos2.cpp:1145
long getTargetCurrent()
[OPMODE=current] function to GET the target current
Definition: Epos2.cpp:858
long getMotorOutputCurrentLimit()
function to GET Motor Output Current Limit
Definition: Epos2.cpp:1355
long getVelocityWindow()
function to get Velocity Window
Definition: Epos2.cpp:1419
long getEncoderPolarity()
function to GET the Encoder Pulses
Definition: Epos2.cpp:1333
void getMovementInfo()
prints information about movement
Definition: Epos2.cpp:1197
int getDigInState(int digitalIN=2)
Gives the state of a certain digital Input.
Definition: Epos2.cpp:1598
long getVelocityIGain()
function to get I Velocity Gain
Definition: Epos2.cpp:904
long getEncoderType()
function to GET the Encoder Pulses
Definition: Epos2.cpp:1327
void setTargetProfilePosition(long position)
function to SET the target position
Definition: Epos2.cpp:825
long getRS232FrameTimeout()
function to GET the RS232 Frame Timeout
Definition: Epos2.cpp:1474
long getPositionMarker(int buffer=0)
gets the position marked by the sensor
Definition: Epos2.cpp:1512
static const int error_codes[]
error integer codes
Definition: Epos2.h:1151


epos2_motor_controller
Author(s): Martí Morta Garriga , Jochen Sprickerhof
autogenerated on Mon Feb 28 2022 22:16:44