plcopen 0.22.0
载入中...
搜索中...
未找到
units.h
浏览该文件的文档.
1#pragma once
2
3#include <cstdint>
4
5namespace plcopen::core::rt
6{
7
8class CycleConfig
9{
10public:
11 static constexpr CycleConfig from_period_ns(std::int64_t period_ns)
12 {
13 const double ps = static_cast<double>(period_ns) * 1e-9;
14 return CycleConfig(period_ns, ps);
15 }
16
17 static constexpr CycleConfig at_1khz()
18 {
19 return from_period_ns(1'000'000);
20 }
21
22 static constexpr CycleConfig at_2khz()
23 {
24 return from_period_ns(500'000);
25 }
26
27 static constexpr CycleConfig at_4khz()
28 {
29 return from_period_ns(250'000);
30 }
31
32 constexpr std::int64_t period_ns() const
33 {
34 return period_ns_;
35 }
36
37 constexpr double period_seconds() const
38 {
39 return ps_;
40 }
41
42 constexpr double velocity_to_cycle(double velocity_per_second) const
43 {
44 return velocity_per_second * ps_;
45 }
46
47 constexpr double acceleration_to_cycle(double accel_per_second_sq) const
48 {
49 return accel_per_second_sq * ps2_;
50 }
51
52 constexpr double jerk_to_cycle(double jerk_per_second_cubed) const
53 {
54 return jerk_per_second_cubed * ps3_;
55 }
56
57 constexpr double velocity_to_si(double velocity_per_cycle) const
58 {
59 return velocity_per_cycle / ps_;
60 }
61
62 constexpr double acceleration_to_si(double accel_per_cycle_sq) const
63 {
64 return accel_per_cycle_sq / ps2_;
65 }
66
67 constexpr double jerk_to_si(double jerk_per_cycle_cubed) const
68 {
69 return jerk_per_cycle_cubed / ps3_;
70 }
71
72private:
73 constexpr CycleConfig(std::int64_t period_ns, double ps)
74 : period_ns_(period_ns)
75 , ps_(ps)
76 , ps2_(ps * ps)
77 , ps3_(ps * ps * ps)
78 {
79 }
80
81 std::int64_t period_ns_ = 1'000'000;
82 double ps_ = 0.001;
83 double ps2_ = 0.000001;
84 double ps3_ = 0.000000001;
85};
86
87} // namespace plcopen::core::rt
static constexpr CycleConfig at_1khz()
定义 units.h:17
constexpr double velocity_to_cycle(double velocity_per_second) const
定义 units.h:42
constexpr double acceleration_to_si(double accel_per_cycle_sq) const
定义 units.h:62
constexpr double velocity_to_si(double velocity_per_cycle) const
定义 units.h:57
static constexpr CycleConfig from_period_ns(std::int64_t period_ns)
定义 units.h:11
constexpr double jerk_to_si(double jerk_per_cycle_cubed) const
定义 units.h:67
constexpr double jerk_to_cycle(double jerk_per_second_cubed) const
定义 units.h:52
static constexpr CycleConfig at_2khz()
定义 units.h:22
constexpr std::int64_t period_ns() const
定义 units.h:32
static constexpr CycleConfig at_4khz()
定义 units.h:27
constexpr double acceleration_to_cycle(double accel_per_second_sq) const
定义 units.h:47
constexpr double period_seconds() const
定义 units.h:37