Chassis v2.1.1
Chassisはロボコンでの足回り制御を行うためのC++ライブラリである。
Loading...
Searching...
No Matches
Mecanum.h
Go to the documentation of this file.
1#ifndef CHASSIS_MECANUM_H_
2#define CHASSIS_MECANUM_H_
7#include <CoordinateUnit.h>
8
9#include <array>
10#include <cmath>
11#include <functional>
12#include <utility>
13
14namespace rct {
15
18
20struct Mecanum {
24 template<class F>
25 Mecanum(F&& f) : f_{std::forward<F>(f)} {}
26
29 static constexpr std::size_t size() noexcept {
30 return 4;
31 }
32
36 void move(const Velocity& vel, const float offset_rad = 0.0) {
37 const float theta_rad = std::atan2(vel.y_milli, vel.x_milli);
38 const float run_power = std::hypot(vel.x_milli, vel.y_milli);
39 const float pwmA = run_power * std::cos(M_PI / 4 + theta_rad + offset_rad) + vel.ang_rad;
40 const float pwmB = run_power * std::sin(M_PI / 4 + theta_rad + offset_rad) + vel.ang_rad;
41 f_({pwmA, pwmB, pwmA, pwmB});
42 }
43
44 private:
45 std::function<void(std::array<float, 4>)> f_;
46};
47
49
50} // namespace rct
51
52#endif // CHASSIS_MECANUM_H_
座標、速度を表す構造体 CoordinateUnit を提供する。
robot control library
Definition Chassis.h:16
メカナムの制御を行うクラス。
Definition Mecanum.h:20
static constexpr std::size_t size() noexcept
モータ数を返す。
Definition Mecanum.h:29
void move(const Velocity &vel, const float offset_rad=0.0)
モータへのPWM出力を計算する。その後callback関数にPWM出力を渡す。
Definition Mecanum.h:36
Mecanum(F &&f)
コンストラクタ。callback関数をセットする。
Definition Mecanum.h:25
N輪オムニの制御を行うクラス。
Definition Omni.h:25