|
|
@@ -1,10 +1,14 @@
|
|
|
#include "core/basic_obj_types.hpp"
|
|
|
#include "robot/ur/ur_defs.h"
|
|
|
+#include "robot/ur/scripts/ur_script.hpp"
|
|
|
+#include "third_party/base64.h"
|
|
|
+#include "third_party/scope_guard.hpp"
|
|
|
#include "utility/bit_operations.hpp"
|
|
|
#include "utility/config_utility.hpp"
|
|
|
#include "utility/coro_worker.hpp"
|
|
|
#include "utility/coro_worker_helper_func.hpp"
|
|
|
#include "utility/debug_utility.hpp"
|
|
|
+#include "utility/dynamic_pool.hpp"
|
|
|
#include "utility/name_translator.hpp"
|
|
|
#include "utility/variable_helper.hpp"
|
|
|
#include "utility/versatile_buffer2.hpp"
|
|
|
@@ -15,7 +19,6 @@
|
|
|
#include <boost/asio/detached.hpp>
|
|
|
#include <boost/asio/use_awaitable.hpp>
|
|
|
#include <boost/asio/write.hpp>
|
|
|
-#include <boost/iostreams/device/mapped_file.hpp>
|
|
|
#include <boost/smart_ptr/scoped_ptr.hpp>
|
|
|
#include <boost/system/error_code.hpp>
|
|
|
|
|
|
@@ -40,7 +43,6 @@ namespace sophiar {
|
|
|
using boost::asio::co_spawn;
|
|
|
using boost::asio::detached;
|
|
|
using boost::asio::use_awaitable;
|
|
|
- using boost::iostreams::mapped_file;
|
|
|
using boost::scoped_ptr;
|
|
|
using boost::system::error_code;
|
|
|
|
|
|
@@ -331,6 +333,42 @@ namespace sophiar {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ static void unit_ur_to_sophiar(Eigen::Isometry3d &trans) {
|
|
|
+ trans.translation() *= 1000; // m -> mm
|
|
|
+ }
|
|
|
+
|
|
|
+ static void unit_ur_to_sophiar(vector6d_type &arr) {
|
|
|
+ for (int i = 0; i < 3; ++i) { // only for the linear velocity part
|
|
|
+ arr[i] *= 1000; // m -> mm
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static void unit_ur_to_sophiar(Eigen::Vector3d &vec) {
|
|
|
+ vec *= 1000; // m -> mm
|
|
|
+ }
|
|
|
+
|
|
|
+ static void unit_ur_to_sophiar(double &val) {
|
|
|
+ val *= 1000; // m -> mm
|
|
|
+ }
|
|
|
+
|
|
|
+ static void unit_sophiar_to_ur(Eigen::Isometry3d &trans) {
|
|
|
+ trans.translation() *= 0.001; // mm -> m
|
|
|
+ }
|
|
|
+
|
|
|
+ static void unit_sophiar_to_ur(vector6d_type &arr) {
|
|
|
+ for (int i = 0; i < 3; ++i) { // only for the linear velocity part
|
|
|
+ arr[i] *= 0.001; // mm -> m
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static void unit_sophiar_to_ur(Eigen::Vector3d &vec) {
|
|
|
+ vec *= 0.001; // mm -> m
|
|
|
+ }
|
|
|
+
|
|
|
+ static void unit_sophiar_to_ur(double &val) {
|
|
|
+ val *= 0.001; // mm -> m
|
|
|
+ }
|
|
|
+
|
|
|
static Eigen::Isometry3d identity_transform;
|
|
|
static vector6d_type identity_transform_vec;
|
|
|
|
|
|
@@ -340,14 +378,13 @@ namespace sophiar {
|
|
|
static constexpr uint16_t rtde_port = 30004;
|
|
|
static constexpr uint16_t urscript_port = 30002;
|
|
|
static constexpr uint16_t rtde_protocol_version = 2;
|
|
|
- static constexpr auto urscript_path = "scripts/URScript.script";
|
|
|
|
|
|
static constexpr auto ur_endian = boost::endian::order::big;
|
|
|
|
|
|
static constexpr double joint_acceleration_default = 1.4; // rad/s^2
|
|
|
- static constexpr double tcp_acceleration_default = 1.2; // m/s^2
|
|
|
+ static constexpr double tcp_acceleration_default = 1200; // mm/s^2
|
|
|
static constexpr double joint_speed_default = 1.05; // rad/s
|
|
|
- static constexpr double tcp_speed_default = 0.25; // m/s
|
|
|
+ static constexpr double tcp_speed_default = 250; // mm/s
|
|
|
|
|
|
ur_interface *q_this = nullptr;
|
|
|
|
|
|
@@ -497,10 +534,12 @@ namespace sophiar {
|
|
|
tcp::socket urscript_socket(*global_context);
|
|
|
co_await urscript_socket.async_connect({ur_ip, urscript_port}, use_awaitable);
|
|
|
// send script file
|
|
|
- auto script_file = mapped_file(urscript_path, boost::iostreams::mapped_file::readonly);
|
|
|
- assert(script_file.is_open());
|
|
|
+ auto script_len = macaron::Base64::Decode(ur_script_data, nullptr);
|
|
|
+ auto script_data = (char *) global_dynamic_pool->allocate(script_len);
|
|
|
+ auto closer = sg::make_scope_guard([&]() { global_dynamic_pool->deallocate(script_data, script_len); });
|
|
|
+ macaron::Base64::Decode(ur_script_data, script_data);
|
|
|
co_await async_write(urscript_socket,
|
|
|
- boost::asio::buffer(script_file.const_data(), script_file.size()),
|
|
|
+ boost::asio::buffer(script_data, script_len),
|
|
|
use_awaitable);
|
|
|
co_return;
|
|
|
}
|
|
|
@@ -520,7 +559,7 @@ namespace sophiar {
|
|
|
|
|
|
void handle_data_package(income_reader_type &reader) {
|
|
|
auto content = ur_status_content{};
|
|
|
- const auto &status = content.content;
|
|
|
+ auto &status = content.content;
|
|
|
content.fill_from(reader);
|
|
|
assert(content.recipe_id == outputs_recipe_id);
|
|
|
|
|
|
@@ -531,12 +570,21 @@ namespace sophiar {
|
|
|
try_update_variable_value<array6_obj>(target_qdd_index, status.target_qdd, ts);
|
|
|
try_update_variable_value<array6_obj>(actual_q_index, status.actual_q, ts);
|
|
|
try_update_variable_value<array6_obj>(actual_qd_index, status.actual_qd, ts);
|
|
|
+
|
|
|
vector6d_to_transform(status.target_TCP_pose, trans_tmp);
|
|
|
+ unit_ur_to_sophiar(trans_tmp);
|
|
|
try_update_variable_value<transform_obj>(target_pose_index, trans_tmp, ts);
|
|
|
+
|
|
|
+ unit_ur_to_sophiar(status.target_TCP_speed);
|
|
|
try_update_variable_value<array6_obj>(target_speed_index, status.target_TCP_speed, ts);
|
|
|
+
|
|
|
vector6d_to_transform(status.actual_TCP_pose, trans_tmp);
|
|
|
+ unit_ur_to_sophiar(trans_tmp);
|
|
|
try_update_variable_value<transform_obj>(actual_pose_index, trans_tmp, ts);
|
|
|
+
|
|
|
+ unit_ur_to_sophiar(status.actual_TCP_speed);
|
|
|
try_update_variable_value<array6_obj>(actual_speed_index, status.actual_TCP_speed, ts);
|
|
|
+
|
|
|
try_update_variable_value<bool_obj>(is_controllable_index, determine_is_controllable(status), ts);
|
|
|
try_update_variable_value<bool_obj>(is_moving_index, status.is_moving, ts);
|
|
|
}
|
|
|
@@ -678,6 +726,11 @@ namespace sophiar {
|
|
|
try_query_variable_value<double_obj>(
|
|
|
tcp_speed_limit_index, tcp_speed_default);
|
|
|
|
|
|
+ unit_sophiar_to_ur(cmd_content->tcp_pose);
|
|
|
+ unit_sophiar_to_ur(cmd_content->target);
|
|
|
+ unit_sophiar_to_ur(cmd_content->param_a);
|
|
|
+ unit_sophiar_to_ur(cmd_content->param_v);
|
|
|
+
|
|
|
co_await send_rtde_packet(*content);
|
|
|
co_return true;
|
|
|
};
|
|
|
@@ -712,6 +765,10 @@ namespace sophiar {
|
|
|
try_query_variable_value<double_obj>(
|
|
|
tcp_acceleration_limit_index, tcp_acceleration_default);
|
|
|
|
|
|
+ unit_sophiar_to_ur(cmd_content->tcp_pose);
|
|
|
+ unit_sophiar_to_ur(cmd_content->target);
|
|
|
+ unit_sophiar_to_ur(cmd_content->param_a);
|
|
|
+
|
|
|
co_await send_rtde_packet(*content);
|
|
|
co_return true;
|
|
|
};
|