plcopen 0.22.0
载入中...
搜索中...
未找到
gantry.h
浏览该文件的文档.
1#pragma once
2
3// Reference kinematics #1 (approved matrix, decision #7): Cartesian gantry —
4// a per-axis linear map joint = (cartesian - offset) / scale. The simplest
5// mechanism above the identity, singularity-free by construction.
6
7#include <cmath>
8#include <cstddef>
9
10#include "kin/kinematics.h"
11
12namespace plcopen::core::kin
13{
14
15class CartesianGantry final : public Kinematics
16{
17public:
18 // axis_count in [2, 3]; scale must be nonzero per axis.
19 CartesianGantry(std::size_t axis_count,
20 const double *scale,
21 const double *offset)
22 : count_(axis_count)
23 {
24 for(std::size_t i = 0; i < count_ && i < 3; ++i) {
25 scale_[i] = scale[i];
26 offset_[i] = offset[i];
27 }
28 }
29
30 std::size_t joint_count() const override
31 {
32 return count_;
33 }
34
35 std::size_t cartesian_count() const override
36 {
37 return count_;
38 }
39
40 rt::ErrorCode forward(const double *joints,
41 std::size_t joint_count,
42 geom::Vec3 &cartesian) const override
43 {
44 if(joint_count != count_) {
46 }
47 const double x = scale_[0] * joints[0] + offset_[0];
48 const double y = count_ > 1 ? scale_[1] * joints[1] + offset_[1] : 0.0;
49 const double z = count_ > 2 ? scale_[2] * joints[2] + offset_[2] : 0.0;
50 cartesian = geom::Vec3{x, y, z};
51 return rt::ErrorCode::ok;
52 }
53
55 const double *,
56 std::size_t joint_count,
57 double *joints_out) const override
58 {
59 if(joint_count != count_) {
61 }
62 const double coordinates[3] = {cartesian.x, cartesian.y, cartesian.z};
63 for(std::size_t i = 0; i < count_; ++i) {
64 if(scale_[i] == 0.0 || !std::isfinite(coordinates[i])) {
66 }
67 joints_out[i] = (coordinates[i] - offset_[i]) / scale_[i];
68 }
69 return rt::ErrorCode::ok;
70 }
71
72 double singularity_margin(const double *, std::size_t) const override
73 {
74 return 1e30; // linear mechanism: no singular configurations
75 }
76
77private:
78 std::size_t count_ = 0;
79 double scale_[3] = {1.0, 1.0, 1.0};
80 double offset_[3] = {0.0, 0.0, 0.0};
81};
82
83} // namespace plcopen::core::kin
rt::ErrorCode inverse(geom::Vec3 cartesian, const double *, std::size_t joint_count, double *joints_out) const override
rt::ErrorCode forward(const double *joints, std::size_t joint_count, geom::Vec3 &cartesian) const override
std::size_t cartesian_count() const override
std::size_t joint_count() const override
double singularity_margin(const double *, std::size_t) const override
CartesianGantry(std::size_t axis_count, const double *scale, const double *offset)