| xCore-SDK 0.7.1 xCore SDK C# API

converter_cli.hpp
1#pragma once
2#ifndef XCORESDK_SRC_MANAGED_CONVERTER_CLI_HPP_
3#define XCORESDK_SRC_MANAGED_CONVERTER_CLI_HPP_
4
5#include <system_error>
6#include "data_types.h"
7#include "data_types_cli.hpp"
8
9 namespace rokae::clr {
10 template <size_t S>
11 array<double>^ convertArray(const std::array<double, S>& _in) {
12 auto ret = gcnew array<double>((int)_in.size());
13 for (int i = 0; i < (int)_in.size(); ++i) {
14 ret[i] = _in[i];
15 }
16 return ret;
17 }
18
19 template <typename T>
20 array<T>^ convertVectorToArray(const std::vector<T>& _in) {
21 auto ret = gcnew array<T>((int)_in.size());
22 for (int i = 0; i < (int)_in.size(); ++i) {
23 ret[i] = _in[i];
24 }
25 return ret;
26 }
27
28 template <size_t S>
29 std::array<double, S> convertArray(array<double>^ _in) {
30 std::array<double, S> _out{};
31 for (unsigned int i = 0; i < ((_in->Length < S) ? _in->Length : S); ++i) {
32 _out[i] = _in[i];
33 }
34 return _out;
35 }
36
37 template <typename T>
38 std::vector<T> convertVector(List<T>^ _in) {
39 std::vector<T> _out(_in->Count);
40 for (int i = 0; i < _in->Count; ++i) {
41 _out[i] = _in[i];
42 }
43 return _out;
44 }
45
46 template <typename T>
47 std::vector<T> convertArrayToVector(array<T>^ in) {
48 std::vector<T> out(in->Length);
49 for (decltype(in->Length) i = 0; i < in->Length; ++i) {
50 out[i] = in[i];
51 }
52 return out;
53 }
54
55 template <typename T>
56 void convertVector(const std::vector<T>& in, List<T>^% out) {
57 out->Clear();
58 for (const auto& d : in) {
59 out->Add(d);
60 }
61 }
62
63 void convertErrorCode(const std::error_code& _in, ErrorCode^% _out);
64 Load^ convertLoad(const rokae::Load& _in);
65 Toolset^ convertToolset(const rokae::Toolset& _in);
66
67 void convertLoad(Load^ in, rokae::Load& out);
68 rokae::Toolset convertToolset(Toolset^ in);
69
70 rokae::Frame convertFrame(Frame^ frame);
71 std::string convertString(String^ in);
72
73 Frame^ convertFrame(const rokae::Frame& _in);
74
75 rokae::CartesianPosition convertCartesianPosition(CartesianPosition^ posture);
76
77 CartesianPosition^ convertCartesianPosition(const rokae::CartesianPosition& _cart);
78
79 void convertOffset(CartesianPosition::Offset^ in, rokae::CartesianPosition::Offset& out);
80
81 template <class Cmd>
82 std::vector<Cmd> convertCartMove(List<MoveCommand^>^ cmds) {
83 std::vector<Cmd> _cmds;
84
85 for each (MoveCommand ^ cmd in cmds) {
86 Cmd _cmd(convertCartesianPosition(cmd->cartTarget), cmd->speed, cmd->zone);
87 convertOffset(cmd->cartTargetOffset, _cmd.offset);
88
89 if constexpr (std::is_same_v<MoveLCommand, Cmd>) {
90 _cmd.rotSpeed = cmd->rotSpeed;
91 }
92 else {
93 _cmd.jointSpeed = cmd->jointSpeed;
94 }
95
96 _cmd.customInfo = convertString(cmd->customInfo);
97 _cmds.emplace_back(_cmd);
98 }
99 return _cmds;
100 }
101
102 std::vector<MoveCCommand> convertCircularMove(List<MoveCommand^>^ cmds);
103
104 std::vector<MoveCFCommand> convertCircularFullMove(List<MoveCommand^>^ cmds);
105
106 std::vector<rokae::MoveSPCommand> convertSpiralMove(List<MoveCommand^>^ cmds);
107
108 std::vector<rokae::MoveAbsJCommand> convertJointMove(List<MoveCommand^>^ cmds);
109
110 rokae::MoveWaitCommand convertWaitMove(List<MoveCommand^>^ cmds);
111
112}
113
114#endif // XCORESDK_SRC_MANAGED_CONVERTER_CLI_HPP_
data_types_cli.hpp