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 
30 #include <memory>
31 #include <string>
32 #include <vector>
33 
34 // Classes from libkni (KNI)
35 class CCdlCOM;
36 class CCplSerialCRC;
37 class CLMBase;
38 class CKatBase;
39 class CSctBase;
40 struct TMotInit;
41 
42 namespace fawkes {
43 
44 //class RefPtr;
45 
47 {
48 public:
50  virtual ~KatanaControllerKni();
51 
52  // setup
53  virtual void setup(std::string &device,
54  std::string &kni_conffile,
55  unsigned int read_timeout,
56  unsigned int write_timeout);
57  virtual void init();
58  virtual void set_max_velocity(unsigned int vel);
59 
60  // status checking
61  virtual bool final();
62  virtual bool joint_angles();
63  virtual bool joint_encoders();
64 
65  // commands
66  virtual void calibrate();
67  virtual void stop();
68  virtual void turn_on();
69  virtual void turn_off();
70  virtual void read_coordinates(bool refresh = false);
71  virtual void read_motor_data();
72  virtual void read_sensor_data();
73  virtual void gripper_open(bool blocking = false);
74  virtual void gripper_close(bool blocking = false);
75  virtual void
76  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 } // end of namespace fawkes
126 
127 #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:34
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.
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.