WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 6ecfecd

Browse files
authored
Merge pull request #2 from ZhuoyueLi/main
FrankaProxy framework done the message dealing and test for state publish and control request
2 parents 9fdee03 + 084dc7f commit 6ecfecd

26 files changed

+989
-406
lines changed

CMakeLists.txt

100755100644
Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
11
cmake_minimum_required(VERSION 3.10)
2-
project(FRANKA_CONTROL_PROXY)
2+
project(Franka_Control_Proxy)
33

4-
# Set C++ standard
54
set(CMAKE_CXX_STANDARD 17)
65
set(CMAKE_CXX_STANDARD_REQUIRED True)
76

8-
find_package(Franka REQUIRED)
7+
#include
8+
include_directories(
9+
include
10+
include/control_mode
11+
include/protocol
12+
include/debugger
13+
)
914

10-
# Find libzmq package
15+
# dependencies
16+
find_package(Franka REQUIRED)
17+
find_package(Threads REQUIRED)
1118
find_package(PkgConfig REQUIRED)
1219
pkg_check_modules(ZMQ REQUIRED libzmq)
1320
find_package(yaml-cpp REQUIRED)
1421

22+
23+
# collect source
24+
file(GLOB_RECURSE SOURCES
25+
src/*.cpp
26+
)
27+
1528
# Include directories
1629
include_directories(include ${YAML_CPP_INCLUDE_DIR} ${Franka_INCLUDE_DIRS})
1730

18-
# Add executable target
19-
add_executable(leader src/human_controller.cpp)
20-
add_executable(follower src/follow.cpp)
31+
# build proxy
32+
add_executable(proxy ${SOURCES})
33+
34+
# connect with dependencies
35+
target_link_libraries(proxy
36+
${Franka_LIBRARIES}
37+
${ZMQ_LIBRARIES}
38+
${YAML_CPP_LIBRARIES}
39+
Threads::Threads
40+
)
41+
42+
#include path
43+
target_include_directories(proxy PRIVATE
44+
${franka_INCLUDE_DIRS}
45+
${ZMQ_INCLUDE_DIRS}
46+
)
47+
48+
2149

22-
# Link libraries to your target (franka, yaml-cpp, zmq)
23-
target_link_libraries(leader PRIVATE ${YAML_CPP_LIBRARIES} ${Franka_LIBRARIES} ${ZMQ_LIBRARIES})
24-
target_link_libraries(follower PRIVATE ${YAML_CPP_LIBRARIES} ${Franka_LIBRARIES} ${ZMQ_LIBRARIES})

RobotConfig.yaml

100755100644
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
RobotIP: 172.16.2.2
2-
PublisherAddr: tcp://141.3.53.152:5555
3-
ServiceAddr: tcp://141.3.53.152:5556
1+
robot_ip: 172.16.2.2
2+
state_pub_addr: tcp://141.3.53.152:5555
3+
service_addr: tcp://141.3.53.152:5556
44
useGripper: true

include/FrankaProxy.h

Lines changed: 0 additions & 95 deletions
This file was deleted.

include/FrankaProxy.hpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#ifndef FRANKA_SERVER_HPP
2+
#define FRANKA_SERVER_HPP
3+
4+
#include <zmq.hpp>
5+
#include <thread>
6+
#include <atomic>
7+
#include <mutex>
8+
#include <string>
9+
#include <memory>
10+
11+
#include <franka/robot.h>
12+
#include <franka/model.h>
13+
#include <franka/robot_state.h>
14+
#include <yaml-cpp/yaml.h>
15+
#include "protocol/franka_arm_state.hpp"
16+
#include "control_mode/abstract_control_mode.h"
17+
18+
class FrankaProxy {
19+
20+
public:
21+
// Constructor & Destructor
22+
explicit FrankaProxy(const std::string& config_path);// Constructor that initializes the proxy with a configuration file
23+
~FrankaProxy();// Destructor to clean up resources
24+
25+
// Core server operations
26+
bool start();// Starts the Franka server, initializing the robot and communication sockets
27+
void stop();// Stops the server, cleaning up resources and shutting down communication
28+
void spin();// Main loop for processing requests
29+
30+
// State management
31+
franka::RobotState getCurrentState();// Return the current state of the robot
32+
33+
// Mode management
34+
void registerControlMode(const std::string& mode, std::unique_ptr<AbstractControlMode> control_mode);//register the map
35+
void setControlMode(const std::string& mode);
36+
37+
38+
39+
// Configuration
40+
void displayConfig() const;
41+
42+
private:
43+
// Initialization
44+
void initialize(const std::string &filename);// Initializes the FrankaProxy with the given configuration file
45+
void setupCommunication();// Sets up ZMQ communication sockets and threads?
46+
47+
// Thread functions
48+
void statePublishThread();// ZMQ PUB, Publishes the current state of the robot at a fixed rate
49+
void responseSocketThread();// ZMQ REP,responds to incoming requests from clients
50+
void controlLoopThread();// Main control loop for processing commands and updating the robot state
51+
52+
53+
// Message handling
54+
void handleServiceRequest(const std::string& request, std::string& response);
55+
56+
57+
private:
58+
// Configuration
59+
YAML::Node proxy_config_;
60+
std::string robot_ip_;
61+
std::string state_pub_addr_;
62+
std::string service_addr_;
63+
64+
// Franka robot
65+
std::shared_ptr<franka::Robot> robot_;
66+
std::shared_ptr<franka::Model> model_;
67+
68+
// ZMQ communication
69+
zmq::context_t context_;
70+
zmq::socket_t pub_socket_;
71+
zmq::socket_t sub_socket_;
72+
zmq::socket_t rep_socket_;
73+
74+
// Threading
75+
std::thread state_pub_thread_;//statePublishThread()
76+
std::thread service_thread_;//responseSocketThread()
77+
std::thread control_thread_;//controlLoopThread()
78+
79+
80+
// Synchronization
81+
std::atomic<bool> in_control_;//for threads
82+
83+
// State data
84+
franka::RobotState current_state_;
85+
86+
//Control mode
87+
std::string mode_name;
88+
AbstractControlMode* current_mode_ = nullptr;
89+
std::mutex control_mutex_;
90+
std::map<std::string, std::shared_ptr<AbstractControlMode>> control_modes_map_;
91+
92+
// TODO: put all the Constants to a config file
93+
static constexpr int STATE_PUB_RATE_HZ = 100;
94+
static constexpr int SOCKET_TIMEOUT_MS = 100;
95+
static constexpr int MAX_MESSAGE_SIZE = 4096;
96+
};
97+
98+
#endif // FRANKA_SERVER_HPP

include/FrankaState.h

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,18 @@ class RobotConfig {
3535
}
3636

3737
// Function to get a value as a string
38-
std::string getValue(const std::string& key) const {
38+
39+
std::string getValue(const std::string& key, const std::string& default_value = "") const {
3940
auto it = config_data.find(key);
4041
if (it != config_data.end()) {
4142
return it->second;
4243
} else {
43-
std::cerr << "Warning: Key not found in config: " << key << std::endl;
44-
return "";
44+
std::cerr << "Warning: Key not found in config: " << key << ", using default: " << default_value << std::endl;
45+
return default_value;
4546
}
46-
}
47+
}
48+
49+
4750

4851
// Function to display the loaded configuration
4952
void display() const {

0 commit comments

Comments
 (0)