-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathposition_server.cpp
57 lines (48 loc) · 1.46 KB
/
position_server.cpp
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
#include "ros/ros.h"
#include "epos2/Position.h"
#include "wrap.h"
bool moveToPosition(epos2::Position::Request &req, epos2::Position::Response &res)
{
unsigned int ulErrorCode = 0;
// the force transform of the data type can cause problem
ROS_INFO("request: position=%ld", (long int)req.position);
MoveToPosition(g_pKeyHandle, g_usNodeId, (long)req.position, req.isAbsolute, &ulErrorCode);
short current;
int position_new;
ROS_INFO("now read position");
get_position(g_pKeyHandle, g_usNodeId, &position_new, &ulErrorCode);
// res.current = current;
res.position_new = position_new;
// sleep(0.01);
ROS_INFO("now return");
return true;
}
int main(int argc, char **argv)
{
int lResult = MMC_FAILED;
unsigned int ulErrorCode = 0;
// Set parameter for usb IO operation
SetDefaultParameters();
// open device
if((lResult = OpenDevice(&ulErrorCode))!=MMC_SUCCESS)
{
LogError("OpenDevice", lResult, ulErrorCode);
return lResult;
}
SetEnableState(g_pKeyHandle, g_usNodeId, &ulErrorCode);
ActivateProfilePositionMode(g_pKeyHandle, g_usNodeId, &ulErrorCode);
ros::init(argc, argv, "epos2");
ros::NodeHandle n;
ros::ServiceServer service = n.advertiseService("moveToPosition", moveToPosition);
ROS_INFO("Ready to move.");
ros::spin();
//disable epos
SetDisableState(g_pKeyHandle, g_usNodeId, &ulErrorCode);
//close device
if((lResult = CloseDevice(&ulErrorCode))!=MMC_SUCCESS)
{
LogError("CloseDevice", lResult, ulErrorCode);
return lResult;
}
return 0;
}