38 constexpr Pos() noexcept
45 constexpr Pos(
const Pos& rhs) noexcept
93 constexpr bool operator!=(
const Pos& rhs)
const noexcept {
return !(*
this == rhs); }
96 constexpr explicit operator bool() const noexcept
104 return !Pos::operator bool();
123 Pos mapped(
double inMin,
double inMax,
double outMin,
double outMax)
const noexcept
127 Map(
turn, inMin, inMax, outMin, outMax),
136 template <
typename Visitor>
147 template <
typename Visitor>
163 uint8_t powerLimit = 255;
164 uint8_t turnPowerLimit = 255;
165 const auto mappedTurn =
Udon::Map(
turn, -255, 255, -turnPowerLimit, turnPowerLimit);
167 std::array<double, 4> powers{ {
176 auto&& max =
Udon::Abs(*std::max_element(powers.begin(), powers.end(), [](
double lhs,
double rhs)
177 { return Udon::Abs(lhs) < Udon::Abs(rhs); }));
179 if (max > powerLimit)
181 const auto ratio = powerLimit / max;
183 std::transform(powers.begin(), powers.end(), powers.begin(),
184 [ratio](
double power)
185 { return power * ratio; });
203 template <
size_t WheelCount = 4>
204 std::array<Udon::Polar, WheelCount>
toSteer(uint8_t powerLimit = 255,
205 uint8_t turnPowerLimit = 255)
const
207 static_assert(WheelCount >= 3,
"WheelCount must be greater than or equal to 3.");
208 static_assert(WheelCount == 4,
"Not supported over 4 wheels now.");
211 const Udon::Vec2 turnVec = { 0,
Udon::Map(this->turn, -255, 255, -turnPowerLimit, turnPowerLimit) };
214 std::array<Udon::Vec2, WheelCount> vectors;
216 for (
size_t i = 0; i < WheelCount; ++i)
222 std::array<Udon::Polar, WheelCount> modules;
224 for (
size_t i = 0; i < WheelCount; ++i)
226 modules.at(i) = vectors.at(i).toPolar();
232 auto&& max = *std::max_element(modules.begin(), modules.end(), [](
const Udon::Polar& lhs,
const Udon::Polar& rhs)
233 { return lhs.r < rhs.r; });
235 if (max.r > powerLimit)
237 const auto ratio = powerLimit / max.r;
238 for (
auto&& module : modules)
252 Serial.print(
F(
"turn: ")), Serial.print(
turn), Serial.print(
'\t');
#define F(x)
Definition Show.hpp:17
constexpr T Abs(const T &rhs)
絶対値を返す (std::abs)
Definition Math.hpp:98
constexpr double Pi
π
Definition Math.hpp:26
constexpr double Map(const double value, const double inputMin, const double inputMax, const double outputMin, const double outputMax)
数値をある範囲から別の範囲に再マッピングする
Definition Math.hpp:136
極座標系
Definition Polar.hpp:21
ロボットの位置
Definition Position.hpp:26
constexpr Pos operator+(ValueType rhs) const noexcept
Definition Position.hpp:68
Pos modifyVector(Visitor &&visitor) const noexcept
Definition Position.hpp:137
constexpr Pos(const Pos &rhs) noexcept
デフォルトコピーコンストラクタ
Definition Position.hpp:45
Pos updateVector(const Udon::Vec2 &v) const noexcept
Definition Position.hpp:131
std::array< double, N > toOmni() const
Definition Position.hpp:161
Pos operator/=(ValueType rhs) noexcept
Definition Position.hpp:83
constexpr Pos operator/(const Pos &rhs) const noexcept
Definition Position.hpp:67
Pos operator-=(const Pos &rhs) noexcept
Definition Position.hpp:77
Pos mapped(double inMin, double inMax, double outMin, double outMax) const noexcept
Definition Position.hpp:123
constexpr Pos operator/(ValueType rhs) const noexcept
Definition Position.hpp:71
Pos operator/=(const Pos &rhs) noexcept
Definition Position.hpp:79
constexpr Pos operator-(const Pos &rhs) const noexcept
Definition Position.hpp:65
void clear() noexcept
値クリア
Definition Position.hpp:108
constexpr Pos operator+(const Pos &rhs) const noexcept
算術演算子
Definition Position.hpp:64
Pos abs()
絶対値を取る
Definition Position.hpp:115
double ValueType
要素の型
Definition Position.hpp:29
constexpr bool isZero() const noexcept
要素がすべて0であるかを変えす
Definition Position.hpp:102
Pos operator+=(ValueType rhs) noexcept
Definition Position.hpp:80
Pos updateTurn(double t) const noexcept
Definition Position.hpp:142
Pos operator-=(ValueType rhs) noexcept
Definition Position.hpp:81
Pos operator*=(ValueType rhs) noexcept
Definition Position.hpp:82
constexpr Pos operator*(ValueType rhs) const noexcept
Definition Position.hpp:70
UDON_ENUMERABLE(vector, turn)
constexpr Pos(const Udon::Vec2 &vector, ValueType turn) noexcept
コンストラクタ
Definition Position.hpp:52
Pos operator+=(const Pos &rhs) noexcept
複合代入演算子
Definition Position.hpp:76
Pos & operator=(const Pos &)=default
デフォルトコピー代入演算子
constexpr bool operator!=(const Pos &rhs) const noexcept
比較演算子
Definition Position.hpp:93
constexpr Pos operator-(ValueType rhs) const noexcept
Definition Position.hpp:69
ValueType turn
旋回角 [rad]
Definition Position.hpp:35
Udon::Vec2 vector
座標
Definition Position.hpp:32
Pos operator*=(const Pos &rhs) noexcept
Definition Position.hpp:78
Pos modifyTurn(Visitor &&visitor) const noexcept
Definition Position.hpp:148
std::array< Udon::Polar, WheelCount > toSteer(uint8_t powerLimit=255, uint8_t turnPowerLimit=255) const
独立ステアリング機構のタイヤ出力値、旋回角を取得する
Definition Position.hpp:204
constexpr Pos() noexcept
デフォルトコンストラクタ
Definition Position.hpp:38
constexpr Pos operator*(const Pos &rhs) const noexcept
Definition Position.hpp:66
constexpr bool operator==(const Pos &rhs) const noexcept
比較演算子
Definition Position.hpp:88
二次元ベクトル
Definition Vector2D.hpp:22
ValueType y
Y成分
Definition Vector2D.hpp:31
constexpr Vec2 mapped(ValueType fromMin, ValueType fromMax, ValueType toMin, ValueType toMax) const noexcept
各要素をある範囲から別の範囲に再マップしたベクトルを返す
Definition Vector2D.hpp:254
Vec2 rotated(ValueType angle) const noexcept
原点を中心に回転したベクトルを返す
Definition Vector2D.hpp:172
ValueType x
X成分
Definition Vector2D.hpp:28
Vec2 abs() const noexcept
絶対値を取る
Definition Vector2D.hpp:140