Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rsi driver #99

Closed
wants to merge 108 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
51c45b3
Merge remote-tracking branch 'origin/master' into feature/rsi_driver
oprezz Jun 23, 2022
376c4bc
initial portation of the HW to ROS2_CONTROL
oprezz Jun 23, 2022
ec9d93b
adding setup launch file, not yet working example
oprezz Jun 23, 2022
338bfc8
some fixes to pluginazation, still not working
oprezz Jun 24, 2022
a7294aa
change CI to humble
Svastits Jun 27, 2022
1c54952
hwinterface to SHARED library
Svastits Jun 27, 2022
c5a6c83
fix parameter names
Svastits Jun 27, 2022
4f169c2
changed to joint_trajectory controller, will fix for forward controll…
oprezz Jul 13, 2022
3f4c45c
launch file rework
Svastits Aug 1, 2022
be9d756
uncrustify
Svastits Aug 1, 2022
3805f9a
add custom controller_manager, remove unused node
Svastits Aug 1, 2022
8e266ee
lint
Svastits Aug 1, 2022
ce96d76
logging
Svastits Aug 1, 2022
bf2ec09
start controller as active
Svastits Aug 1, 2022
67938cd
remove unnecessary logs
Svastits Aug 1, 2022
12e41f3
lint, move launch file to launch folder
Svastits Aug 1, 2022
cd09919
uncrustify
Svastits Aug 1, 2022
eb11aeb
initialize with 0-s
Svastits Aug 5, 2022
e1931b6
lint cmake
Svastits Aug 5, 2022
eb19f2f
fix humble exclude
Svastits Aug 5, 2022
7e86221
fix sonar code smells
Svastits Aug 5, 2022
43a2700
clean up unnecessary class members
Svastits Aug 5, 2022
849e723
move configuration to init
Svastits Aug 5, 2022
be2e70b
uncrustify
Svastits Aug 5, 2022
7622fa9
disable writing to hwif before successful read
Svastits Aug 8, 2022
9885c3f
uncrustify
Svastits Aug 8, 2022
32ff715
Merge branch 'master' into feature/rsi_driver
Svastits Aug 10, 2022
6bf1491
Merge branch 'master' into feature/rsi_driver
Svastits Aug 16, 2022
67cf9df
Merge branch 'master' into feature/rsi_driver
kovacsge11 Jan 12, 2023
ec09377
fix merge
kovacsge11 Jan 12, 2023
251a11b
Merge branch 'master' into feature/rsi_driver
kovacsge11 Jan 12, 2023
311c83a
Merge branch 'master' into feature/rsi_driver
Svastits Jan 27, 2023
b1818af
Merge branch 'master' into feature/rsi_driver
Jun 19, 2023
0bd8a73
add manager node
Jun 19, 2023
d5f6916
fix deactivation
Jun 19, 2023
cc634a4
update rsi context files
Jun 22, 2023
f003b8e
UDP without memory allocation
altex111 Jun 23, 2023
3220ed3
todos
altex111 Jun 26, 2023
0bb44e6
xml_element defined
altex111 Jun 29, 2023
6ee7f28
update ip log
Jun 30, 2023
5719717
update rsi start instructions
Jun 30, 2023
dd947cd
update readme
Jun 30, 2023
5c89a0c
xml_element design update
altex111 Jun 30, 2023
6490ae6
Merge remote-tracking branch 'origin/feature/rsi_driver' into feature…
altex111 Jun 30, 2023
07d3f11
param caster function
altex111 Jul 5, 2023
83c0f7d
xml_element into a cpp and hpp file
altex111 Jul 11, 2023
bdb4e52
decode function with indexing
altex111 Jul 11, 2023
306dcac
decode algorithm without error handling
altex111 Jul 12, 2023
94b781a
working xml decoder function few changes still needed
altex111 Jul 19, 2023
7e9fda5
map find with xmlString without allocation
altex111 Jul 21, 2023
15a81db
Encoder layout
altex111 Jul 25, 2023
a29f389
Encode algorithm
altex111 Jul 31, 2023
c6b3a69
Encode under test
altex111 Aug 1, 2023
5c8fc4d
Merge branch 'master' into feature/rsi_driver
Aug 2, 2023
90de396
remove tabs
Aug 2, 2023
ad4cc50
Working encoding
altex111 Aug 2, 2023
d9c6a7a
Merge remote-tracking branch 'origin/feature/rsi_driver' into feature…
altex111 Aug 2, 2023
9800d9b
xml_handler moved into kss driver
altex111 Aug 2, 2023
61fcf44
Corrected map find functions
altex111 Aug 2, 2023
1e0c0bf
corrected decode function
altex111 Aug 3, 2023
d86ad0e
remove unnecessary files (merge error)
Aug 4, 2023
6e00b0e
Small pr changes
altex111 Aug 7, 2023
76ca597
Integrate command handler into rsi hardware interface
altex111 Aug 14, 2023
df98db4
Fix Element access bug
altex111 Aug 14, 2023
91c31a6
fix operator< functions now they are consistent
altex111 Aug 14, 2023
af69f9b
fix error handling in encode
altex111 Aug 14, 2023
ac4d6cb
fixed error handling in command handler
altex111 Aug 15, 2023
fba8d4f
working control
altex111 Aug 16, 2023
aa6a3ff
Small PR changes
altex111 Aug 16, 2023
fc68638
Update algorithm to be more stable
altex111 Aug 17, 2023
6ff5107
Merge remote-tracking branch 'origin/master' into feature/rsi_driver
altex111 Aug 17, 2023
95a3f7c
Updating Error handling and added comments
altex111 Aug 17, 2023
09106d2
CI changes
altex111 Aug 17, 2023
92fb416
XMLElement class function comments
altex111 Aug 17, 2023
23374a3
CI corrections
altex111 Aug 18, 2023
12c4773
CI correction #2
altex111 Aug 18, 2023
57bcdcb
using ros angles
altex111 Aug 18, 2023
97163e9
sonarCloud codesmells
altex111 Aug 18, 2023
2011cc3
try to make strncpy safe
altex111 Aug 18, 2023
cd30168
try to make strncpy safe #2
altex111 Aug 18, 2023
3af369d
try to make strncpy safe #3
altex111 Aug 18, 2023
98507f2
sonarCloud corrections
altex111 Aug 18, 2023
46e41b4
comment typo corrections
Aug 21, 2023
0442e63
fix description
Aug 21, 2023
25ae06e
ci
Aug 21, 2023
c841341
refactor encode to lower complexity
altex111 Aug 22, 2023
37fd426
refactor decode to lower complexity
altex111 Aug 22, 2023
4871cbd
update decode refactor
altex111 Aug 22, 2023
7bb798d
refactor decode to lower complexity #2
altex111 Aug 22, 2023
24aa600
refactor decode to lower complexity #3
altex111 Aug 22, 2023
8ec36ff
refactor decode to lower complexity #4
altex111 Aug 22, 2023
856db58
Remove old xml parser
altex111 Aug 22, 2023
d68f057
remove redundant
altex111 Aug 22, 2023
7432203
correcting comments
altex111 Aug 24, 2023
2706ee1
fix include
altex111 Aug 24, 2023
c7d7b22
set locale when it is needed
altex111 Aug 24, 2023
cd58358
remove deactivate
altex111 Aug 24, 2023
0818578
Update locale set and reset
altex111 Aug 25, 2023
0a752dd
fix
altex111 Aug 25, 2023
a4eff55
fix #2
altex111 Aug 25, 2023
32e89a7
add unit tests
Sep 5, 2023
1d6a3cc
Test cases with pugixml
altex111 Sep 7, 2023
a32ddcc
further test cases
altex111 Sep 8, 2023
6e4e2e6
working on custom mem alloc
altex111 Sep 8, 2023
aa66dc8
more test cases
altex111 Sep 14, 2023
daaa42c
pugi without heap allocation
altex111 Sep 19, 2023
8da9c35
working pugi with pmr memory pool
altex111 Sep 21, 2023
cb5bce2
test duration correction
altex111 Sep 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions kuka_rsi_hw_interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
Expand All @@ -23,26 +23,33 @@ find_package(kroshu_ros2_core REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(controller_manager_msgs REQUIRED)
find_package(pluginlib REQUIRED)
find_package(angles REQUIRED)
find_package(pugixml REQUIRED)

find_package(tinyxml_vendor REQUIRED)
find_package(TinyXML REQUIRED)
include_directories(include)

include_directories(include ${TinyXML2_INCLUDE_DIRS})
add_library(xml_handler SHARED
src/xml_handler/xml_element.cpp
src/xml_handler/xml_param.cpp
src/xml_handler/xml_string.cpp
)

add_library(${PROJECT_NAME} SHARED
src/kuka_hardware_interface.cpp
src/rsi_command_handler.cpp
src/pugi_command_handler.cpp
)

target_link_libraries(${PROJECT_NAME} xml_handler pugixml)

# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "JOINT_STATE_BROADCASTER_BUILDING_DLL")

# prevent pluginlib from using boost
target_compile_definitions(${PROJECT_NAME} PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")

ament_target_dependencies(${PROJECT_NAME} rclcpp sensor_msgs hardware_interface)
target_link_libraries(${PROJECT_NAME} tinyxml)


ament_target_dependencies(${PROJECT_NAME} rclcpp sensor_msgs hardware_interface angles)

add_executable(robot_manager_node
src/robot_manager_node.cpp)
Expand All @@ -51,7 +58,7 @@ target_link_libraries(robot_manager_node kroshu_ros2_core::communication_helpers

pluginlib_export_plugin_description_file(hardware_interface kuka_rsi_hw_interface.xml)

install(TARGETS ${PROJECT_NAME} robot_manager_node
install(TARGETS ${PROJECT_NAME} robot_manager_node xml_handler
DESTINATION lib/${PROJECT_NAME})

if(BUILD_TESTING)
Expand All @@ -71,9 +78,12 @@ if(BUILD_TESTING)
ament_lint_cmake()
ament_uncrustify(--language=C++)
ament_xmllint(--exclude ros_rsi.rsi.xml)

enable_testing()
add_subdirectory(test)
endif()

## EXPORTS
# # EXPORTS
ament_export_include_directories(
include
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,23 @@
#ifndef KUKA_RSI_HW_INTERFACE__KUKA_HARDWARE_INTERFACE_HPP_
#define KUKA_RSI_HW_INTERFACE__KUKA_HARDWARE_INTERFACE_HPP_

#include <kuka_rsi_hw_interface/udp_server.h>
#include <kuka_rsi_hw_interface/rsi_state.h>
#include <kuka_rsi_hw_interface/rsi_command.h>

#include <vector>
#include <string>
#include <memory>
#include <chrono>
#include <cmath>
#include <mutex>

#include "rclcpp/macros.hpp"

#include "kuka_rsi_hw_interface/udp_server.h"
#include "kuka_rsi_hw_interface/visibility_control.h"
#include "kuka_rsi_hw_interface/rsi_command_handler.hpp"

#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "hardware_interface/types/hardware_interface_type_values.hpp"
#include "rclcpp/macros.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_lifecycle/state.hpp"

Expand Down Expand Up @@ -112,14 +110,10 @@ class KukaRSIHardwareInterface : public hardware_interface::SystemInterface
std::vector<double> joint_pos_correction_deg_;

uint64_t ipoc_ = 0;
RSIState rsi_state_;
RSICommand rsi_command_;
RSICommandHandler command_handler_;
std::unique_ptr<UDPServer> server_;
std::string in_buffer_;
std::string out_buffer_;

static constexpr double R2D = 180 / M_PI;
static constexpr double D2R = M_PI / 180;
char in_buffer_[UDP_BUFFER_SIZE] = {0};
char out_buffer_[UDP_BUFFER_SIZE] = {0};
};
} // namespace kuka_rsi_hw_interface

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Copyright 2023 Komaromi Sándor
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef KUKA_RSI_HW_INTERFACE__PUGI_COMMAND_HANDLER_HPP_
#define KUKA_RSI_HW_INTERFACE__PUGI_COMMAND_HANDLER_HPP_

#include <pugixml.hpp>
#include <cstring>
#include <memory_resource>
#include <iostream>
#include <cassert>
#include <map>
#include <functional>

namespace kuka_rsi_hw_interface
{

void * custom_allocate(size_t size);
void custom_deallocate(void * ptr);

struct xml_memory_writer : pugi::xml_writer
{
char * buffer_;
size_t capacity_;
size_t result_;

xml_memory_writer()
: buffer_(0), capacity_(0), result_(0) {}
xml_memory_writer(char * buffer, size_t capacity)
: buffer_(buffer), capacity_(capacity), result_(0) {}

size_t written_size() const
{
return result_ < capacity_ ? result_ : capacity_;
}

virtual void write(const void * data, size_t size)
{
if (result_ < capacity_) {
size_t chunk = (capacity_ - result_ < size) ? capacity_ - result_ : size;
memcpy(buffer_ + result_, data, chunk);
}
result_ += size;
}
};

class print_resource : public std::pmr::memory_resource
{
public:
print_resource(std::string name, std::pmr::memory_resource * upstream)
: name_(name), upstream_(upstream)
{
assert(upstream);
}

private:
std::string name_;
std::pmr::memory_resource * upstream_;

void * do_allocate(std::size_t bytes, std::size_t alignment) override
{
std::cout << "[" << name_ << " (alloc)] Size: " << bytes << " Alignment: " << alignment <<
" ..." << std::endl;
auto result = upstream_->allocate(bytes, alignment);
std::cout << "[" << name_ << " (alloc)] ... Address: " << result << std::endl;
return result;
}

void do_deallocate(void * ptr, std::size_t bytes, std::size_t alignment) override
{
std::cout << "[" << name_ << " (dealloc)] Address: " << ptr << "Size: " << bytes <<
" Alignment: " << alignment << std::endl;
upstream_->deallocate(ptr, bytes, alignment);
}

bool do_is_equal(const std::pmr::memory_resource & other) const noexcept override
{
return this == &other;
}
};

class MemoryManager
{
public:
MemoryManager(std::pmr::memory_resource * upstream);
void * Allocate(size_t size);
void Deallocate(void * ptr);

private:
//std::pmr::polymorphic_allocator<std::byte> allocator_;
std::pmr::memory_resource * memory_pool_;
std::pmr::map<void *, size_t> memory_pool_sizes_;
};

class PugiCommandHandler
{
public:
pugi::xml_document state_doc;
pugi::xml_document command_doc;

PugiCommandHandler(const size_t buffer_size);
~PugiCommandHandler();

bool Decode(const char * buffer, const size_t buffer_size);
char * Encode(char * buffer, const size_t buffer_size);

private:
char * state_buffer_;
};

extern MemoryManager * memory_manager_handler;
} // namespace kuka_rsi_hw_interface


#endif // KUKA_RSI_HW_INTERFACE__PUGI_COMMAND_HANDLER_HPP_

This file was deleted.

Loading
Loading