ElmoCtrl.h
Go to the documentation of this file.
1 /****************************************************************
2  *
3  * Copyright (c) 2010
4  *
5  * Fraunhofer Institute for Manufacturing Engineering
6  * and Automation (IPA)
7  *
8  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9  *
10  * Project name: care-o-bot
11  * ROS stack name: cob3_driver
12  * ROS package name: cob_head_axis
13  *
14  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15  *
16  * Author: Ulrich Reiser, email:ulrich.reiser@ipa.fhg.de
17  *
18  * Date of creation: Jul 2010
19  * ToDo:
20  *
21  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions are met:
25  *
26  * * Redistributions of source code must retain the above copyright
27  * notice, this list of conditions and the following disclaimer.
28  * * Redistributions in binary form must reproduce the above copyright
29  * notice, this list of conditions and the following disclaimer in the
30  * documentation and/or other materials provided with the distribution.
31  * * Neither the name of the Fraunhofer Institute for Manufacturing
32  * Engineering and Automation (IPA) nor the names of its
33  * contributors may be used to endorse or promote products derived from
34  * this software without specific prior written permission.
35  *
36  * This program is free software: you can redistribute it and/or modify
37  * it under the terms of the GNU Lesser General Public License LGPL as
38  * published by the Free Software Foundation, either version 3 of the
39  * License, or (at your option) any later version.
40  *
41  * This program is distributed in the hope that it will be useful,
42  * but WITHOUT ANY WARRANTY; without even the implied warranty of
43  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44  * GNU Lesser General Public License LGPL for more details.
45  *
46  * You should have received a copy of the GNU Lesser General Public
47  * License LGPL along with this program.
48  * If not, see <http://www.gnu.org/licenses/>.
49  *
50  ****************************************************************/
51 
52 
53 
54 #ifndef __ELMO_CTRL_H__
55 #define __ELMO_CTRL_H__
56 #define NTCAN_CLEAN_NAMESPACE
59 #include <cob_generic_can/CanItf.h>
62 #include <cob_generic_can/CanESD.h>
63 
64 // Headers provided by cob-packages which should be avoided/removed^M
65 #include <cob_utilities/IniFile.h>
66 #include <string>
67 
68 
69 typedef struct _CanOpenAddress
70 {
71  int TxPDO1;
72  int TxPDO2;
73  int RxPDO2;
74  int TxSDO;
75  int RxSDO;
77 
78 class ElmoCtrl;
79 
80 typedef struct
81 {
84 
85 
87 {
88 
89  public:
91 
92  int Init(std::string CanDevice, int BaudRate, int ModuleID)
93  {
94  SetCanDevice(CanDevice);
95  SetBaudRate(BaudRate);
96  SetModuleID(ModuleID);
97  return 0;
98  }
99 
100  //Can Device
101  void SetCanDevice(std::string CanDevice){m_CanDevice = CanDevice;}
102  std::string GetCanDevice(){return m_CanDevice;}
103 
104  //BaudRate
105  void SetBaudRate(int BaudRate){m_BaudRate=BaudRate;}
106  int GetBaudRate(){return m_BaudRate;}
107 
108  //ModuleIDs
109  int GetModuleID(){return m_ModuleID;}
110  void SetModuleID(int id){m_ModuleID = id;}
111 
112  //Angular Constraints
113  void SetUpperLimit(double UpperLimit){m_UpperLimit = UpperLimit;}
114  void SetLowerLimit(double LowerLimit){m_LowerLimit = LowerLimit;}
115  void SetAngleOffset(double AngleOffset){m_Offset = AngleOffset;}
116  double GetUpperLimit(){return m_UpperLimit;}
117  double GetLowerLimit(){return m_LowerLimit;}
118  double GetAngleOffset(){return m_Offset;}
119 
120  //Velocity
121  void SetMaxVel(double maxVel){m_MaxVel = maxVel;}
122  double GetMaxVel(){return m_MaxVel;}
123 
124  //HomingDir
125  void SetHomingDir(int dir){m_HomingDir = dir;}
126  int GetHomingDir(){return m_HomingDir;}
127 
128  //HomingDigIn
129  void SetHomingDigIn(int dig_in){m_HomingDigIn = dig_in;}
130  int GetHomingDigIn(){return m_HomingDigIn;}
131 
132  //CanIniFile
133  void SetCanIniFile(std::string iniFile){m_CanIniFile=iniFile;}
134  std::string GetCanIniFile(){return m_CanIniFile;}
135 
136  //Encoder increments
137  void SetEncoderIncrements(int enc_incr){m_EncIncrPerRevMot = enc_incr;}
138  int GetEncoderIncrements(){return m_EncIncrPerRevMot;}
139 
140  //Belt & Gear ratio in one
141  void SetGearRatio(double gear_ratio){m_GearRatio = gear_ratio;}
142  double GetGearRatio(){return m_GearRatio;}
143 
144  //Motor direction
145  void SetMotorDirection(int motor_dir){
146  if(motor_dir<0) m_MotorDirection = -1;
147  else m_MotorDirection = 1;
148  }
149  int GetMotorDirection(){return m_MotorDirection;}
150 
151 
152 
153 
154  private:
156  std::string m_CanDevice;
162  double m_GearRatio;
163  double m_Offset;
164  double m_UpperLimit;
165  double m_LowerLimit;
166  double m_MaxVel;
167  std::string m_CanIniFile;
168 
169 };
170 
171 class ElmoCtrl
172 {
173 
174 public:
175  ElmoCtrl();
176  ~ElmoCtrl();
177 
178  bool Init(ElmoCtrlParams* params, bool home = true);
179 
180 
181  double MoveJointSpace (double PosRad);
182 
183 
184  bool Home();
185 
186  bool RecoverAfterEmergencyStop();
187 
188  bool Stop();
189 
190 
191  void setMaxVelocity(float radpersec)
192  {
193  m_MaxVel = radpersec;
194  }
195 
201  int getGearPosVelRadS(double* pdAngleGearRad, double* pdVelGearRadS);
202 
207  int setGearPosVelRadS(double dPosRad, double dVelRadS);
208 
212  int evalCanBuffer();
213 
214  //_double getConfig();
215 
216  double getJointVelocity();
217 
218 
219 
220  bool SetMotionCtrlType(int type);
221  int GetMotionCtrlType();
222  bool isError() ;
223 
224 
225  enum {
227  VEL_CTRL
228  } MOTION_CTRL_TYPE;
229 
230 
231  CANPeakSysUSB* GetCanCtrl(){return m_CanCtrl;}
232  //CanESD* GetCanCtrl(){return m_CanCtrl;}
233  //bool m_ElmoCtrlThreadActive;
235  //pthread_mutex_t m_cs_elmoCtrlIO;
237 
238 private:
239 
240  bool sendNetStartCanOpen(CanItf* canCtrl);
241 
243 
245 
248 
250  //CanESD * m_CanCtrl;
251 
252  double m_MaxVel;
257  double m_GearRatio;
258 
259  double m_UpperLimit;
260  double m_LowerLimit;
262  /*
263  Jointd* m_CurrentAngularVelocity;
265  Jointd* m_CurrentJointAngles;
266  */
268  pthread_mutex_t m_Mutex;
270  //pthread_mutex_t m_AngularVel_Mutex;
272  //pthread_t m_ElmoThreadID;
274  //ElmoThreadArgs * m_ElmoCtrlThreadArgs;
277 
278 
280 
281 };
282 
283 
284 
285 
286 
287 
288 
289 
290 
291 #endif //__ELMO_CTRL_H__
double GetAngleOffset()
Definition: ElmoCtrl.h:118
double m_MaxVel
Definition: ElmoCtrl.h:166
void SetCanDevice(std::string CanDevice)
Definition: ElmoCtrl.h:101
int m_HomingDir
Definition: ElmoCtrl.h:253
void SetLowerLimit(double LowerLimit)
Definition: ElmoCtrl.h:114
double m_LowerLimit
Definition: ElmoCtrl.h:165
double GetMaxVel()
Definition: ElmoCtrl.h:122
void SetModuleID(int id)
Definition: ElmoCtrl.h:110
void SetHomingDir(int dir)
Definition: ElmoCtrl.h:125
CanMsg m_CanMsgRec
Definition: ElmoCtrl.h:276
int GetModuleID()
Definition: ElmoCtrl.h:109
double m_JointOffset
Definition: ElmoCtrl.h:261
int GetHomingDigIn()
Definition: ElmoCtrl.h:130
void SetCanIniFile(std::string iniFile)
Definition: ElmoCtrl.h:133
double m_UpperLimit
Definition: ElmoCtrl.h:164
int m_CanBaseAddress
Definition: ElmoCtrl.h:246
pthread_mutex_t m_Mutex
joint mutexes
Definition: ElmoCtrl.h:268
std::string m_CanIniFile
Definition: ElmoCtrl.h:167
double m_MaxVel
Definition: ElmoCtrl.h:252
int m_MotorDirection
Definition: ElmoCtrl.h:256
int Init(std::string CanDevice, int BaudRate, int ModuleID)
Definition: ElmoCtrl.h:92
ElmoCtrlParams * m_Params
joint velocity mutexes
Definition: ElmoCtrl.h:275
CANPeakSysUSB * GetCanCtrl()
Definition: ElmoCtrl.h:231
int m_HomingDigIn
Definition: ElmoCtrl.h:254
void SetUpperLimit(double UpperLimit)
Definition: ElmoCtrl.h:113
double GetLowerLimit()
Definition: ElmoCtrl.h:117
CanOpenAddress m_CanAddress
Definition: ElmoCtrl.h:247
void SetBaudRate(int BaudRate)
Definition: ElmoCtrl.h:105
double m_GearRatio
Definition: ElmoCtrl.h:257
struct _CanOpenAddress CanOpenAddress
void SetMotorDirection(int motor_dir)
Definition: ElmoCtrl.h:145
double m_LowerLimit
Definition: ElmoCtrl.h:260
ElmoCtrl * pElmoCtrl
Definition: ElmoCtrl.h:82
int GetEncoderIncrements()
Definition: ElmoCtrl.h:138
std::string m_CanDevice
Definition: ElmoCtrl.h:156
double m_UpperLimit
Definition: ElmoCtrl.h:259
double m_GearRatio
Definition: ElmoCtrl.h:162
std::string GetCanIniFile()
Definition: ElmoCtrl.h:134
void SetGearRatio(double gear_ratio)
Definition: ElmoCtrl.h:141
int m_HomingDigIn
Definition: ElmoCtrl.h:159
CANPeakSysUSB * m_CanCtrl
Definition: ElmoCtrl.h:249
void setMaxVelocity(float radpersec)
Definition: ElmoCtrl.h:191
double m_Offset
Definition: ElmoCtrl.h:163
std::string GetCanDevice()
Definition: ElmoCtrl.h:102
int GetMotorDirection()
Definition: ElmoCtrl.h:149
int m_MotorDirection
Definition: ElmoCtrl.h:161
CanDriveHarmonica * m_Joint
joint mutexes
Definition: ElmoCtrl.h:236
int GetBaudRate()
Definition: ElmoCtrl.h:106
DriveParam * m_JointParams
Definition: ElmoCtrl.h:244
int m_EncIncrPerRevMot
Definition: ElmoCtrl.h:160
void SetEncoderIncrements(int enc_incr)
Definition: ElmoCtrl.h:137
int m_MotionCtrlType
Definition: ElmoCtrl.h:242
void SetMaxVel(double maxVel)
Definition: ElmoCtrl.h:121
void SetHomingDigIn(int dig_in)
Definition: ElmoCtrl.h:129
int m_EncIncrPerRevMot
Definition: ElmoCtrl.h:255
double GetGearRatio()
Definition: ElmoCtrl.h:142
double GetUpperLimit()
Definition: ElmoCtrl.h:116
int GetHomingDir()
Definition: ElmoCtrl.h:126
void SetAngleOffset(double AngleOffset)
Definition: ElmoCtrl.h:115


cob_head_axis
Author(s): Ulrich Reiser
autogenerated on Tue Jul 25 2017 02:22:10