forked from muccc/formica_rev1_muc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
motor.h
72 lines (55 loc) · 1.99 KB
/
motor.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
/* Copyright 2008 Stephen English, Jeffrey Gough, Alexis Johnson,
Robert Spanton and Joanna A. Sun.
This file is part of the Formica robot firmware.
The Formica robot firmware 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.
The Formica robot firmware 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 the Formica robot firmware.
If not, see <http://www.gnu.org/licenses/>. */
#ifndef __MOTOR_H
#define __MOTOR_H
#include <stdint.h>
#define M1 (1<<0)
#define MP (1<<1)
#define M2 (1<<3)
#define MN (1<<4)
#define M_ALL (M1 | MP | M2 | MN)
/* Both motors forward */
#define M_FWD ( MP | MN )
/* Both motors backward */
#define M_BK ( M1 | M2 )
/* Left hand motor forward */
#define M_L_FWD ( MP | MN | M2 )
/* Left hand motor backward */
#define M_L_BK ( M1 )
/* Right hand motor forward */
#define M_R_FWD ( M1 | MP | MN )
/* Right hand motor backward */
#define M_R_BK ( M2 )
#define motor_off() do { P1DIR &= ~M_ALL; } while (0)
#define motor_fwd() do { P1DIR &= ~M_ALL; P1DIR |= M_FWD; } while (0)
#define motor_bk() do { P1DIR &= ~M_ALL; P1DIR |= M_BK; } while (0)
void motor_init( void );
typedef enum {
MOTOR_FWD,
MOTOR_BK,
MOTOR_TURN_LEFT,
MOTOR_TURN_RIGHT
} motor_mode_t;
extern motor_mode_t motor_mode;
/* The motor speeds */
extern uint8_t MAX_SPEED;
extern uint8_t motor_r;
extern uint8_t motor_l;
/* Change to another direction for the random walk */
void motor_rand_walk_change( void );
/* Enable/disable the random walk */
void random_walk_enable( void );
void random_walk_disable( void );
#endif /* __MOTOR_H */