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