Skip to content

Commit 7bd06ff

Browse files
committed
Merge remote-tracking branch 'origin/build/update-to-jazzy' into enhancement/try-new-cm
2 parents 6617dd7 + b976e08 commit 7bd06ff

File tree

10 files changed

+118
-28
lines changed

10 files changed

+118
-28
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ endif()
1515

1616
find_package(ament_cmake REQUIRED)
1717
find_package(dynamixel_sdk REQUIRED)
18+
find_package(jitsuyo REQUIRED)
1819
find_package(kansei_interfaces REQUIRED)
1920
find_package(keisan REQUIRED)
2021
find_package(rclcpp REQUIRED)
@@ -70,6 +71,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
7071

7172
ament_target_dependencies(${PROJECT_NAME}
7273
dynamixel_sdk
74+
jitsuyo
7375
kansei_interfaces
7476
keisan
7577
rclcpp
@@ -170,6 +172,7 @@ endif()
170172

171173
ament_export_dependencies(
172174
dynamixel_sdk
175+
jitsuyo
173176
kansei_interfaces
174177
keisan
175178
rclcpp

include/tachimawari/control/controller/packet/protocol_1/model/packet.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#ifndef TACHIMAWARI__CONTROL__CONTROLLER__PACKET__PROTOCOL_1__MODEL__PACKET_HPP_
2222
#define TACHIMAWARI__CONTROL__CONTROLLER__PACKET__PROTOCOL_1__MODEL__PACKET_HPP_
2323

24+
#include <cstdint>
2425
#include <string>
2526
#include <vector>
2627

include/tachimawari/control/controller/packet/protocol_1/utils/word.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#ifndef TACHIMAWARI__CONTROL__CONTROLLER__PACKET__PROTOCOL_1__UTILS__WORD_HPP_
2222
#define TACHIMAWARI__CONTROL__CONTROLLER__PACKET__PROTOCOL_1__UTILS__WORD_HPP_
2323

24+
#include <cstdint>
2425
#include <string>
2526

2627
namespace tachimawari::control::protocol_1

include/tachimawari/control/sdk/module/dynamixel_sdk.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <memory>
2626
#include <string>
2727
#include <vector>
28+
#include <unordered_map>
2829

2930
#include "dynamixel_sdk/dynamixel_sdk.h"
3031
#include "tachimawari/control/manager/control_manager.hpp"

include/tachimawari/control/sdk/packet/model/group_bulk_read.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <memory>
2626
#include <string>
2727
#include <vector>
28+
#include <unordered_map>
2829

2930
#include "dynamixel_sdk/dynamixel_sdk.h"
3031
#include "tachimawari/joint/model/joint.hpp"

include/tachimawari/joint/model/joint_id.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define TACHIMAWARI__JOINT__MODEL__JOINT_ID_HPP_
2323

2424
#include <array>
25+
#include <cstdint>
2526
#include <map>
2627
#include <string>
2728

launch/tachimawari_launch.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright (c) 2024 ICHIRO ITS
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
# THE SOFTWARE.
20+
21+
import os
22+
import socket
23+
from launch import LaunchDescription
24+
from launch_ros.actions import Node
25+
26+
def generate_launch_description():
27+
hostname = socket.gethostname()
28+
config_path = os.path.expanduser(f'~/ros2-ws/configuration/{hostname}/ipm/')
29+
30+
return LaunchDescription([
31+
Node(
32+
package='tachimawari',
33+
executable='main',
34+
name='main',
35+
output='screen',
36+
arguments=['cm740', config_path],
37+
respawn=True,
38+
respawn_delay=1
39+
)
40+
])

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<license>MIT License</license>
99
<buildtool_depend>ament_cmake</buildtool_depend>
1010
<depend>dynamixel_sdk</depend>
11+
<depend>jitsuyo</depend>
1112
<depend>kansei_interfaces</depend>
1213
<depend>keisan</depend>
1314
<depend>rclcpp</depend>

src/tachimawari/joint/tf2/tf2_manager.cpp

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,88 @@
2121
#include <algorithm>
2222
#include <fstream>
2323
#include <memory>
24-
#include <nlohmann/json.hpp>
2524
#include <string>
2625
#include <vector>
2726

2827
#include "tachimawari/joint/tf2/tf2_manager.hpp"
2928

29+
#include "jitsuyo/config.hpp"
30+
#include "nlohmann/json.hpp"
31+
3032
namespace tachimawari::joint
3133
{
3234

3335
Tf2Manager::Tf2Manager() {}
3436

3537
bool Tf2Manager::load_configuration(const std::string & path)
3638
{
37-
std::string ss = path + "frame_measurements.json";
38-
39-
std::ifstream input(ss, std::ifstream::in);
40-
if (!input.is_open()) {
41-
throw std::runtime_error("Unable to open `" + ss + "`!");
39+
nlohmann::json config;
40+
if (!jitsuyo::load_config(path, "frame_measurements.json", config)) {
41+
return false;
4242
}
4343

44-
nlohmann::json config = nlohmann::json::parse(input);
44+
bool valid_config = true;
4545

4646
for (auto & item : config.items()) {
4747
// Get all config
48-
try {
49-
std::string name = item.key();
50-
double translation_x = item.value().at("translation").at("x");
51-
double translation_y = item.value().at("translation").at("y");
52-
double translation_z = item.value().at("translation").at("z");
53-
double const_roll = item.value().at("const_rpy").at("roll");
54-
double const_pitch = item.value().at("const_rpy").at("pitch");
55-
double const_yaw = item.value().at("const_rpy").at("yaw");
56-
auto map_string_id = FrameId::frame_string_id.find(name);
57-
58-
uint8_t id = map_string_id->second;
59-
frames.push_back(
60-
Frame(id, translation_x, translation_y, translation_z, const_roll, const_pitch, const_yaw));
61-
} catch (nlohmann::json::parse_error & ex) {
62-
std::cerr << "parse error at byte " << ex.byte << std::endl;
63-
throw ex;
48+
double translation_x;
49+
double translation_y;
50+
double translation_z;
51+
double const_roll;
52+
double const_pitch;
53+
double const_yaw;
54+
55+
std::string name = item.key();
56+
57+
bool valid_section = true;
58+
nlohmann::json section;
59+
if (jitsuyo::assign_val(config, name, section)) {
60+
nlohmann::json translation;
61+
nlohmann::json const_rpy;
62+
63+
if (jitsuyo::assign_val(section, "translation", translation)) {
64+
bool valid_translation = true;
65+
valid_translation &= jitsuyo::assign_val(translation, "x", translation_x);
66+
valid_translation &= jitsuyo::assign_val(translation, "y", translation_y);
67+
valid_translation &= jitsuyo::assign_val(translation, "z", translation_z);
68+
if (!valid_translation) {
69+
std::cout << "Error found at section `translation`" << std::endl;
70+
valid_section = false;
71+
}
72+
} else {
73+
valid_section = false;
74+
}
75+
76+
if (jitsuyo::assign_val(section, "const_rpy", const_rpy)) {
77+
bool valid_const_rpy = true;
78+
valid_const_rpy &= jitsuyo::assign_val(const_rpy, "roll", const_roll);
79+
valid_const_rpy &= jitsuyo::assign_val(const_rpy, "pitch", const_pitch);
80+
valid_const_rpy &= jitsuyo::assign_val(const_rpy, "yaw", const_yaw);
81+
if (!valid_const_rpy) {
82+
std::cout << "Error found at section `const_rpy`" << std::endl;
83+
valid_section = false;
84+
}
85+
} else {
86+
valid_section = false;
87+
}
88+
} else {
89+
valid_section = false;
6490
}
91+
92+
if (!valid_section) {
93+
valid_config = false;
94+
continue;
95+
}
96+
97+
auto map_string_id = FrameId::frame_string_id.find(name);
98+
99+
uint8_t id = map_string_id->second;
100+
frames.push_back(
101+
Frame(id, translation_x, translation_y, translation_z, const_roll, const_pitch, const_yaw));
102+
}
103+
104+
if (!valid_config) {
105+
throw std::runtime_error("Failed to load config file `" + path + "frame_measurements.json`");
65106
}
66107

67108
return true;

src/tachimawari_main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727

2828
int main(int argc, char * argv[])
2929
{
30-
rclcpp::init(argc, argv);
30+
auto args = rclcpp::init_and_remove_ros_arguments(argc, argv);
3131

32-
if (argc < 2) {
32+
if (args.size() < 2) {
3333
std::cerr << "Please specify the mode! [sdk / cm740]" << std::endl;
3434
return 0;
35-
} else if (argc < 3) {
35+
} else if (args.size() < 3) {
3636
std::cerr << "Please specify the tf configuration path" << std::endl;
3737
}
3838

39-
std::string mode = argv[1];
40-
std::string path = argv[2];
39+
std::string mode = args[1];
40+
std::string path = args[2];
4141
std::shared_ptr<tachimawari::control::ControlManager> controller;
4242

4343
if (mode == "sdk") {

0 commit comments

Comments
 (0)