-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFrankaProxy.h
More file actions
executable file
·95 lines (73 loc) · 2.44 KB
/
FrankaProxy.h
File metadata and controls
executable file
·95 lines (73 loc) · 2.44 KB
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
#ifndef FRANKA_SERVER_HPP
#define FRANKA_SERVER_HPP
#include <zmq.hpp>
#include <thread>
#include <atomic>
#include <mutex>
#include <string>
#include <memory>
#include <franka/robot.h>
#include <franka/model.h>
#include <yaml-cpp/yaml.h>
#include "FrankaState.h"
#include "control_mode/AbstractControlMode.h"
class FrankaProxy {
public:
// Constructor & Destructor
explicit FrankaProxy(const std::string& config_path);
~FrankaProxy();
// Core server operations
bool start();
void stop();
void spin();
// State management
const FrankaArmState& getCurrentState() const;
// Mode management
void setControlMode(const std::string& mode);
// Configuration
void registerControlMode(const std::string& mode, std::unique_ptr<AbstractControlMode> control_mode);
void displayConfig() const;
private:
// Initialization
void initialize(const std::string &filename);
// Thread functions
void statePublishThread();
void responseSocketThread();
// Message handling
void handleServiceRequest(const std::string& request, std::string& response);
void handleCommandMessage(const std::string& command);
// State conversion
FrankaArmState convertFrankaState(const franka::RobotState& franka_state) const;
// Utility functions
std::string createStateMessage(const FrankaArmState& state) const;
std::string createModeMessage(const std::string& mode) const;
private:
// Configuration
YAML::Node proxy_config_;
std::string robot_ip_;
std::string state_pub_addr_;
std::string service_addr_;
// Franka robot
std::shared_ptr<franka::Robot> robot_;
std::shared_ptr<franka::Model> model_;
// ZMQ communication
zmq::context_t context_;
zmq::socket_t pub_socket_;
zmq::socket_t sub_socket_;
zmq::socket_t rep_socket_;
// Threading
std::thread state_pub_thread_;
std::thread control_thread_;
std::thread service_thread_;
// Synchronization
std::atomic<bool> in_control_;
// State data
FrankaArmState current_state_;
std::string current_mode_;
std::map<std::string, std::shared_ptr<AbstractControlMode>> control_modes_map_;
// TODO: put all the Constants to a config file
static constexpr int STATE_PUB_RATE_HZ = 100;
static constexpr int SOCKET_TIMEOUT_MS = 100;
static constexpr int MAX_MESSAGE_SIZE = 4096;
};
#endif // FRANKA_SERVER_HPP