hardware/gantry_controller.h

Physical coordinate translation and G-code generation.

        22" physical rail travel

<—————————-&#8212;>

+-+ +——————&#8212;+ +-+

| |B| | | |W|| | |L| | 12” board | |H||

| |A| | | |I||

| |C| | 8x8 grid | |T||

| |K| | | |E||

| +-+ +——————&mdash;+ +-+|

| 3.0” .5” 12” .5” 3.0” | |<———- 19” occupied width ——-&mdash;>|

^ ^

| |

Black captures White captures

X = 1.5”, 3.0” X = 17.5”, 19.0”

Y = 4.420” to 14.920” Y = 4.420” to 14.920”

namespace Gantry

Enums

enum StartingSlot

Values:

enumerator SLOT_R1
enumerator SLOT_R2
enumerator SLOT_B1
enumerator SLOT_B2
enumerator SLOT_N1
enumerator SLOT_N2
enumerator SLOT_Q
enumerator SLOT_K
enumerator SLOT_P1
enumerator SLOT_P2
enumerator SLOT_P3
enumerator SLOT_P4
enumerator SLOT_P5
enumerator SLOT_P6
enumerator SLOT_P7
enumerator SLOT_P8

Variables

constexpr double RAIL_TRAVEL = 18.0
constexpr double BOARD_SIZE = 12.0
constexpr double SQUARE_SIZE = 1.5
constexpr double BOARD_MARGIN = 3.0
constexpr double A1_CENTER_X = 5.000
constexpr double A1_CENTER_Y = 4.420
constexpr double CAPTURE_VERTICAL_SPACING = 1.5
constexpr double CAPTURE_HORIZONTAL_SPACING = 1.5
constexpr double WHITE_CAPTURE_COL1_X = 17.500
constexpr double WHITE_CAPTURE_COL2_X = 19.000
constexpr double BLACK_CAPTURE_COL1_X = 3.000
constexpr double BLACK_CAPTURE_COL2_X = 1.500
constexpr double CAPTURE_START_Y = A1_CENTER_Y
constexpr double FEED_RATE = 1000.0
struct GcodeObserver
#include <gantry_controller.h>

Public Members

void *context = nullptr
void (*onCommand)(void *ctx, const char *cmd, bool dryRun) = nullptr
class GrblController
#include <gantry_controller.h>

Public Functions

GrblController()
~GrblController()
bool connect(const char *port, int baudRate = 115200)
void disconnect()
inline bool isConnected() const
void enableDryRun()

Enable dry-run mode: no serial port is required. Every G-code command that would be sent to GRBL is printed to stdout instead. The full planning and G-code generation pipeline runs normally so you can audit every command before powering the gantry.

Call this instead of connect() when you have no hardware attached.

inline bool isDryRun() const
bool sendCommand(const std::string &cmd)
bool sendCommands(const std::vector<std::string> &cmds)
bool home()
bool executeMove(const MovePlan &plan, bool capturedPieceIsWhite, int capturedSlot)
bool executeCapture(const BoardCoord &square, bool isWhitePiece, StartingSlot slot)
bool setupNewGame()
bool moveTo(const Position &pos)
bool moveTo(const BoardCoord &coord)
bool setMagnet(bool on)
inline Position getCurrentPosition() const
inline bool isMagnetEngaged() const
GrblCapabilities probeCapabilities()
bool writeSetting(int number, double value)
bool applyMotionProfile(const MotionProfile &profile)
inline void setMotionProfile(const MotionProfile &profile)
inline const MotionProfile &getMotionProfile() const
inline void setGcodeObserver(const GcodeObserver &observer)

Private Functions

int getCommandTimeoutMs(const std::string &cmd) const
bool send(const std::string &cmd)
bool waitForOk(int timeoutMs = 5000)
std::string readLine(int timeoutMs = 1000)
std::vector<std::string> readLines(int timeoutMs)
inline void notifyGcode(const std::string &cmd)

Private Members

int serialFd
bool connected
bool dryRunMode
Position currentPos
bool magnetEngaged
MotionProfile activeProfile
GcodeObserver gcodeObserver
bool hasGcodeObserver = false
struct Position
#include <gantry_controller.h>

Public Functions

inline Position()
inline Position(double px, double py)
inline bool operator==(const Position &other) const

Public Members

double x
double y