-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot.h
207 lines (179 loc) · 4.81 KB
/
robot.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#ifndef ROBOT_H
#define ROBOT_H
#include <node.hpp>
#include <stdmsg.hh>
#include <thread.hpp>
#include "driver\motion.h"
#include "driver\Laser.h"
#include "driver\LaserUST.h"
//#include "driver\LaserSick\laser.h"
#include <vector>
#include <iostream>
#include <sstream>
#include <math.h>
#include <queue>
#include <list>
#include "VMProtectSDK.h"
std::string hwid();
void set_licence(const std::string file = "licence.key");
#define EXPORT
#ifdef WIN32
#ifndef EXPORT
#define EXPORT __declspec(dllimport)
#endif
#else
#define EXPORT
#endif
/* serval driver for navigator
* the GenerelDriver provide the api
* the handware is based on jiaolong wheelchair, most source is in ./driver
* the Simulator is for gazebo/jiaolong simulator
* the Playback is to replay the scene of the logged file
*/
class GenerelDriver
{
public:
virtual void set_commad( const stdmsg::Velocity & vel) = 0;//控制前后左右
virtual void set_otherstate(const int & openclose, const int & risefall) = 0;//控制升降杆,支腿
virtual stdmsg::Velocity velocity() = 0;
virtual stdmsg::Laser_Scan scan() = 0;
//crti;2016-06-22,加一个返回emergency_stop_flag的函数
virtual int get_emergency_stop_flag() = 0;
//crti;2016-07-05,投影仪控制
virtual void set_projector(int open_or_close_projector) = 0;
virtual int get_projector() = 0;
virtual void set_light(int open_or_close_light) = 0;
virtual int get_light() = 0;
virtual void set_light2(int open_or_close_light) = 0;
virtual int get_light2() = 0;
//virtual void set_light2(int open_or_close_light2) = 0;
//virtual int get_light2() = 0;
//fyf, 2016-12-2, 增加返回docking_state的函数
virtual int get_docking_state() = 0;
virtual int get_battery_level() = 0;
virtual int get_charge_state() = 0;
virtual int get_control_state() = 0;
virtual int get_goal_port() = 0;
virtual int get_set_place_cmd() = 0;
virtual int get_record_path_cmd() = 0;
virtual int get_initial_pose() = 0;
virtual int get_mapping_cmd() = 0;
};
enum Control_Mode
{
MANUAL,
AUTONOMOUS
};
class EXPORT Robot
{
protected:
middleware::Node *nh;
middleware::RPC rpc;
middleware::ConfigFile cfg;
int publish_time;
std::string raw_scan_topic;
private:
struct _Rpc_Thread:public BThread
{
Robot* handle;
_Rpc_Thread(Robot* p)
{
handle = p;
}
~_Rpc_Thread()
{
kill();
}
void run()
{
try{
while(true)
{
handle->rpc.run();
_sleep(1);//crti:2016-05-28,降低cpu使用率
}
}
catch(const std::exception& e)
{
std::cerr<<"communication error: "<< e.what() <<std::endl;
}
}
} rpc_thread;
struct _Node_Thread:public BThread
{
Robot* handle;
_Node_Thread(Robot* p)
{
handle = p;
}
~_Node_Thread()
{
kill();
}
void run()
{
try{
while(true)
{
handle->nh->run();
_sleep(1);//crti:2016-05-28,降低cpu使用率
}
}
catch(const std::exception& e)
{
std::cerr<<"communication error: "<< e.what() <<std::endl;
}
}
} nh_thread;
GenerelDriver *driver;
std::string velocity_topic;
Control_Mode control_mode;
stdmsg::Velocity manual_vel;
//GenerelDriver** ptrHardware;
public:
Robot(int argc, char** argv) ;
/* remote process api, it must recevie a serilizable
* object, and return another serilizable object
*/
void start_ipc();
stdmsg::Laser_Scan scan( );
stdmsg::String set_mode(const stdmsg::String& mode);
stdmsg::String get_mode(const stdmsg::String& mode);
void set_cmd_manual(const stdmsg::Velocity & vel);
void set_cmd_autonomous(const stdmsg::Velocity & vel);
void set_otherstate_autonomous(const int & openclose, const int & risefall);
~Robot();
//crti;2016-06-22,加一个返回emergency_stop_flag的函数
int get_emergency_stop_flag()
{
return this->driver->get_emergency_stop_flag();
}
int get_docking_state()
{
return this->driver->get_docking_state();
}
int get_battery_level();
int get_charge_state();
int get_control_state();
int get_goal_port();
int get_set_place_cmd();
int get_record_path_cmd();
int get_initial_pose();
int get_mapping_cmd();
stdmsg::Velocity odomvelocity();
//virtual void run();
//crti;2016-07-05,投影仪控制
void set_projector_flag(int open_or_close_projector)
{
this->driver->set_projector(open_or_close_projector);
}
void set_light_flag(int open_or_close_light)
{
this->driver->set_light(open_or_close_light);
}
void set_light2_flag(int open_or_close_light2)
{
this->driver->set_light2(open_or_close_light2);
}
};
#endif