test_positions.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 "ctime.h"
24 #include "Epos2.h"
25 
26 using namespace std;
27 
35 int main(void){
36 
37  CEpos2 controller;
38 
39  cout << "Epos2 Positions:" << endl;
40 
41  long pos_marker=0,pos_marker_old=0;
42  CTime tavg;
43 
44  try{
45 
46  controller.init();
47 
48  // enable motor in velocity mode
49  controller.enableController();
50  controller.enableMotor(controller.VELOCITY);
51  controller.setOperationMode(controller.VELOCITY);
52 
53  CTime tbase,telapsed;
54  int experiment_duration = 10, vel = 1000;
55  bool primera = true;
56 
57  controller.setPositionMarker();
58  controller.setTargetVelocity(vel);
59  controller.startVelocity();
60 
61 
62  cout << "t0\tpos0\tt1\tpos1"<< endl;
63 
64  do{
65 
66  telapsed.set();
67  telapsed = telapsed - tbase;
68 
69  pos_marker = controller.getPositionMarker(1);
70 
71 
72  if (pos_marker != pos_marker_old)
73  {
74  telapsed.setFormat(ctf_ms);
75  if(primera){
76  cout << telapsed << "\t" << pos_marker;
77  primera = false;
78  }else{
79  cout << "\t" << telapsed << "\t" << pos_marker << endl;
80  primera = true;
81  }
82  pos_marker_old = pos_marker;
83  }
84 
85  }while( telapsed.getTimeInSeconds() < experiment_duration );
86 
87  controller.stopVelocity();
88 
89  controller.close();
90 
91  }catch(CException &e){
92  controller.close();
93  cout << e.what() << endl;
94  }
95 
96  return 1;
97 
98 }
99 
int main(void)
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 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
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
long getPositionMarker(int buffer=0)
gets the position marked by the sensor
Definition: Epos2.cpp:1512


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