GKD.RoboCtrl
RoboMaster Linux 电控:异步 IO、设备驱动与机器人控制
载入中...
搜索中...
未找到
shoot.h
浏览该文件的文档.
1
5#pragma once
6#include "utils/ramp.hpp"
7#include "utils/singleton.hpp"
8#include "core/async.hpp"
9#include "core/logger.h"
10#include "device/motor/base.hpp"
11#include <chrono>
12#include <string>
13
14namespace roboctrl::ctrl{
15using namespace std::chrono_literals;
16
21class shoot : public utils::singleton_base<shoot>,public logable<shoot> {
22public:
23 shoot() = default;
25 struct info_type{
26 using owner_type = shoot;
27
28 utils::ramp_f::params_type friction_params;
29 float friction_max_speed {};
30 float trigger_speed {}; // Output shaft rad/s, matching legacy trigger PID feedback.
31 float friction_ready_speed {1.5f};
32 float jam_current {4000.0f};
33 float jam_speed {1.0f};
34 std::chrono::steady_clock::duration jam_release_time {50ms};
35 std::chrono::steady_clock::duration control_time {1ms};
36 std::string left_friction_motor {"left_friction"};
37 std::string right_friction_motor {"right_friction"};
38 std::string trigger_motor {"trigger"};
39 bool enforce_referee {false};
40 unsigned int bullet_caliber {17}; // 17 mm normally, 42 mm Hero.
41 };
42
43 inline std::string desc()const{return "shoot";}
44
47
49 bool init(const info_type& info);
50 bool init(const info_type& info, device::motor_base& left,
51 device::motor_base& right, device::motor_base& trigger);
52 void start();
56 void set_enabled(bool enabled);
57 void set_fire_permitted(bool permitted) { fire_permitted_ = permitted; }
58 [[nodiscard]] bool fire_allowed() const;
59
61 void set_firing(bool state);
62 inline bool firing()const{return firing_;}
64 void set_friction_enabled(bool state);
65 inline bool friction_enabled() const{return friction_enabled_;}
67 [[nodiscard]] bool friction_ready() const;
68
69private:
70 info_type info_;
71 utils::ramp_f friction_ramp_;
72
73 bool enabled_ {false};
74 bool fire_permitted_ {false};
75 bool initialized_ {false};
76 bool started_ {false};
77 bool firing_ {false};
78 bool friction_enabled_ {false};
79 std::chrono::steady_clock::time_point jam_release_at_ {};
80 device::motor_base* left_friction_motor_ {nullptr};
81 device::motor_base* right_friction_motor_ {nullptr};
82 device::motor_base* trigger_motor_ {nullptr};
83
84};
85
86static_assert(utils::singleton<shoot>);
87}
异步任务上下文组件。
开火控制
Definition shoot.h:21
bool friction_ready() const
判断摩擦轮是否达到可发射的准备速度。
Definition shoot.cpp:107
void set_firing(bool state)
请求开始或停止拨弹。
Definition shoot.cpp:96
roboctrl::awaitable< void > task()
周期更新摩擦轮和拨弹电机输出。
Definition shoot.cpp:157
bool init(const info_type &info)
绑定发射器所需电机并初始化内部状态。
Definition shoot.cpp:40
void set_friction_enabled(bool state)
请求启用或停止摩擦轮。
Definition shoot.cpp:101
void set_enabled(bool enabled)
Definition shoot.cpp:81
roboctrl::awaitable< void > update(fp32 dt)
Definition shoot.cpp:128
用于提供日志功能的辅助基类 通过CRTP模式实现,要求派生类实现desc()方法以提供描述信息,在继承时传入派生类自身类型作为模板参数。 继承这个类后,派生类可以方便地使用log_debug、log_i...
Definition logger.h:178
提供单例模式的单例基类
Definition singleton.hpp:19
电机基础组件。
用于日志输出的组件。
asio::awaitable< T > awaitable
协程任务类型。
Definition async.hpp:46
ramp< float > ramp_f
float 精度的 Ramp 控制器别名。
Definition ramp.hpp:128
发射器初始化参数。
Definition shoot.h:25
float fp32
单精度浮点别名。
Definition utils.hpp:22