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 72 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
18 changes: 13 additions & 5 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 @@ -29,29 +29,37 @@ find_package(TinyXML REQUIRED)

include_directories(include ${TinyXML2_INCLUDE_DIRS})
altex111 marked this conversation as resolved.
Show resolved Hide resolved

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
)

target_link_libraries(${PROJECT_NAME} xml_handler)

# 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)



add_executable(robot_manager_node
src/robot_manager_node.cpp)
ament_target_dependencies(robot_manager_node rclcpp kroshu_ros2_core sensor_msgs controller_manager_msgs)
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 @@ -73,7 +81,7 @@ if(BUILD_TESTING)
ament_xmllint(--exclude ros_rsi.rsi.xml)
endif()

## EXPORTS
# # EXPORTS
ament_export_include_directories(
include
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
#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 <kuka_rsi_hw_interface/rsi_command_handler.hpp>
// #include <kuka_rsi_hw_interface/rsi_state.h>
// #include <kuka_rsi_hw_interface/rsi_command.h>

#include <vector>
#include <string>
Expand Down Expand Up @@ -112,11 +113,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_;
char in_buffer_[UDP_BUFFER_SIZE] = {0};
char out_buffer_[UDP_BUFFER_SIZE] = {0};

static constexpr double R2D = 180 / M_PI;
static constexpr double D2R = M_PI / 180;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*********************************************************************
* Software License Agreement (BSD License)
altex111 marked this conversation as resolved.
Show resolved Hide resolved
*
* Copyright (c) 2014 Norwegian University of Science and Technology
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Norwegian University of Science and
* Technology, nor the names of its contributors may be used to
* endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/

/*
* Author: Komaromi Sandor
*/

#ifndef KUKA_RSI_HW_INTERFACE__RSI_COMMAND_HANDLER_H_
#define KUKA_RSI_HW_INTERFACE__RSI_COMMAND_HANDLER_H_


#include "xml_handler/xml_element.hpp"

namespace kuka_rsi_hw_interface
{

class RSICommandHandler
{
public:
altex111 marked this conversation as resolved.
Show resolved Hide resolved
RSICommandHandler();
~RSICommandHandler() = default;


inline const xml::XMLElement & GetState() const {return state_data_structure_;}
inline const xml::XMLElement & GetCommand() const {return command_data_structure_;}

template<typename T>
bool SetCommandParam(
const std::string & elementName, const std::string & paramName,
const T & param)
{
try {
return command_data_structure_.Element(elementName)->SetParam<T>(paramName, param);
} catch (const std::exception & e) {
std::cerr << e.what() << '\n';
return false;
}
}

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

private:
xml::XMLElement command_data_structure_;
xml::XMLElement state_data_structure_;

void decodeNode(
xml::XMLElement & element, char * const buffer, char * & buffer_it,
const size_t buffer_size);

void encodeNode(
xml::XMLElement & element, char * & buffer_it, int & size_left);
};
} // namespace kuka_rsi_hw_interface


#endif // KUKA_RSI_HW_INTERFACE__RSI_COMMAND_HANDLER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class RSIState
RIst_el->Attribute("A", &cart_position[3]);
RIst_el->Attribute("B", &cart_position[4]);
RIst_el->Attribute("C", &cart_position[5]);
// Extract cartesian actual position
// Extract cartesian setpoint position
TiXmlElement * RSol_el = rob->FirstChildElement("RSol");
RSol_el->Attribute("X", &initial_cart_position[0]);
RSol_el->Attribute("Y", &initial_cart_position[1]);
Expand Down
26 changes: 15 additions & 11 deletions kuka_rsi_hw_interface/include/kuka_rsi_hw_interface/udp_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@

#include "rclcpp/rclcpp.hpp"

#define BUFSIZE 1024
constexpr size_t UDP_BUFFER_SIZE = 1024;

class UDPServer
{
Expand Down Expand Up @@ -102,20 +102,20 @@ class UDPServer
}
}

ssize_t send(std::string & buffer)
ssize_t send(char * buffer)
{
ssize_t bytes = 0;
bytes = sendto(
sockfd_, buffer.c_str(),
buffer.size(), 0, (struct sockaddr *) &clientaddr_, clientlen_);
sockfd_, buffer,
strlen(buffer), 0, (struct sockaddr *) &clientaddr_, clientlen_);
if (bytes < 0) {
RCLCPP_ERROR(rclcpp::get_logger("UDPServer"), "Error in send");
}

return bytes;
}

ssize_t recv(std::string & buffer)
ssize_t recv(char * buffer)
{
ssize_t bytes = 0;

Expand All @@ -133,9 +133,11 @@ class UDPServer
}

if (FD_ISSET(sockfd_, &read_fds)) {
memset(buffer_, 0, BUFSIZE);
memset(buffer_, 0, UDP_BUFFER_SIZE);
bytes =
recvfrom(sockfd_, buffer_, BUFSIZE, 0, (struct sockaddr *) &clientaddr_, &clientlen_);
recvfrom(
sockfd_, buffer_, UDP_BUFFER_SIZE, 0, (struct sockaddr *) &clientaddr_,
&clientlen_);
if (bytes < 0) {
RCLCPP_ERROR(rclcpp::get_logger("UDPServer"), "Error in receive");
}
Expand All @@ -144,14 +146,16 @@ class UDPServer
}

} else {
memset(buffer_, 0, BUFSIZE);
bytes = recvfrom(sockfd_, buffer_, BUFSIZE, 0, (struct sockaddr *) &clientaddr_, &clientlen_);
memset(buffer_, 0, UDP_BUFFER_SIZE);
bytes = recvfrom(
sockfd_, buffer_, UDP_BUFFER_SIZE, 0, (struct sockaddr *) &clientaddr_,
&clientlen_);
if (bytes < 0) {
RCLCPP_ERROR(rclcpp::get_logger("UDPServer"), "Error in receive");
}
}

buffer = std::string(buffer_);
strncpy(buffer, buffer_, bytes);

return bytes;
}
Expand All @@ -166,7 +170,7 @@ class UDPServer
socklen_t clientlen_;
struct sockaddr_in serveraddr_;
struct sockaddr_in clientaddr_;
char buffer_[BUFSIZE];
char buffer_[UDP_BUFFER_SIZE];
int optval;
};

Expand Down
129 changes: 129 additions & 0 deletions kuka_rsi_hw_interface/include/xml_handler/xml_element.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Copyright 2023 Komáromi 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 XML__XML_ELEMENT_H_
#define XML__XML_ELEMENT_H_

#include <map>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <functional>

#include "xml_param.hpp"

namespace xml
{
inline bool operator<(const XMLString & a, const std::string & b)
altex111 marked this conversation as resolved.
Show resolved Hide resolved
{
if (a.length_ < b.length()) {
return true;
} else if (a.length_ > b.length()) {
return false;
} else {
return strncmp(a.data_ptr_, b.c_str(), a.length_) < 0;
}
}

inline bool operator<(const std::string & b, const XMLString & a)
{
if (b.length() < a.length_) {
return true;
} else if (b.length() > a.length_) {
return false;
} else {
return strncmp(b.c_str(), a.data_ptr_, a.length_) < 0;
}
}

class XMLElement
{
private:
static XMLString castXMLString(char * & str_ptr);
XMLElement * element(const std::string & elementName, int depth = 0);
const XMLElement * const getElement(
const std::string & elementName,
int depth = 0) const;

std::map<std::string, XMLParam, std::less<>> params_;
std::vector<XMLElement> childs_;
std::string name_;

public:
XMLElement(const std::string & name)
: name_(name) {}
XMLElement() = default;
~XMLElement() = default;

inline std::string GetName() const {return name_;}
inline void SetName(const std::string & name) {name_ = name;}
inline const std::vector<XMLElement> & GetChilds() const {return childs_;}
inline std::vector<XMLElement> & Childs() {return childs_;}
inline std::map<std::string, XMLParam, std::less<>> & Params() {return params_;}

inline XMLElement * Element(const std::string & elementName) {return element(elementName);}
inline const XMLElement * const GetElement(
const std::string & elementName) const {return getElement(elementName);}

bool CastParam(const XMLString & key, char * & str_ptr);
bool IsParamNameValid(XMLString & key, char * & str_ptr);
bool IsNameValid(XMLString & key, char * & str_ptr);

// TODO (Komaromi): When cpp20 is in use, use requires so only the types we set can be used
Svastits marked this conversation as resolved.
Show resolved Hide resolved
template<typename T>
bool GetParam(const std::string & key, T & param) const
{
auto param_it = params_.find(key);
if (param_it != params_.end()) {
if constexpr (std::is_same<T, bool>::value || std::is_same<T, long>::value ||
std::is_same<T, double>::value || std::is_same<T, XMLString>::value)
{
param = param_it->second.GetParamValue<T>();
return true;
}
}
return false;
}

template<typename T>
T GetParam(const std::string & key) const
{
auto param_it = params_.find(key);
if (param_it != params_.end()) {
return param_it->second.GetParamValue<T>();
}
throw std::range_error("Could not find key in parameter list");
}

// TODO (Komaromi): When cpp20 is in use, use requires so only the types we set can be used
template<typename T>
bool SetParam(const std::string & key, const T & param)
{
auto param_it = params_.find(key);
if (param_it != params_.end()) {
if constexpr (std::is_same<T, bool>::value || std::is_same<T, long>::value ||
std::is_same<T, double>::value || std::is_same<T, XMLString>::value)
{
param_it->second.param_value_ = param;
return true;
}
}
return false;
}
};
}

#endif // XML__XML_ELEMENT_H_
Loading