Chassis
v2.1.1
Chassisはロボコンでの足回り制御を行うためのC++ライブラリである。
Loading...
Searching...
No Matches
Omni.h
Go to the documentation of this file.
1
#ifndef CHASSIS_OMNI_H_
2
#define CHASSIS_OMNI_H_
7
#include <
CoordinateUnit.h
>
8
9
#include <array>
10
#include <cmath>
11
#include <functional>
12
#include <utility>
13
14
namespace
rct
{
15
21
24
template
<
int
N>
25
struct
Omni
{
26
static_assert
(
N
> 0,
"template parameter N must be greater than 0"
);
27
31
template
<
class
F>
32
Omni
(
F
&&
f
) : f_{std::
forward
<
F
>(
f
)} {}
33
36
static
constexpr
int
size
()
noexcept
{
37
return
N
;
38
}
39
43
void
move
(
const
Velocity
&
vel
,
const
float
offset_rad
= 0.0) {
44
const
float
theta_rad
= std::atan2(
vel
.y_milli,
vel
.x_milli);
45
const
float
run_power
= std::hypot(
vel
.x_milli,
vel
.y_milli);
46
std::array<float, N>
pwms
;
47
for
(
int
i
= 0;
i
<
N
; ++
i
) {
48
constexpr
auto
k
= 2 *
M_PI
/
N
;
49
const
auto
pwm
=
run_power
* std::cos(
i
*
k
+
theta_rad
+
offset_rad
) +
vel
.ang_rad;
50
pwms
[
i
] =
pwm
;
51
}
52
f_(std::move(
pwms
));
53
}
54
55
private
:
56
std::function<
void
(std::array<float, N>)> f_;
57
};
58
60
61
}
// namespace rct
62
63
#endif
// CHASSIS_OMNI_H_
CoordinateUnit.h
座標、速度を表す構造体 CoordinateUnit を提供する。
rct
robot control library
Definition
Chassis.h:16
rct::Omni
N輪オムニの制御を行うクラス。
Definition
Omni.h:25
rct::Omni::move
void move(const Velocity &vel, const float offset_rad=0.0)
モータへのPWM出力を計算する。その後callback関数にPWM出力を渡す。
Definition
Omni.h:43
rct::Omni::Omni
Omni(F &&f)
コンストラクタ。callback関数をセットする。
Definition
Omni.h:32
rct::Omni::size
static constexpr int size() noexcept
モータ数を返す。
Definition
Omni.h:36
src
Omni.h
Generated by
1.9.8