Void Sentry
An AI-driven, real-time Sentry Turret platform leveraging asynchronous I/O and computer vision to deliver high-precision autonomous motion tracking on resource-constrained embedded hardware.
Loading...
Searching...
No Matches
turret.h
Go to the documentation of this file.
1
5#pragma once
6
7#include "base_turret.h"
8#include "step_planner.h"
9#include "sync.h"
10#include <ESP32Servo.h>
11#include <cstdint>
12#include <freertos/FreeRTOS.h>
13#include <freertos/task.h>
14
27class Turret : public BaseTurret
28{
29public:
31 explicit Turret(Servo& servo);
32
37 bool begin();
38
39 void set_target_deg(const aiming::Angles& target) override;
40 void jog(float pan, float tilt) override;
41 void home() override;
42 aiming::Angles position_deg() const override;
43 float pan_speed() const override;
44
46 uint32_t late_ticks() const;
47
52 uint32_t stack_free() const;
53
54private:
55 enum class CommandKind : uint8_t { None, Target, Jog, Home };
56
57 struct Command {
58 CommandKind kind = CommandKind::None;
59 aiming::Angles target{0.0f, 0.0f};
60 float jog_pan = 0.0f;
61 float jog_tilt = 0.0f;
62 uint32_t sequence = 0;
63 };
64
65 static void task_entry(void* arg);
66 void run();
67 void write_coils(int phase);
68 void release_coils();
69
70 Servo& _servo;
71 TaskHandle_t _task = nullptr;
73 struct Published {
74 aiming::Angles position{0.0f, 90.0f};
75 float speed = 0.0f;
76 uint32_t late_ticks = 0;
77 uint32_t stack_free = 0;
78 };
79
82
83 // Owned by the motor task only.
84 aiming::StepPlanner _planner;
85 int _phase = 0;
86 bool _coils_on = false;
87 uint32_t _last_step_ms = 0;
88 float _tilt_target = 90.0f;
89 float _tilt_current = 90.0f;
90 float _tilt_rate = 0.0f;
91 int _servo_written = 90;
92};
What the controller can ask of the pan/tilt turret. Thread-safe: called from loop(),...
Definition base_turret.h:11
Non-blocking turret: callers post commands, a 1 kHz motor task executes them.
Definition turret.h:28
aiming::Angles position_deg() const override
Current angles (pan from the step counter, tilt as last written to the servo).
Definition turret.cpp:105
Turret(Servo &servo)
Definition turret.cpp:40
void jog(float pan, float tilt) override
Manual velocity, each axis -1..1 of its max speed; 0,0 stops (with deceleration).
Definition turret.cpp:85
void set_target_deg(const aiming::Angles &target) override
Move to absolute angles (clamped to the soft limits).
Definition turret.cpp:76
bool begin()
Configure pins (coils LOW), attach the servo at home tilt and start the motor task.
Definition turret.cpp:48
float pan_speed() const override
Current stepper speed, steps/s (signed).
Definition turret.cpp:120
void home() override
Same as set_target_deg({0, home tilt}).
Definition turret.cpp:97
uint32_t stack_free() const
Minimum free stack of the motor task seen so far, in bytes (high-water mark, sampled every 1000 ticks...
Definition turret.cpp:115
uint32_t late_ticks() const
Count of late wake-ups (lag of more than 1 tick) where missed 1 ms ticks were dropped.
Definition turret.cpp:110
Definition step_planner.h:27
A value of type T that owns its own spinlock; every access is one short critical section.
Definition sync.h:54
Trapezoidal velocity planner for the pan stepper, ticked at 1 kHz (pure C++20, natively tested).
Turret pose: pan degrees from home (positive = right), tilt servo degrees (larger = up).
Definition aim_map.h:30
Small RAII wrappers for the two locking patterns the firmware uses (device only).