-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathplanner.h
83 lines (71 loc) · 3.05 KB
/
planner.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
* (c) 2013, 2016 Henner Zeller <[email protected]>
*
* This file is part of BeagleG. http://github.com/hzeller/beagleg
*
* BeagleG is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* BeagleG is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with BeagleG. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _BEAGLEG_PLANNER_H_
#define _BEAGLEG_PLANNER_H_
#include "gcode-parser/gcode-parser.h" // AxesRegister
struct MachineControlConfig;
class HardwareMapping;
class SegmentQueue;
// The planner receives a sequence of desired target positions.
// It then plans acceleration and speed profile for the physical
// machine, and emits these to the SegmentQueue backend.
class Planner {
public:
// The planner writes out motor operations to the backend.
Planner(const MachineControlConfig *config, HardwareMapping *hardware_mapping,
SegmentQueue *motor_backend);
~Planner();
// Enqueue a new target position to go to in a linear movement from
// the current position.
// Returns true if successful, false if aborted
bool Enqueue(const AxesRegister &target_pos, float speed);
// Flush the queue and wait until all remaining motor
// operations have been flushed.
void BringPathToHalt();
// Get the latest position enqueued to the motors.
// TODO(Leonardo): get actual position of the motor at this moment.
void GetCurrentPosition(AxesRegister *pos);
// Drive an axis directly. Should only be used for cases such as
// homing which require direct motor driving.
//
// Precondition: path needs to be halted, so call BringPathToHalt() first.
// After one or a series of DirectDrive() calls, SetExternalPosition()
// must be called to inform the Planner what new absolute position we
// are in.
//
// Returns the number of steps the stepmotor for that axis did.
int DirectDrive(GCodeParserAxis axis, float distance, float v0, float v1);
// Set the current absolute position of the given axis from an
// machine move outside of the control of the Planner.
// Precondition: BringPathToHalt() had been called before.
void SetExternalPosition(GCodeParserAxis axis, float pos);
// Set the internal planner queue size.
// Used to trade-off between command sent - executed motion latency
// and maximum achievable speed.
// Requires 0 < size <= GetMaxLookahead(), returns true on success.
bool SetLookahead(int size);
// Retrieve the internal planning queue size.
int Lookahead() const;
// Get the maximum allowed lookahead size.
int GetMaxLookahead() const;
private:
class Impl;
Impl *const impl_;
};
#endif