UdonLibrary 1.0.0
機械システム研究部 C++ ライブラリ
読み取り中…
検索中…
一致する文字列を見つけられません
Motor.hpp
[詳解]
1//
2// 通信経由モーター制御クラス
3//
4// Copyright (c) 2022-2024 udonrobo
5//
6
7#pragma once
8
10#include <algorithm>
11
14#include <Udon/Utility/Show.hpp>
16
17namespace Udon
18{
19
21 template <template <typename> class Writer>
22 class MotorBy
23 {
24 static_assert(Traits::IsWriter<Writer>::value, "Writer is not writer");
25
26 using WriterType = Writer<Message::Motor>;
27 WriterType writer;
28
29 int16_t power; // 出力値 -255 ~ 255
30
31 bool direction; // 回転方向 true: forward, false: backward
32
33 public:
34
38 MotorBy(WriterType&& writer, bool direction)
39 : writer(std::move(writer))
40 , power()
41 , direction(direction)
42 {
43 }
44
47 void move(int16_t p)
48 {
49 power = Constrain(p, (int16_t)-255, (int16_t)255);
50 writer.setMessage({ static_cast<int16_t>(power * (direction ? 1 : -1)) });
52 }
53
55 void stop()
56 {
57 move(0);
58 }
59
61 void show() const
62 {
63 Udon::Show(power);
64 }
65 };
66
67} // namespace Udon
通信経由モーター制御クラス
Definition Motor.hpp:23
void show() const
出力値をシリアル出力
Definition Motor.hpp:61
MotorBy(WriterType &&writer, bool direction)
コンストラクタ
Definition Motor.hpp:38
void stop()
停止
Definition Motor.hpp:55
void move(int16_t p)
出力値を取得
Definition Motor.hpp:47
void MaybeInvokeUpdate(HasMemberFunctionUpdate &rhs)
T に T::update 関数が存在する場合呼び出す。それ以外の場合何もしない。
Definition HasMemberFunction.hpp:111
Definition Bit.hpp:12
void Show(Args &&... args)
区切り文字ありで出力する
Definition Show.hpp:339
constexpr A Constrain(const A &amt, const B &low, const C &high)
値を指定された範囲内に収める (std::clamp)
Definition Math.hpp:68
Definition Typedef.hpp:94
送信クラスであるか判定
Definition ReaderWriterTraits.hpp:25