test_like_h3d.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 // This file is part of IRI EPOS2 Driver
6 // IRI EPOS2 Driver is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #include <stdio.h>
20 #include <unistd.h>
21 
22 #include <iostream>
23 #include <sstream>
24 #include "ctime.h"
25 #include "log.h"
26 #include "Epos2.h"
27 
28 using namespace std;
29 
37 int main(void){
38 
39  CEpos2 controller;
40  CLog john("test_like_h3d");
41 
42  cout << "Epos2 Like H3D:" << endl;
43 
44  double avg=0,total_avg=0,max_avg=0,min_avg=0;
45  int total_seconds=20;//3*60;
46 
47  try{
48 
49  controller.init();
50 
51  // enable motor in velocity mode
52  controller.enableController();
53  controller.enableMotor(controller.VELOCITY);
54  controller.setOperationMode(controller.VELOCITY);
55  //controller.setVerbose(true);
56 
57  controller.setTargetVelocity(350);
58 
59  // start the movement
60  controller.startVelocity();
61  CTime tbase,telapsed,t0,t1,tavg;
62  int32_t pos=0;
63  stringstream text;
64  int k=0;
65 
66  telapsed.setFormat(ctf_ms);
67 
68  do{
69 
70  t0.set();
71  pos = controller.readPosition();
72  t1.set();
73  tavg = t1-t0;
74  avg = tavg.getTimeInSeconds();
75  telapsed = (t1+t0)/2 - tbase;
76  cout << ">>> " << telapsed.getTimeInSeconds() << " " << pos << endl;
77 
78  if(total_avg==0)
79  total_avg = avg;
80  else
81  total_avg = (total_avg + avg)/2;
82 
83  max_avg = max(max_avg,avg);
84  min_avg = min(min_avg,avg);
85 
86  telapsed.set();
87  telapsed = telapsed - tbase;
88 
89  if( telapsed.getTimeInSeconds() > 5*k )
90  {
91  cout << telapsed << endl;
92  k++;
93  }
94  //usleep(100*1000);
95 
96  }while( telapsed.getTimeInSeconds() < total_seconds);
97 
98  cout << "End" << endl;
99 
100  controller.stopVelocity();
101 
102  controller.close();
103 
104  }catch(CException &e){
105  controller.close();
106  cout << e.what() << endl;
107  }
108 
109  cout <<
110  " t avg: " << total_avg <<
111  " t min: " << min_avg <<
112  " t max: " << max_avg << endl;
113 
114  return 1;
115 
116 }
117 
void enableMotor(long opmode)
function to facititate transitions from switched on to operation enabled
Definition: Epos2.cpp:696
int main(void)
void setOperationMode(long opmode)
function to set the operation mode
Definition: Epos2.cpp:624
void startVelocity()
function to move the motor in Velocity mode
Definition: Epos2.cpp:758
void enableController()
function to facititate transitions from the start of the controller to switch it on ...
Definition: Epos2.cpp:632
void close()
Disconnects hardware.
Definition: Epos2.cpp:58
Implementation of a driver for EPOS2 Motor Controller.
Definition: Epos2.h:60
void init()
Connects hardware.
Definition: Epos2.cpp:49
int32_t readPosition()
function to read motor position
Definition: Epos2.cpp:1167
void stopVelocity()
function to stop the motor in velocity mode
Definition: Epos2.cpp:766
void setTargetVelocity(long velocity)
function to SET the target velocity
Definition: Epos2.cpp:750


epos2_motor_controller
Author(s): Martí Morta Garriga , Jochen Sprickerhof
autogenerated on Mon Jul 22 2019 03:19:01