Fawkes API  Fawkes Development Version
controller_kni.h
1 
2 /***************************************************************************
3  * controller_kni.h - KNI Controller class for katana arm
4  *
5  * Created: Tue Jan 03 11:40:31 2012
6  * Copyright 2012 Bahram Maleki-Fard, AllemaniACs RoboCup Team
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef __PLUGINS_KATANA_CONTROLLER_KNI_H_
24 #define __PLUGINS_KATANA_CONTROLLER_KNI_H_
25 
26 #include "controller.h"
27 
28 #include <core/utils/refptr.h>
29 #include <string>
30 #include <memory>
31 #include <vector>
32 
33 // Classes from libkni (KNI)
34 class CCdlCOM;
35 class CCplSerialCRC;
36 class CLMBase;
37 class CKatBase;
38 class CSctBase;
39 struct TMotInit;
40 
41 namespace fawkes {
42 #if 0 /* just to make Emacs auto-indent happy */
43 }
44 #endif
45 
46 //class RefPtr;
47 
49 {
50  public:
52  virtual ~KatanaControllerKni();
53 
54  // setup
55  virtual void setup(std::string& device, std::string& kni_conffile,
56  unsigned int read_timeout, unsigned int write_timeout);
57  virtual void init();
58  virtual void set_max_velocity(unsigned int vel);
59 
60 
61  // status checking
62  virtual bool final();
63  virtual bool joint_angles();
64  virtual bool joint_encoders();
65 
66  // commands
67  virtual void calibrate();
68  virtual void stop();
69  virtual void turn_on();
70  virtual void turn_off();
71  virtual void read_coordinates(bool refresh = false);
72  virtual void read_motor_data();
73  virtual void read_sensor_data();
74  virtual void gripper_open(bool blocking = false);
75  virtual void gripper_close(bool blocking = false);
76  virtual void move_to(float x, float y, float z, float phi, float theta, float psi, bool blocking = false);
77  virtual void move_to(std::vector<int> encoders, bool blocking = false);
78  virtual void move_to(std::vector<float> angles, bool blocking = false);
79  virtual void move_motor_to(unsigned short id, int enc, bool blocking = false);
80  virtual void move_motor_to(unsigned short id, float angle, bool blocking = false);
81  virtual void move_motor_by(unsigned short id, int enc, bool blocking = false);
82  virtual void move_motor_by(unsigned short id, float angle, bool blocking = false);
83 
84  // getters
85  virtual double x();
86  virtual double y();
87  virtual double z();
88  virtual double phi();
89  virtual double theta();
90  virtual double psi();
91  virtual void get_sensors(std::vector<int>& to, bool refresh = false);
92  virtual void get_encoders(std::vector<int>& to, bool refresh = false);
93  virtual void get_angles(std::vector<float>& to, bool refresh = false);
94 
95  private:
96  double __x, __y, __z;
97  double __phi, __theta, __psi;
98 
99  std::string __cfg_device;
100  std::string __cfg_kni_conffile;
101  unsigned int __cfg_read_timeout;
102  unsigned int __cfg_write_timeout;
103 
104  fawkes::RefPtr<CLMBase> __katana;
105 #if __cplusplus >= 201103L
106  std::unique_ptr<CCdlCOM> __device;
107  std::unique_ptr<CCplSerialCRC> __protocol;
108 #else
109  std::auto_ptr<CCdlCOM> __device;
110  std::auto_ptr<CCplSerialCRC> __protocol;
111 #endif
112  CKatBase *__katbase;
113  CSctBase *__sensor_ctrl;
114  std::vector<TMotInit> __motor_init;
115 
116  std::vector<short> __active_motors;
117  std::vector<int> __gripper_last_pos;
118 
119  bool motor_oor(unsigned short id);
120  bool motor_final(unsigned short id);
121  void cleanup_active_motors();
122  void add_active_motor(unsigned short id);
123 
124 };
125 
126 
127 } // end of namespace fawkes
128 
129 #endif
virtual double z()
Get z-coordinate of latest endeffector position.
virtual void setup(std::string &device, std::string &kni_conffile, unsigned int read_timeout, unsigned int write_timeout)
Setup parameters needed to initialize Katana arm with libkni.
virtual double theta()
Get theta-rotation of latest endeffector orientation.
virtual void read_sensor_data()
Read all sensor data from device into controller libray.
Fawkes library namespace.
virtual void turn_on()
Turn on arm/motors.
virtual void move_to(float x, float y, float z, float phi, float theta, float psi, bool blocking=false)
Move endeffctor to given coordinates.
virtual double phi()
Get x-coordinate of latest endeffector position.
virtual double x()
Get x-coordinate of latest endeffector position.
Controller class for a Neuronics Katana, using libkni to interact with the real Katana arm...
virtual void init()
Initialize controller.
Abstract class for a Neuronics Katana controller.
Definition: controller.h:37
virtual void move_motor_by(unsigned short id, int enc, bool blocking=false)
Move single joint/motor by encoder value (i.e.
virtual void turn_off()
Turn off arm/motors.
virtual void move_motor_to(unsigned short id, int enc, bool blocking=false)
Move single joint/motor to encoder value.
virtual void set_max_velocity(unsigned int vel)
Set maximum velocity.
virtual void gripper_close(bool blocking=false)
Close Gripper.
virtual double y()
Get y-coordinate of latest endeffector position.
virtual void read_motor_data()
Read motor data of currently active joints from device into controller libray.
virtual bool joint_angles()
Check if controller provides joint angle values.
virtual ~KatanaControllerKni()
Destructor.
virtual void calibrate()
Calibrate the arm.
KatanaControllerKni()
Constructor.
virtual double psi()
Get psi-rotation of latest endeffector orientation.
virtual void get_encoders(std::vector< int > &to, bool refresh=false)
Get encoder values of joints/motors.
virtual void get_angles(std::vector< float > &to, bool refresh=false)
Get angle values of joints/motors.
virtual void get_sensors(std::vector< int > &to, bool refresh=false)
Get sensor values.
virtual bool joint_encoders()
Check if controller provides joint encoder values.
virtual void gripper_open(bool blocking=false)
Open Gripper.
virtual void stop()
Stop movement immediately.
virtual void read_coordinates(bool refresh=false)
Store current coordinates of endeeffctor.