-
Notifications
You must be signed in to change notification settings - Fork 2
/
joint_position_controller.cpp
51 lines (41 loc) · 1.68 KB
/
joint_position_controller.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
#include "network_interfaces/control_type.h"
#include "network_interfaces/zmq/network.h"
int main(int argc, char** argv) {
std::string state_uri = "*:1601";
std::string command_uri = "*:1602";
if (argc == 2) {
if (atof(argv[1]) == 17) {
state_uri = "*:1701";
command_uri = "*:1702";
} else if (atof(argv[1]) != 16) {
std::cerr << "This robot is unknown, choose either '16' (default) or '17'." << std::endl;
return 1;
}
} else {
std::cerr << "Please provide at most one argument to choose which robot to connect to ('16' or '17')." << std::endl;
return 1;
}
double gain = 10.0;
double damping = 0.1;
::zmq::context_t context(1);
::zmq::socket_t subscriber, publisher;
network_interfaces::zmq::configure_sockets(context, subscriber, state_uri, publisher, command_uri, true, true);
network_interfaces::zmq::StateMessage state;
network_interfaces::zmq::CommandMessage command;
command.control_type = std::vector<int>{static_cast<int>(network_interfaces::control_type_t::EFFORT)};
command.joint_state = state_representation::JointState::Zero("franka", 7);
state_representation::JointPositions target;
while (context.handle() != nullptr) {
if (network_interfaces::zmq::receive(state, subscriber)) {
if (target.is_empty()) {
target = state.joint_state;
command.joint_state = state.joint_state;
command.joint_state.set_zero();
}
auto error = target.get_positions() - state.joint_state.get_positions();
auto torques = gain * error - damping * state.joint_state.get_velocities();
command.joint_state.set_torques(torques);
network_interfaces::zmq::send(command, publisher);
}
}
}