PageRenderTime 32ms CodeModel.GetById 18ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/firmware/src/shared/StepperInterface.hh

http://github.com/makerbot/G3Firmware
C++ Header | 80 lines | 31 code | 15 blank | 34 comment | 0 complexity | a4821ba947c9bbed83fe4c933805bf36 MD5 | raw file
 1/*
 2 * Copyright 2010 by Adam Mayer	 <adam@makerbot.com>
 3 *
 4 * This program is free software: you can redistribute it and/or modify
 5 * it under the terms of the GNU General Public License as published by
 6 * the Free Software Foundation, either version 3 of the License, or
 7 * (at your option) any later version.
 8 *
 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program.  If not, see <http://www.gnu.org/licenses/>
16 */
17
18#ifndef STEPPERINTERFACE_HH_
19#define STEPPERINTERFACE_HH_
20
21#include <Pin.hh>
22
23/// The StepperInterface module represents a connection to a single stepper controller.
24/// \ingroup SoftwareLibraries
25class StepperInterface {
26private:
27    /// Default constructor
28    StepperInterface() {}
29    StepperInterface(const Pin& dir,
30                    const Pin& step,
31                    const Pin& enable,
32                    const Pin& max,
33                    const Pin& min,
34                    uint16_t eeprom_base_in);
35
36        friend class Motherboard;
37
38private:
39        /// Initialize the pins for the interface
40        /// \param[in] idx Stepper index that this interface refers to (used to look up
41        ///                it's settings in the EEPROM)
42        void init(uint8_t idx);
43
44
45
46        Pin dir_pin;                ///< Pin (output) that the direction line is connected to
47        Pin step_pin;               ///< Pin (output) that the step line is connected to
48        Pin enable_pin;             ///< Pin (output) that the enable line is connected to
49        Pin max_pin;                ///< Pin (input) that the maximum endstop is connected to.
50        Pin min_pin;                ///< Pin (input) that the minimum endstop is connected to.
51        bool invert_endstops;       ///< True if endstops input polarity is inverted for
52                                    ///< this axis.
53        bool invert_axis;           ///< True if motions for this axis should be inverted
54
55        uint16_t eeprom_base;       ///< Base address to read EEPROM configuration from
56
57public:
58	/// Set the direction for the stepper to move
59        /// \param[in] forward True to move the stepper forward, false otherwise.
60	void setDirection(bool forward);
61
62	/// Set the value of the step line
63        /// \param[in] value True to enable, false to disable. This should be toggled
64        ///                  back and fourth to effect stepping.
65	void step(bool value);
66
67        /// Enable or disable the stepper motor on this axis
68        /// \param[in] True to enable the motor
69	void setEnabled(bool enabled);
70
71        /// Check if the maximum endstop has been triggered for this axis.
72        /// \return True if the axis has triggered its maximum endstop
73	bool isAtMaximum();
74
75        /// Check if the minimum endstop has been triggered for this axis.
76        /// \return True if the axis has triggered its minimum endstop
77	bool isAtMinimum();
78};
79
80#endif // STEPPERINTERFACE_HH_