-
Notifications
You must be signed in to change notification settings - Fork 7
/
AStar32U4Motors.h
84 lines (71 loc) · 3.05 KB
/
AStar32U4Motors.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
84
// Copyright Pololu Corporation. For more information, see http://www.pololu.com/
/*! \file AStar32U4Motors.h */
#pragma once
#include <stdint.h>
/*! \brief Controls motor speed and direction on the A-Star 32U4 Robot
* Controller.
*
* By default, positive speed arguments ("forward") correspond to current
* flowing from motor driver output A to B, while negative speed arguments
* ("reverse") correspond to current flowing from B to A. Calling flipM1() or
* flipM2() with an argument of \c true flips the correspondence for that motor
* (that is, it flips the meaning of "forward" and "reverse").
*
* This library uses Timer 1, so it will conflict with any other libraries using
* that timer. */
class AStar32U4Motors
{
public:
/** \brief Flips the direction of motor 1.
*
* You can call this function with an argument of \c true if you want to
* flip the effect that positive and negative speeds have on the direction
* of motor 1.
*
* \param flip If true, then positive motor speeds will correspond to
* current flowing from B to A. If false, then positive motor speeds will
* correspond to current flowing from A to B. */
static void flipM1(bool flip);
/** \brief Flips the direction of motor 2.
*
* You can call this function with an argument of \c true if you want to
* flip the effect that positive and negative speeds have on the direction
* of motor 2.
*
* \param flip If true, then positive motor speeds will correspond to
* current flowing from B to A. If false, then positive motor speeds will
* correspond to current flowing from A to B. */
static void flipM2(bool flip);
/** \brief Sets the speed for motor 1.
*
* \param speed A number from -400 to 400 representing the speed and
* direction of motor 1. Values of -400 or less result in full speed
* reverse, and values of 400 or more result in full speed forward. */
static void setM1Speed(int16_t speed);
/** \brief Sets the speed for motor 2.
*
* \param speed A number from -400 to 400 representing the speed and
* direction of motor 2. Values of -400 or less result in full speed
* reverse, and values of 400 or more result in full speed forward. */
static void setM2Speed(int16_t speed);
/** \brief Sets the speed for both motors.
*
* \param m1Speed A number from -400 to 400 representing the speed and
* direction of motor 1. Values of -400 or less result in full speed
* reverse, and values of 400 or more result in full speed forward.
* \param m2Speed A number from -400 to 400 representing the speed and
* direction of motor 2. Values of -400 or less result in full speed
* reverse, and values of 400 or more result in full speed forward. */
static void setSpeeds(int16_t m1Speed, int16_t m2Speed);
private:
static inline void init()
{
static bool initialized = false;
if (!initialized)
{
initialized = true;
init2();
}
}
static void init2();
};