Revision 1556
Cleaned up accidental commit of include folder and bin folder.
include/libdragonfly/time.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* @file time.h |
|
29 |
* @brief Contains time-related functions and definitions |
|
30 |
* |
|
31 |
* Contains functions and definitions for dealing with time, |
|
32 |
* namely delay_ms and the realtime clock. |
|
33 |
* |
|
34 |
* @author Colony Project, CMU Robotics Club |
|
35 |
**/ |
|
36 |
|
|
37 |
#ifndef _TIME_H_ |
|
38 |
#define _TIME_H_ |
|
39 |
|
|
40 |
/* Predefined times for prescale_opt in time.c. |
|
41 |
To make you own, know that a pulse is 1/16th of a second. You cannot get less than this. To get more, you need |
|
42 |
to know how many 16ths of a second are in the time you want. (Time_desired * 16 = prescaler_opt) |
|
43 |
*/ |
|
44 |
/** |
|
45 |
* @addtogroup time |
|
46 |
* @{ |
|
47 |
**/ |
|
48 |
/** @brief A sixteenth of a second **/ |
|
49 |
#define SIXTEENTH_SECOND 1 |
|
50 |
/** @brief An eighth of a second **/ |
|
51 |
#define EIGTH_SECOND 2 |
|
52 |
/** @brief A quarter of a second **/ |
|
53 |
#define QUARTER_SECOND 4 |
|
54 |
/** @brief Half of a second **/ |
|
55 |
#define HALF_SECOND 8 |
|
56 |
/** @brief One second **/ |
|
57 |
#define SECOND 16 |
|
58 |
/** @brief Two seconds **/ |
|
59 |
#define TWO_SECOND 32 |
|
60 |
/** @brief Four seconds **/ |
|
61 |
#define FOUR_SECOND 64 |
|
62 |
|
|
63 |
/** @brief Delay execution for the specified time **/ |
|
64 |
void delay_ms(int ms) ; |
|
65 |
/** @brief Enable the realtime clock **/ |
|
66 |
void rtc_init(int prescale_opt, void (*rtc_func)(void)); |
|
67 |
/** @brief Reset the counter of the realtime clock **/ |
|
68 |
void rtc_reset(void); |
|
69 |
/** @brief Get the value of the realtime clock. **/ |
|
70 |
int rtc_get(void); |
|
71 |
|
|
72 |
/** @} **/ |
|
73 |
|
|
74 |
#endif |
|
75 |
|
include/libdragonfly/motor.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* @file motor.h |
|
29 |
* @brief Contains definitions for controlling the motors |
|
30 |
* |
|
31 |
* Contains definitions and functions for controlling |
|
32 |
* the motors. |
|
33 |
* |
|
34 |
* @author Colony Project, CMU Robotics Club |
|
35 |
* Based on Tom Lauwer's Firefly Library |
|
36 |
**/ |
|
37 |
|
|
38 |
#ifndef _MOTOR_H |
|
39 |
#define _MOTOR_H |
|
40 |
|
|
41 |
#include <avr/io.h> |
|
42 |
/** |
|
43 |
* @addtogroup motors |
|
44 |
* @{ |
|
45 |
**/ |
|
46 |
|
|
47 |
/** @brief make the motors go forwards **/ |
|
48 |
#define FORWARD 1 |
|
49 |
/** @brief make the motors go backwards **/ |
|
50 |
#define BACKWARD 0 |
|
51 |
|
|
52 |
/** @brief Initialize the motors **/ |
|
53 |
void motors_init(void); |
|
54 |
/** @brief Set speed and direction of motor1 |
|
55 |
* @deprecated use the left motor function instead. it's more intuitive and easier to read.**/ |
|
56 |
void motor1_set(int direction, int speed); |
|
57 |
/** @brief Set speed and direction of motor2 |
|
58 |
* @deprecated use the right motor function instead. it's more intuitive and easier to read.**/ |
|
59 |
void motor2_set(int direction, int speed); |
|
60 |
/** @brief Set speed and direction of left motor **/ |
|
61 |
void motor_l_set(int direction, int speed); |
|
62 |
/** @brief Set speed and direction of right motor **/ |
|
63 |
void motor_r_set(int direction, int speed); |
|
64 |
/** @brief Turn the motors off **/ |
|
65 |
void motors_off(void); |
|
66 |
|
|
67 |
/**@}**/ // end addtogroup |
|
68 |
|
|
69 |
#endif |
|
70 |
|
include/libdragonfly/analog.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
25 |
|
|
26 |
/** |
|
27 |
* |
|
28 |
* @file analog.h |
|
29 |
* @brief Contains functions and definitions for using the ADC |
|
30 |
* |
|
31 |
* Contains definitions and function prototypes for using the |
|
32 |
* ADC to detect analog signals on pins AN0 - AN7. |
|
33 |
* AN6 and AN7 are used for the wheel and battery. |
|
34 |
|
|
35 |
* The pins labeled E6 and E7 are external interrupt pins and are not related |
|
36 |
* to analog. |
|
37 |
|
|
38 |
* @author Colony Project, CMU Robotics Club, based on firefly |
|
39 |
* originally taken from fwr analog file (author: Tom Lauwers) |
|
40 |
* loop code written by Kevin Woo and James Kong |
|
41 |
*/ |
|
42 |
|
|
43 |
#ifndef _ANALOG_H |
|
44 |
#define _ANALOG_H |
|
45 |
|
|
46 |
#include <inttypes.h> |
|
47 |
|
|
48 |
/** |
|
49 |
* @addtogroup analog |
|
50 |
* @{ |
|
51 |
**/ |
|
52 |
|
|
53 |
/** @brief Analog port 0 **/ |
|
54 |
#define AN0 0x00 |
|
55 |
/** @brief Analog port 1 **/ |
|
56 |
#define AN1 0x01 |
|
57 |
/** @brief Analog port 2 **/ |
|
58 |
#define AN2 0x02 |
|
59 |
/** @brief Analog port 3 **/ |
|
60 |
#define AN3 0x03 |
|
61 |
/** @brief Analog port 4 **/ |
|
62 |
#define AN4 0x04 |
|
63 |
/** @brief Analog port 5 **/ |
|
64 |
#define AN5 0x05 |
|
65 |
/** @brief Analog port 6 **/ |
|
66 |
#define AN6 0x06 |
|
67 |
/** @brief Analog port 7 **/ |
|
68 |
#define AN7 0x07 |
|
69 |
/** @brief Analog port 8 **/ |
|
70 |
#define AN8 0x08 |
|
71 |
/** @brief Analog port 9 **/ |
|
72 |
#define AN9 0x09 |
|
73 |
/** @brief Analog port 10 **/ |
|
74 |
#define AN10 0x0A |
|
75 |
/** @brief Analog port 11 **/ |
|
76 |
#define AN11 0x0B |
|
77 |
/** @brief Analog port 12 **/ |
|
78 |
#define AN12 0x0C |
|
79 |
/** @brief Analog port 13 **/ |
|
80 |
#define AN13 0x0D |
|
81 |
/** @brief Analog port 14 **/ |
|
82 |
#define AN14 0x0E |
|
83 |
/** @brief Analog port 15 **/ |
|
84 |
#define AN15 0x0F |
|
85 |
|
|
86 |
/** @brief BOM_PORT analog port for BOM **/ |
|
87 |
#define BOM_PORT AN0 |
|
88 |
/** @brief EXT_MUX analog port **/ |
|
89 |
#define EXT_MUX AN7 |
|
90 |
/** @brief Analog port for the wheel **/ |
|
91 |
#define WHEEL_PORT AN10 |
|
92 |
/** @brief Analog port for the battery voltage detector **/ |
|
93 |
#define BATT_PORT AN11 |
|
94 |
|
|
95 |
/** @brief Analog loop status. ADC conversion running. **/ |
|
96 |
#define ADC_LOOP_RUNNING 1 |
|
97 |
/** @brief Analog loop status. No ADC conversion running.**/ |
|
98 |
#define ADC_LOOP_STOPPED 0 |
|
99 |
|
|
100 |
/** @brief Analog init parameter. Start the analog loop. **/ |
|
101 |
#define ADC_START 1 |
|
102 |
/** @brief Analog init parameter. Don't start the analog loop. **/ |
|
103 |
#define ADC_STOP 0 |
|
104 |
|
|
105 |
#define ADMUX_OPT 0x60 |
|
106 |
|
|
107 |
/** @brief Struct to hold the value of a particular analog port **/ |
|
108 |
typedef struct { |
|
109 |
uint8_t adc8; |
|
110 |
uint16_t adc10; |
|
111 |
} adc_t; |
|
112 |
|
|
113 |
|
|
114 |
/** @brief Initialize analog ports. Will start running a loop |
|
115 |
if start_conversion is ADC_START.**/ |
|
116 |
void analog_init(int start_conversion); |
|
117 |
/** @brief starts the analog loop. Doesn't do anything if the loop is already running. **/ |
|
118 |
void analog_start_loop(void); |
|
119 |
/** @brief Stops the analog loop. Doesn't do anything if the loop is already stopped. **/ |
|
120 |
void analog_stop_loop(void); |
|
121 |
/** @brief Returns the status of the analog loop. **/ |
|
122 |
int analog_loop_status(void); |
|
123 |
/** @brief Returns an 8-bit analog value from the look up table. Use this instead of analog_get8. **/ |
|
124 |
unsigned int analog8(int which); |
|
125 |
/** @brief Returns an 10-bit analog value from the look up table. Use this instead of analog_get10. **/ |
|
126 |
unsigned int analog10(int which); |
|
127 |
/** @brief Read the position of the wheel. **/ |
|
128 |
int wheel(void); |
|
129 |
/** @brief Read an 8-bit number from an analog port. Loop must be stopped for this to work. **/ |
|
130 |
unsigned int analog_get8(int which); |
|
131 |
/** @brief Read a 10-bit number from an analog port. Loop must be stopped for this to work. **/ |
|
132 |
unsigned int analog_get10(int which); |
|
133 |
|
|
134 |
|
|
135 |
/**@}**/ //end group |
|
136 |
|
|
137 |
#endif |
|
138 |
|
include/libdragonfly/encoders.h | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
* @file encoders.h |
|
4 |
* @brief Contains functions for reading encoder values. |
|
5 |
* |
|
6 |
* Contains high and low level functions for reading encoders |
|
7 |
* including reading out total distance covered, and |
|
8 |
* eventually velocity. |
|
9 |
* |
|
10 |
* @author Colony Project, CMU Robotics Club |
|
11 |
*/ |
|
12 |
|
|
13 |
/** |
|
14 |
* @addtogroup encoders |
|
15 |
* @{ |
|
16 |
**/ |
|
17 |
|
|
18 |
#ifndef __ENCODERS_H__ |
|
19 |
#define __ENCODERS_H__ |
|
20 |
|
|
21 |
|
|
22 |
#ifndef LEFT |
|
23 |
/** @brief Left wheel **/ |
|
24 |
#define LEFT 0 |
|
25 |
#endif |
|
26 |
#ifndef RIGHT |
|
27 |
/** @brief Right wheel **/ |
|
28 |
#define RIGHT 1 |
|
29 |
#endif |
|
30 |
|
|
31 |
/** @brief Max value of valid encoder reading. **/ |
|
32 |
#define ENCODER_MAX 1024 |
|
33 |
|
|
34 |
/** @brief Magnet misaligned - likely distance from encoder problem. **/ |
|
35 |
#define ENCODER_MAGNET_FAILURE 1025 |
|
36 |
/** @brief Encoder misaligned - likely on XY plane. **/ |
|
37 |
#define ENCODER_MISALIGNED 1027 |
|
38 |
/** @brief Not enough time has passed - encoders not initialized in hardware. **/ |
|
39 |
#define ENCODER_DATA_NOT_READY 1026 |
|
40 |
|
|
41 |
/** @brief delay_ms argument after a full read is complete **/ |
|
42 |
#define ENCODER_DELAY 20 |
|
43 |
|
|
44 |
//Data invalid flags (hardware failure): |
|
45 |
#define OCF _BV(4) |
|
46 |
#define COF _BV(3) |
|
47 |
|
|
48 |
//Data invalid alarm (May be invalid): |
|
49 |
#define LIN _BV(2) |
|
50 |
|
|
51 |
#define MagINCn _BV(1) |
|
52 |
#define MagDECn _BV(0) |
|
53 |
|
|
54 |
/** @brief Buffer size **/ |
|
55 |
#define BUFFER_SIZE 46 |
|
56 |
|
|
57 |
#define ERR_VEL 1024 |
|
58 |
|
|
59 |
/** @brief Initialize encoders. **/ |
|
60 |
void encoders_init(void); |
|
61 |
/** @brief Read instantaneous encoder value. **/ |
|
62 |
int encoder_read(char encoder); |
|
63 |
|
|
64 |
/** @brief Get total distance traveled. |
|
65 |
* @note Simply calls encoder_get_dx. |
|
66 |
**/ |
|
67 |
int encoder_get_x(char encoder); |
|
68 |
|
|
69 |
/** @brief Get instantaneous velocity. **/ |
|
70 |
int encoder_get_v(char encoder); |
|
71 |
|
|
72 |
/** @brief Get total distance traveled. **/ |
|
73 |
int encoder_get_dx(char encoder); |
|
74 |
/** @brief Reset distance counter. **/ |
|
75 |
void encoder_rst_dx(char encoder); |
|
76 |
/** @brief Get time count: The number of encoder reads that have occurred. **/ |
|
77 |
int encoder_get_tc(void); |
|
78 |
/** @brief Reset the time count. **/ |
|
79 |
void encoder_rst_tc(void); |
|
80 |
|
|
81 |
/** @brief Waits for the next n encoder reading, then returns. **/ |
|
82 |
void encoder_wait( int nReadings ); |
|
83 |
|
|
84 |
/**@}**/ //end group |
|
85 |
|
|
86 |
#endif |
include/libdragonfly/lcd.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* @file lcd.h |
|
29 |
* @brief Contains definitions for dealing with the LCD screen. |
|
30 |
* |
|
31 |
* Contains definitions and functions for dealing with the |
|
32 |
* LCD screen. |
|
33 |
* |
|
34 |
* @author Colony Project, CMU Robotics Club |
|
35 |
**/ |
|
36 |
|
|
37 |
#ifndef _LCD_H_ |
|
38 |
#define _LCD_H_ |
|
39 |
|
|
40 |
/** |
|
41 |
* @addtogroup lcd |
|
42 |
* @{ |
|
43 |
**/ |
|
44 |
|
|
45 |
/** @brief Initialize the LCD screen **/ |
|
46 |
void lcd_init(void); |
|
47 |
/** @brief Clear the LCD screen **/ |
|
48 |
void lcd_clear_screen( void ); |
|
49 |
/** @brief Print a char to the LCD screen **/ |
|
50 |
void lcd_putc(char c); |
|
51 |
/** @brief Print a string to the LCD screen **/ |
|
52 |
void lcd_puts(char *s); |
|
53 |
/** @brief Print an int to the LCD screen **/ |
|
54 |
void lcd_puti(int value); |
|
55 |
/** @brief Set the current cursor position **/ |
|
56 |
void lcd_gotoxy(int x, int y); |
|
57 |
|
|
58 |
/** @} **/ |
|
59 |
|
|
60 |
#endif |
|
61 |
|
include/libdragonfly/odometry.h | ||
---|---|---|
1 |
|
|
2 |
/** |
|
3 |
* @file odometry.h |
|
4 |
* @brief Code for estimating the robots pose. |
|
5 |
* |
|
6 |
* Offers simple position and orientation information. |
|
7 |
* |
|
8 |
* @author Colony Project, CMU Robotics Club |
|
9 |
**/ |
|
10 |
|
|
11 |
#ifndef __ODOMETRY_C__ |
|
12 |
#define __ODOMETRY_C__ |
|
13 |
|
|
14 |
/** |
|
15 |
* @addtogroup odometry |
|
16 |
* @{ |
|
17 |
**/ |
|
18 |
|
|
19 |
//Odometry resolution, *64 microseconds. |
|
20 |
#define ODOMETRY_CLK 255u |
|
21 |
#define TIME_SCALE 64 |
|
22 |
|
|
23 |
//Wheel = 2.613 in. |
|
24 |
//Circumference = 208.508133 mm |
|
25 |
//Distance per encoder click (circumference / 1024) = 203.621224 um. |
|
26 |
//Robot width = 5.3745 in. = 136.5123 mm |
|
27 |
|
|
28 |
#define ROBOT_WIDTH_UM 137000 //um |
|
29 |
#define CLICK_DISTANCE_UM 204 //um |
|
30 |
|
|
31 |
#define DISTANCE_SCALE 2.10526316 //Magic constant. |
|
32 |
#define ANGLE_SCALE 1.12823207 //Magic constant. |
|
33 |
|
|
34 |
/** @brief Retrieve the robots estimated x position*/ |
|
35 |
long odometry_dx(void); |
|
36 |
|
|
37 |
/** @brief Retrieve the robots estimated y position*/ |
|
38 |
long odometry_dy(void); |
|
39 |
|
|
40 |
/** @brief Retrieve the robots estimated orientation*/ |
|
41 |
double odometry_angle(void); |
|
42 |
|
|
43 |
/** @brief Initialize odometry. MUST be called before |
|
44 |
* the other functions work.**/ |
|
45 |
void odometry_init(void); |
|
46 |
|
|
47 |
/** @brief Reset position and orientation to the origin facing |
|
48 |
* the x axis.*/ |
|
49 |
void odometry_reset(void); |
|
50 |
|
|
51 |
/** @brief Report estimated velocity [mm/s].*/ |
|
52 |
long odometry_velocity(void); |
|
53 |
|
|
54 |
/**@}**/ //end group |
|
55 |
|
|
56 |
#endif |
include/libdragonfly/move.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* @file move.h |
|
29 |
* @brief Contains definitions for controlling robot motion |
|
30 |
* |
|
31 |
* This file offers higher-level functions for robot motion. |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
**/ |
|
35 |
|
|
36 |
#ifndef _MOVE_H_ |
|
37 |
#define _MOVE_H_ |
|
38 |
|
|
39 |
/** |
|
40 |
* @addtogroup move |
|
41 |
* @{ |
|
42 |
**/ |
|
43 |
|
|
44 |
/** @brief Move forwards **/ |
|
45 |
#define FWD 0 |
|
46 |
/** @brief Move backwards **/ |
|
47 |
#define BCK 1 |
|
48 |
|
|
49 |
/** @brief A slow speed **/ |
|
50 |
#define SLOW_SPD 96 |
|
51 |
/** @brief Half of the full speed **/ |
|
52 |
#define HALF_SPD 128 |
|
53 |
/** @brief A normal speed **/ |
|
54 |
#define NRML_SPD 160 |
|
55 |
/** @brief A fast speed **/ |
|
56 |
#define FAST_SPD 192 |
|
57 |
/** @brief The maximum speed **/ |
|
58 |
#define FULL_SPD 255 |
|
59 |
|
|
60 |
/** @brief A slow turning speed **/ |
|
61 |
#define SLOW_TURN 64 |
|
62 |
/** @brief A medium turning speed **/ |
|
63 |
#define NRML_TURN 96 |
|
64 |
/** @brief A high turning speed **/ |
|
65 |
#define FAST_TURN 128 |
|
66 |
|
|
67 |
/** @brief Move the robot at the specified velocity **/ |
|
68 |
void move(int velocity, int omega); |
|
69 |
/** @brief Move the robot while avoiding obstacles **/ |
|
70 |
void move_avoid(int velocity, int omega, int strength); |
|
71 |
|
|
72 |
/** @} **/ |
|
73 |
|
|
74 |
#endif |
|
75 |
|
include/libdragonfly/battery.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* @file battery.h |
|
29 |
* @brief Definitions for checking battery voltage. |
|
30 |
* |
|
31 |
* Contains definitions for checking the voltage of the |
|
32 |
* battery. |
|
33 |
* |
|
34 |
* @author Colony Project, CMU Robotics Club |
|
35 |
**/ |
|
36 |
|
|
37 |
#ifndef _BATTERY_H_ |
|
38 |
#define _BATTERY_H_ |
|
39 |
|
|
40 |
/** |
|
41 |
* @addtogroup battery |
|
42 |
* @{ |
|
43 |
**/ |
|
44 |
|
|
45 |
/** @brief Normal battery voltage. (6 V) **/ |
|
46 |
#define BATTERY_NORMALV 154 |
|
47 |
/** @brief Charging battery voltage. (7 V) **/ |
|
48 |
#define BATTERY_CHARINGV 179 |
|
49 |
/** @brief Low battery voltage. ( < 6 V) **/ |
|
50 |
#define BATTERY_LOWV 152 |
|
51 |
|
|
52 |
/** @brief Read the battery voltage. **/ |
|
53 |
int battery8(void); |
|
54 |
/** @brief Read the battery voltage in deciVolts. **/ |
|
55 |
int battery(void); |
|
56 |
/** @brief Check if the battery is low. **/ |
|
57 |
char battery_low(void); |
|
58 |
/** @brief Get an average battery voltage reading. **/ |
|
59 |
int battery8_avg(int n_samples); |
|
60 |
|
|
61 |
/** @} **/ //end addtogroup |
|
62 |
|
|
63 |
#endif |
|
64 |
|
include/libdragonfly/dio.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* @file dio.h |
|
29 |
* @brief Definitions for digital input / output |
|
30 |
* |
|
31 |
* This file contains definitions and functions for dealing |
|
32 |
* with digital input and output. |
|
33 |
* |
|
34 |
* @author Colony Project, CMU Robotics Club |
|
35 |
* Based on Tom Lauwer's Firefly Library |
|
36 |
**/ |
|
37 |
|
|
38 |
#ifndef _DIO_H |
|
39 |
#define _DIO_H |
|
40 |
|
|
41 |
/* |
|
42 |
these are ALL the pins |
|
43 |
don't use unless you know what you're doing |
|
44 |
*/ |
|
45 |
|
|
46 |
/* |
|
47 |
DIO pins on new dragonfly boards are shown below: |
|
48 |
----------------------------------------------- |
|
49 |
| _PIN_E6 | _PIN_E7 | _PIN_D2 | _PIN_D3 | VCC | |
|
50 |
----------------------------------------------- |
|
51 |
| _PIN_E2 | _PIN_E3 | _PIN_E4 | _PIN_E5 | GND | |
|
52 |
----------------------------------------------- |
|
53 |
*/ |
|
54 |
|
|
55 |
/** @brief Port A **/ |
|
56 |
#define _PORT_A 1 |
|
57 |
/** @brief Port B **/ |
|
58 |
#define _PORT_B 2 |
|
59 |
/** @brief Port C **/ |
|
60 |
#define _PORT_C 3 |
|
61 |
/** @brief Port D **/ |
|
62 |
#define _PORT_D 4 |
|
63 |
/** @brief Port E **/ |
|
64 |
#define _PORT_E 5 |
|
65 |
/** @brief Port F **/ |
|
66 |
#define _PORT_F 6 |
|
67 |
/** @brief Port G **/ |
|
68 |
#define _PORT_G 7 |
|
69 |
|
|
70 |
/** @brief Pin A0 **/ |
|
71 |
#define _PIN_A0 8 |
|
72 |
/** @brief Pin A1 **/ |
|
73 |
#define _PIN_A1 9 |
|
74 |
/** @brief Pin A2 **/ |
|
75 |
#define _PIN_A2 10 |
|
76 |
/** @brief Pin A3 **/ |
|
77 |
#define _PIN_A3 11 |
|
78 |
/** @brief Pin A4 **/ |
|
79 |
#define _PIN_A4 12 |
|
80 |
/** @brief Pin A5 **/ |
|
81 |
#define _PIN_A5 13 |
|
82 |
/** @brief Pin A6 **/ |
|
83 |
#define _PIN_A6 14 |
|
84 |
/** @brief Pin A7 **/ |
|
85 |
#define _PIN_A7 15 |
|
86 |
|
|
87 |
/** @brief Pin B0 **/ |
|
88 |
#define _PIN_B0 16 |
|
89 |
/** @brief Pin B1 **/ |
|
90 |
#define _PIN_B1 17 |
|
91 |
/** @brief Pin B2 **/ |
|
92 |
#define _PIN_B2 18 |
|
93 |
/** @brief Pin B3 **/ |
|
94 |
#define _PIN_B3 19 |
|
95 |
/** @brief Pin B4 **/ |
|
96 |
#define _PIN_B4 20 |
|
97 |
/** @brief Pin B5 **/ |
|
98 |
#define _PIN_B5 21 |
|
99 |
/** @brief Pin B6 **/ |
|
100 |
#define _PIN_B6 22 |
|
101 |
/** @brief Pin B7 **/ |
|
102 |
#define _PIN_B7 23 |
|
103 |
|
|
104 |
/** @brief Pin C0 **/ |
|
105 |
#define _PIN_C0 24 |
|
106 |
/** @brief Pin C1 **/ |
|
107 |
#define _PIN_C1 25 |
|
108 |
/** @brief Pin C2 **/ |
|
109 |
#define _PIN_C2 26 |
|
110 |
/** @brief Pin C3 **/ |
|
111 |
#define _PIN_C3 27 |
|
112 |
/** @brief Pin C4 **/ |
|
113 |
#define _PIN_C4 28 |
|
114 |
/** @brief Pin C5 **/ |
|
115 |
#define _PIN_C5 29 |
|
116 |
/** @brief Pin C6 **/ |
|
117 |
#define _PIN_C6 30 |
|
118 |
/** @brief Pin C7 **/ |
|
119 |
#define _PIN_C7 31 |
|
120 |
|
|
121 |
/** @brief Pin D0 **/ |
|
122 |
#define _PIN_D0 32 // pin DIO6 on new dragonfly boards |
|
123 |
/** @brief Pin D1 **/ |
|
124 |
#define _PIN_D1 33 // pin DIO7 |
|
125 |
/** @brief Pin D2 **/ |
|
126 |
#define _PIN_D2 34 |
|
127 |
/** @brief Pin D3 **/ |
|
128 |
#define _PIN_D3 35 |
|
129 |
/** @brief Pin D4 **/ |
|
130 |
#define _PIN_D4 36 |
|
131 |
/** @brief Pin D5 **/ |
|
132 |
#define _PIN_D5 37 |
|
133 |
/** @brief Pin D6 **/ |
|
134 |
#define _PIN_D6 38 |
|
135 |
/** @brief Pin D7 **/ |
|
136 |
#define _PIN_D7 39 |
|
137 |
|
|
138 |
/** @brief Pin E0 **/ |
|
139 |
#define _PIN_E0 40 |
|
140 |
/** @brief Pin E1 **/ |
|
141 |
#define _PIN_E1 41 |
|
142 |
/** @brief Pin E2 **/ |
|
143 |
#define _PIN_E2 42 // pin DIO0 |
|
144 |
/** @brief Pin E3 **/ |
|
145 |
#define _PIN_E3 43 // pin DIO1 |
|
146 |
/** @brief Pin E4 **/ |
|
147 |
#define _PIN_E4 44 // pin DIO2 |
|
148 |
/** @brief Pin E5 **/ |
|
149 |
#define _PIN_E5 45 // pin DIO3 |
|
150 |
/** @brief Pin E6 **/ |
|
151 |
#define _PIN_E6 46 // pin DIO4 |
|
152 |
/** @brief Pin E7 **/ |
|
153 |
#define _PIN_E7 47 // pin DIO5 |
|
154 |
|
|
155 |
/** @brief Pin F0 **/ |
|
156 |
#define _PIN_F0 48 |
|
157 |
/** @brief Pin F1 **/ |
|
158 |
#define _PIN_F1 49 |
|
159 |
/** @brief Pin F2 **/ |
|
160 |
#define _PIN_F2 50 |
|
161 |
/** @brief Pin F3 **/ |
|
162 |
#define _PIN_F3 51 |
|
163 |
/** @brief Pin F4 **/ |
|
164 |
#define _PIN_F4 52 |
|
165 |
/** @brief Pin F5 **/ |
|
166 |
#define _PIN_F5 53 |
|
167 |
/** @brief Pin F6 **/ |
|
168 |
#define _PIN_F6 54 |
|
169 |
/** @brief Pin F7 **/ |
|
170 |
#define _PIN_F7 55 |
|
171 |
|
|
172 |
/** @brief Pin G0 **/ |
|
173 |
#define _PIN_G0 56 |
|
174 |
/** @brief Pin WR **/ |
|
175 |
#define _PIN_WR 56 |
|
176 |
/** @brief Pin G1 **/ |
|
177 |
#define _PIN_G1 57 |
|
178 |
/** @brief Pin RD **/ |
|
179 |
#define _PIN_RD 57 |
|
180 |
/** @brief Pin G2 **/ |
|
181 |
#define _PIN_G2 58 |
|
182 |
/** @brief Pin ALE **/ |
|
183 |
#define _PIN_ALE 58 |
|
184 |
/** @brief Pin G3 **/ |
|
185 |
#define _PIN_G3 59 |
|
186 |
/** @brief Pin TOSC2 **/ |
|
187 |
#define _PIN_TOSC2 59 |
|
188 |
/** @brief Pin G4 **/ |
|
189 |
#define _PIN_G4 60 |
|
190 |
/** @brief Pin TOSC1 **/ |
|
191 |
#define _PIN_TOSC1 60 |
|
192 |
//#define _PIN_G5 61 |
|
193 |
//#define _PIN_G6 62 |
|
194 |
//#define _PIN_G7 63 |
|
195 |
|
|
196 |
/* |
|
197 |
These are the header pins (the ones you can connect things to) |
|
198 |
Feel free to use these |
|
199 |
*/ |
|
200 |
|
|
201 |
/** |
|
202 |
* @addtogroup dio |
|
203 |
* @{ |
|
204 |
**/ |
|
205 |
/** @brief Pin A0 **/ |
|
206 |
#define PIN_A0 8 |
|
207 |
/** @brief Pin A1 **/ |
|
208 |
#define PIN_A1 9 |
|
209 |
/** @brief Pin A2 **/ |
|
210 |
#define PIN_A2 10 |
|
211 |
/** @brief Pin A3 **/ |
|
212 |
#define PIN_A3 11 |
|
213 |
/** @brief Pin A4 **/ |
|
214 |
#define PIN_A4 12 |
|
215 |
/** @brief Pin A5 **/ |
|
216 |
#define PIN_A5 13 |
|
217 |
/** @brief Pin A6 **/ |
|
218 |
#define PIN_A6 14 |
|
219 |
/** @brief Pin A7 **/ |
|
220 |
#define PIN_A7 15 |
|
221 |
|
|
222 |
/** @brief Pin SS **/ |
|
223 |
#define PIN_SS 16 |
|
224 |
/** @brief Pin SCK **/ |
|
225 |
#define PIN_SCK 17 |
|
226 |
/** @brief Pin MOSI **/ |
|
227 |
#define PIN_MOSI 18 |
|
228 |
/** @brief Pin MISO **/ |
|
229 |
#define PIN_MISO 19 |
|
230 |
/** @brief LCD Command Pin **/ |
|
231 |
#define PIN_LCD_COMMAND 20 |
|
232 |
|
|
233 |
/** @brief Pin C0 **/ |
|
234 |
#define PIN_C0 24 |
|
235 |
/** @brief Pin C1 **/ |
|
236 |
#define PIN_C1 25 |
|
237 |
/** @brief Pin C2 **/ |
|
238 |
#define PIN_C2 26 |
|
239 |
/** @brief Pin C3 **/ |
|
240 |
#define PIN_C3 27 |
|
241 |
/** @brief Pin C4 **/ |
|
242 |
#define PIN_C4 28 |
|
243 |
/** @brief Pin C5 **/ |
|
244 |
#define PIN_C5 29 |
|
245 |
/** @brief Pin C6 **/ |
|
246 |
#define PIN_C6 30 |
|
247 |
/** @brief Pin C7 **/ |
|
248 |
#define PIN_C7 31 |
|
249 |
|
|
250 |
/** @brief Pin SCL **/ |
|
251 |
#define PIN_SCL 32 |
|
252 |
/** @brief Pin SDA **/ |
|
253 |
#define PIN_SDA 33 |
|
254 |
|
|
255 |
/** @brief Pin RX0 **/ |
|
256 |
#define PIN_RX0 40 |
|
257 |
/** @brief Pin TX0 **/ |
|
258 |
#define PIN_TX0 41 |
|
259 |
/** @brief LCD Reset Pin **/ |
|
260 |
#define PIN_LCD_RESET 42 |
|
261 |
/** @brief Pin E6 **/ |
|
262 |
#define PIN_E6 46 |
|
263 |
/** @brief Pin EXT_DIO1 **/ |
|
264 |
#define PIN_EXT_DIO1 46 |
|
265 |
/** @brief Pin E7 **/ |
|
266 |
#define PIN_E7 47 |
|
267 |
/** @brief Pin EXT_DIO2 **/ |
|
268 |
#define PIN_EXT_DIO2 48 |
|
269 |
|
|
270 |
/** @brief Pin AN0 **/ |
|
271 |
#define PIN_AN0 48 |
|
272 |
/** @brief Pin ADC0 **/ |
|
273 |
#define PIN_ADC0 48 |
|
274 |
/** @brief Pin AN1 **/ |
|
275 |
#define PIN_AN1 49 |
|
276 |
/** @brief Pin ADC1 **/ |
|
277 |
#define PIN_ADC1 49 |
|
278 |
/** @brief Pin AN2 **/ |
|
279 |
#define PIN_AN2 50 |
|
280 |
/** @brief Pin ADC2 **/ |
|
281 |
#define PIN_ADC2 50 |
|
282 |
/** @brief Pin AN3 **/ |
|
283 |
#define PIN_AN3 51 |
|
284 |
/** @brief Pin ADC3 **/ |
|
285 |
#define PIN_ADC3 51 |
|
286 |
/** @brief Pin AN4 **/ |
|
287 |
#define PIN_AN4 52 |
|
288 |
/** @brief Pin ADC4 **/ |
|
289 |
#define PIN_ADC4 52 |
|
290 |
/** @brief Pin AN5 **/ |
|
291 |
#define PIN_AN5 53 |
|
292 |
/** @brief Pin ADC5 **/ |
|
293 |
#define PIN_ADC5 53 |
|
294 |
/** @brief Pin AN6 **/ |
|
295 |
#define PIN_AN6 54 |
|
296 |
/** @brief Pin ADC6 **/ |
|
297 |
#define PIN_ADC6 54 |
|
298 |
/** @brief Pin AN7 **/ |
|
299 |
#define PIN_AN7 55 |
|
300 |
/** @brief Pin ADC7 **/ |
|
301 |
#define PIN_ADC7 55 |
|
302 |
|
|
303 |
/** @brief Wheel Pin **/ |
|
304 |
#define PIN_WHEEL 54 |
|
305 |
/** @brief Battery Voltage Monitor Pin **/ |
|
306 |
#define PIN_BATT 55 |
|
307 |
|
|
308 |
/** @brief button1 Pin **/ |
|
309 |
#define PIN_BTN1 56 |
|
310 |
/** @brief button2 Pin **/ |
|
311 |
#define PIN_BTN2 57 |
|
312 |
|
|
313 |
/** @brief LED1 Pin **/ |
|
314 |
#define PIN_LED1 58 |
|
315 |
|
|
316 |
/* Buttons */ |
|
317 |
/** @brief Button Pin **/ |
|
318 |
#define PIN_BTN PING |
|
319 |
/** @brief button2 Pin **/ |
|
320 |
#define BTN2 PING1 |
|
321 |
/** @brief button1 Pin **/ |
|
322 |
#define BTN1 PING0 |
|
323 |
|
|
324 |
/** @brief Read a portpin. **/ |
|
325 |
int digital_input(int); |
|
326 |
/** @brief Output to a portpin. **/ |
|
327 |
void digital_output(int bit, int val); |
|
328 |
/** @brief Pullup a portpin. **/ |
|
329 |
void digital_pull_up(int); |
|
330 |
|
|
331 |
/** @brief Check if button1 is pressed. **/ |
|
332 |
int button1_read( void ); |
|
333 |
/** @brief Check if button1 is clicked. **/ |
|
334 |
int button1_click( void ); |
|
335 |
/** @brief Wait until button1 is pressed. **/ |
|
336 |
void button1_wait( void ); |
|
337 |
|
|
338 |
/** @brief Check if button2 is pressed. **/ |
|
339 |
int button2_read( void ); |
|
340 |
/** @brief Check if button2 is clicked. **/ |
|
341 |
int button2_click( void ); |
|
342 |
/** @brief Wait until button2 is pressed. **/ |
|
343 |
void button2_wait( void ); |
|
344 |
|
|
345 |
/** @} **/ // end addtogroup |
|
346 |
|
|
347 |
#endif |
|
348 |
|
include/libdragonfly/dragonfly_lib.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
25 |
|
|
26 |
|
|
27 |
/** |
|
28 |
* @file dragonfly_lib.h |
|
29 |
* @brief Contains other include files |
|
30 |
* |
|
31 |
* Include this file for all the functionality of libdragonfly. |
|
32 |
* |
|
33 |
* @author Colony Project, CMU Robotics Club |
|
34 |
**/ |
|
35 |
|
|
36 |
#ifndef _DRAGONFLY_LIB_H_ |
|
37 |
#define _DRAGONFLY_LIB_H_ |
|
38 |
|
|
39 |
/** |
|
40 |
* @addtogroup dragonfly |
|
41 |
* @{ |
|
42 |
**/ |
|
43 |
|
|
44 |
// Configuration definitions |
|
45 |
/** @brief Initialize analog **/ |
|
46 |
#define ANALOG 0x01 |
|
47 |
/** @brief Initialize serial communications **/ |
|
48 |
#define SERIAL 0x02 |
|
49 |
/** @brief Initialize USB communications **/ |
|
50 |
#define USB 0x02 |
|
51 |
/** @brief Initialize communications **/ |
|
52 |
#define COMM 0x02 |
|
53 |
/** @brief Initialize the orb **/ |
|
54 |
#define ORB 0x04 |
|
55 |
/** @brief Initialize the motors **/ |
|
56 |
#define MOTORS 0x08 |
|
57 |
/** @brief Initialize I2C **/ |
|
58 |
#define I2C 0x20 |
|
59 |
/** @brief Initialize the buzzer **/ |
|
60 |
#define BUZZER 0x40 |
|
61 |
/** @brief Initialize the LCD screen **/ |
|
62 |
#define LCD 0x80 |
|
63 |
/** @brief Initialize the rangefinders **/ |
|
64 |
#define RANGE 0x0100 |
|
65 |
/** @brief Initialize the BOM **/ |
|
66 |
#define BOM 0x0200 |
|
67 |
/** @brief Initialize everything **/ |
|
68 |
#define ALL_ON 0x03FF |
|
69 |
|
|
70 |
/** @brief Initialize the board **/ |
|
71 |
void dragonfly_init(int config); |
|
72 |
|
|
73 |
/** @} **/ //end addtogroup |
|
74 |
|
|
75 |
#include <inttypes.h> |
|
76 |
#include <stdio.h> |
|
77 |
#include <stdlib.h> |
|
78 |
#include <avr/io.h> |
|
79 |
#include <avr/interrupt.h> |
|
80 |
#include <util/delay.h> |
|
81 |
#include <util/twi.h> |
|
82 |
|
|
83 |
// This file is included from the libdragonfly directory because it seems to be |
|
84 |
// missing from the AVR libc distribution. |
|
85 |
#include "atomic.h" |
|
86 |
|
|
87 |
#include <analog.h> |
|
88 |
#include <dio.h> |
|
89 |
#include <time.h> |
|
90 |
#include <lcd.h> |
|
91 |
#include <lights.h> |
|
92 |
#include <motor.h> |
|
93 |
#include <serial.h> |
|
94 |
#include <buzzer.h> |
|
95 |
#include <rangefinder.h> |
|
96 |
#include <bom.h> |
|
97 |
#include <move.h> |
|
98 |
#include <reset.h> |
|
99 |
#include <math.h> |
|
100 |
#include <eeprom.h> |
|
101 |
#include <stdbool.h> |
|
102 |
|
|
103 |
/** @brief shortcut for ATOMIC_BLOCK(ATOMIC_RESTORESTATE) **/ |
|
104 |
#define SYNC ATOMIC_BLOCK(ATOMIC_RESTORESTATE) |
|
105 |
|
|
106 |
/** @brief atomically grab a lock if it is free, return otherwise **/ |
|
107 |
#define REQUIRE_LOCK_OR_RETURN(LOCK) do { SYNC { if (LOCK) return; LOCK=1; } } while (0) |
|
108 |
|
|
109 |
/** @brief atomically release a lock **/ |
|
110 |
#define RELEASE_LOCK(LOCK) do { LOCK=0; } while (0) |
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
#endif |
|
115 |
|
include/libdragonfly/atomic.h | ||
---|---|---|
1 |
/* This file is in the dragonfly library directory because it seems to be |
|
2 |
missing from the AVR libc distribution */ |
|
3 |
|
|
4 |
/* Copyright (c) 2007 Dean Camera |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without |
|
8 |
modification, are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright |
|
11 |
notice, this list of conditions and the following disclaimer. |
|
12 |
|
|
13 |
* Redistributions in binary form must reproduce the above copyright |
|
14 |
notice, this list of conditions and the following disclaimer in |
|
15 |
the documentation and/or other materials provided with the |
|
16 |
distribution. |
|
17 |
|
|
18 |
* Neither the name of the copyright holders nor the names of |
|
19 |
contributors may be used to endorse or promote products derived |
|
20 |
from this software without specific prior written permission. |
|
21 |
|
|
22 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
23 |
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
24 |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
25 |
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
|
26 |
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
27 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
28 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
29 |
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
30 |
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
31 |
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
32 |
POSSIBILITY OF SUCH DAMAGE. |
|
33 |
*/ |
|
34 |
|
|
35 |
/* $Id: atomic.h,v 1.3 2007/12/20 14:17:56 joerg_wunsch Exp $ */ |
|
36 |
|
|
37 |
#ifndef _UTIL_ATOMIC_H_ |
|
38 |
#define _UTIL_ATOMIC_H_ 1 |
|
39 |
|
|
40 |
#include <avr/io.h> |
|
41 |
#include <avr/interrupt.h> |
|
42 |
|
|
43 |
#if !defined(__DOXYGEN__) |
|
44 |
/* Internal helper functions. */ |
|
45 |
static __inline__ uint8_t __iSeiRetVal(void) |
|
46 |
{ |
|
47 |
sei(); |
|
48 |
return 1; |
|
49 |
} |
|
50 |
|
|
51 |
static __inline__ uint8_t __iCliRetVal(void) |
|
52 |
{ |
|
53 |
cli(); |
|
54 |
return 1; |
|
55 |
} |
|
56 |
|
|
57 |
static __inline__ void __iSeiParam(const uint8_t *__s) |
|
58 |
{ |
|
59 |
sei(); |
|
60 |
__asm__ volatile ("" ::: "memory"); |
|
61 |
(void)__s; |
|
62 |
} |
|
63 |
|
|
64 |
static __inline__ void __iCliParam(const uint8_t *__s) |
|
65 |
{ |
|
66 |
cli(); |
|
67 |
__asm__ volatile ("" ::: "memory"); |
|
68 |
(void)__s; |
|
69 |
} |
|
70 |
|
|
71 |
static __inline__ void __iRestore(const uint8_t *__s) |
|
72 |
{ |
|
73 |
SREG = *__s; |
|
74 |
__asm__ volatile ("" ::: "memory"); |
|
75 |
} |
|
76 |
#endif /* !__DOXYGEN__ */ |
|
77 |
|
|
78 |
/** \file */ |
|
79 |
/** \defgroup util_atomic <util/atomic.h> Atomically and Non-Atomically Executed Code Blocks |
|
80 |
|
|
81 |
\code |
|
82 |
#include <util/atomic.h> |
|
83 |
\endcode |
|
84 |
|
|
85 |
\note The macros in this header file require the ISO/IEC 9899:1999 |
|
86 |
("ISO C99") feature of for loop variables that are declared inside |
|
87 |
the for loop itself. For that reason, this header file can only |
|
88 |
be used if the standard level of the compiler (option --std=) is |
|
89 |
set to either \c c99 or \c gnu99. |
|
90 |
|
|
91 |
The macros in this header file deal with code blocks that are |
|
92 |
guaranteed to be excuted Atomically or Non-Atmomically. The term |
|
93 |
"Atomic" in this context refers to the unability of the respective |
|
94 |
code to be interrupted. |
|
95 |
|
|
96 |
These macros operate via automatic manipulation of the Global |
|
97 |
Interrupt Status (I) bit of the SREG register. Exit paths from |
|
98 |
both block types are all managed automatically without the need |
|
99 |
for special considerations, i. e. the interrupt status will be |
|
100 |
restored to the same value it has been when entering the |
|
101 |
respective block. |
|
102 |
|
|
103 |
A typical example that requires atomic access is a 16 (or more) |
|
104 |
bit variable that is shared between the main execution path and an |
|
105 |
ISR. While declaring such a variable as volatile ensures that the |
|
106 |
compiler will not optimize accesses to it away, it does not |
|
107 |
guarantee atomic access to it. Assuming the following example: |
|
108 |
|
|
109 |
\code |
|
110 |
#include <inttypes.h> |
|
111 |
#include <avr/interrupt.h> |
|
112 |
#include <avr/io.h> |
|
113 |
|
|
114 |
volatile uint16_t ctr; |
|
115 |
|
|
116 |
ISR(TIMER1_OVF_vect) |
|
117 |
{ |
|
118 |
ctr--; |
|
119 |
} |
|
120 |
|
|
121 |
... |
|
122 |
int |
|
123 |
main(void) |
|
124 |
{ |
|
125 |
... |
|
126 |
ctr = 0x200; |
|
127 |
start_timer(); |
|
128 |
while (ctr != 0) |
|
129 |
// wait |
|
130 |
; |
|
131 |
... |
|
132 |
} |
|
133 |
\endcode |
|
134 |
|
|
135 |
There is a chance where the main context will exit its wait loop |
|
136 |
when the variable \c ctr just reached the value 0xFF. This happens |
|
137 |
because the compiler cannot natively access a 16-bit variable |
|
138 |
atomically in an 8-bit CPU. So the variable is for example at |
|
139 |
0x100, the compiler then tests the low byte for 0, which succeeds. |
|
140 |
It then proceeds to test the high byte, but that moment the ISR |
|
141 |
triggers, and the main context is interrupted. The ISR will |
|
142 |
decrement the variable from 0x100 to 0xFF, and the main context |
|
143 |
proceeds. It now tests the high byte of the variable which is |
|
144 |
(now) also 0, so it concludes the variable has reached 0, and |
|
145 |
terminates the loop. |
|
146 |
|
|
147 |
Using the macros from this header file, the above code can be |
|
148 |
rewritten like: |
|
149 |
|
|
150 |
\code |
|
151 |
#include <inttypes.h> |
|
152 |
#include <avr/interrupt.h> |
|
153 |
#include <avr/io.h> |
|
154 |
#include <util/atomic.h> |
|
155 |
|
|
156 |
volatile uint16_t ctr; |
|
157 |
|
|
158 |
ISR(TIMER1_OVF_vect) |
|
159 |
{ |
|
160 |
ctr--; |
|
161 |
} |
|
162 |
|
|
163 |
... |
|
164 |
int |
|
165 |
main(void) |
|
166 |
{ |
|
167 |
... |
|
168 |
ctr = 0x200; |
|
169 |
start_timer(); |
|
170 |
sei(); |
|
171 |
uint16_t ctr_copy; |
|
172 |
do |
|
173 |
{ |
|
174 |
ATOMIC_BLOCK(ATOMIC_FORCEON) |
|
175 |
{ |
|
176 |
ctr_copy = ctr; |
|
177 |
} |
|
178 |
} |
|
179 |
while (ctr_copy != 0); |
|
180 |
... |
|
181 |
} |
|
182 |
\endcode |
|
183 |
|
|
184 |
This will install the appropriate interrupt protection before |
|
185 |
accessing variable \c ctr, so it is guaranteed to be consistently |
|
186 |
tested. If the global interrupt state were uncertain before |
|
187 |
entering the ATOMIC_BLOCK, it should be executed with the |
|
188 |
parameter ATOMIC_RESTORESTATE rather than ATOMIC_FORCEON. |
|
189 |
|
|
190 |
*/ |
|
191 |
|
|
192 |
/** \def ATOMIC_BLOCK(type) |
|
193 |
\ingroup util_atomic |
|
194 |
|
|
195 |
Creates a block of code that is guaranteed to be executed |
|
196 |
atomically. Upon entering the block the Global Interrupt Status |
|
197 |
flag in SREG is disabled, and re-enabled upon exiting the block |
|
198 |
from any exit path. |
|
199 |
|
|
200 |
Two possible macro parameters are permitted, ATOMIC_RESTORESTATE |
|
201 |
and ATOMIC_FORCEON. |
|
202 |
*/ |
|
203 |
#if defined(__DOXYGEN__) |
|
204 |
#define ATOMIC_BLOCK(type) |
|
205 |
#else |
|
206 |
#define ATOMIC_BLOCK(type) for ( type, __ToDo = __iCliRetVal(); \ |
|
207 |
__ToDo ; __ToDo = 0 ) |
|
208 |
#endif /* __DOXYGEN__ */ |
|
209 |
|
|
210 |
/** \def NONATOMIC_BLOCK(type) |
|
211 |
\ingroup util_atomic |
|
212 |
|
|
213 |
Creates a block of code that is executed non-atomically. Upon |
|
214 |
entering the block the Global Interrupt Status flag in SREG is |
|
215 |
enabled, and disabled upon exiting the block from any exit |
|
216 |
path. This is useful when nested inside ATOMIC_BLOCK sections, |
|
217 |
allowing for non-atomic execution of small blocks of code while |
|
218 |
maintaining the atomic access of the other sections of the parent |
|
219 |
ATOMIC_BLOCK. |
|
220 |
|
|
221 |
Two possible macro parameters are permitted, |
|
222 |
NONATOMIC_RESTORESTATE and NONATOMIC_FORCEOFF. |
|
223 |
*/ |
|
224 |
#if defined(__DOXYGEN__) |
|
225 |
#define NONATOMIC_BLOCK(type) |
|
226 |
#else |
|
227 |
#define NONATOMIC_BLOCK(type) for ( type, __ToDo = __iSeiRetVal(); \ |
|
228 |
__ToDo ; __ToDo = 0 ) |
|
229 |
#endif /* __DOXYGEN__ */ |
|
230 |
|
|
231 |
/** \def ATOMIC_RESTORESTATE |
|
232 |
\ingroup util_atomic |
|
233 |
|
|
234 |
This is a possible parameter for ATOMIC_BLOCK. When used, it will |
|
235 |
cause the ATOMIC_BLOCK to restore the previous state of the SREG |
|
236 |
register, saved before the Global Interrupt Status flag bit was |
|
237 |
disabled. The net effect of this is to make the ATOMIC_BLOCK's |
|
238 |
contents guaranteed atomic, without changing the state of the |
|
239 |
Global Interrupt Status flag when execution of the block |
|
240 |
completes. |
|
241 |
*/ |
|
242 |
#if defined(__DOXYGEN__) |
|
243 |
#define ATOMIC_RESTORESTATE |
|
244 |
#else |
|
245 |
#define ATOMIC_RESTORESTATE uint8_t sreg_save \ |
|
246 |
__attribute__((__cleanup__(__iRestore))) = SREG |
|
247 |
#endif /* __DOXYGEN__ */ |
|
248 |
|
|
249 |
/** \def ATOMIC_FORCEON |
|
250 |
\ingroup util_atomic |
|
251 |
|
|
252 |
This is a possible parameter for ATOMIC_BLOCK. When used, it will |
|
253 |
cause the ATOMIC_BLOCK to force the state of the SREG register on |
|
254 |
exit, enabling the Global Interrupt Status flag bit. This saves on |
|
255 |
flash space as the previous value of the SREG register does not |
|
256 |
need to be saved at the start of the block. |
|
257 |
|
|
258 |
Care should be taken that ATOMIC_FORCEON is only used when it is |
|
259 |
known that interrupts are enabled before the block's execution or |
|
260 |
when the side effects of enabling global interrupts at the block's |
|
261 |
completion are known and understood. |
|
262 |
*/ |
|
263 |
#if defined(__DOXYGEN__) |
|
264 |
#define ATOMIC_FORCEON |
|
265 |
#else |
|
266 |
#define ATOMIC_FORCEON uint8_t sreg_save \ |
|
267 |
__attribute__((__cleanup__(__iSeiParam))) = 0 |
|
268 |
#endif /* __DOXYGEN__ */ |
|
269 |
|
|
270 |
/** \def NONATOMIC_RESTORESTATE |
|
271 |
\ingroup util_atomic |
|
272 |
|
|
273 |
This is a possible parameter for NONATOMIC_BLOCK. When used, it |
|
274 |
will cause the NONATOMIC_BLOCK to restore the previous state of |
|
275 |
the SREG register, saved before the Global Interrupt Status flag |
|
276 |
bit was enabled. The net effect of this is to make the |
|
277 |
NONATOMIC_BLOCK's contents guaranteed non-atomic, without changing |
|
278 |
the state of the Global Interrupt Status flag when execution of |
|
279 |
the block completes. |
|
280 |
*/ |
|
281 |
#if defined(__DOXYGEN__) |
|
282 |
#define NONATOMIC_RESTORESTATE |
|
283 |
#else |
|
284 |
#define NONATOMIC_RESTORESTATE uint8_t sreg_save \ |
|
285 |
__attribute__((__cleanup__(__iRestore))) = SREG |
|
286 |
#endif /* __DOXYGEN__ */ |
|
287 |
|
|
288 |
/** \def NONATOMIC_FORCEOFF |
|
289 |
\ingroup util_atomic |
|
290 |
|
|
291 |
This is a possible parameter for NONATOMIC_BLOCK. When used, it |
|
292 |
will cause the NONATOMIC_BLOCK to force the state of the SREG |
|
293 |
register on exit, disabling the Global Interrupt Status flag |
|
294 |
bit. This saves on flash space as the previous value of the SREG |
|
295 |
register does not need to be saved at the start of the block. |
|
296 |
|
|
297 |
Care should be taken that NONATOMIC_FORCEOFF is only used when it |
|
298 |
is known that interrupts are disabled before the block's execution |
|
299 |
or when the side effects of disabling global interrupts at the |
|
300 |
block's completion are known and understood. |
|
301 |
*/ |
|
302 |
#if defined(__DOXYGEN__) |
|
303 |
#define NONATOMIC_FORCEOFF |
|
304 |
#else |
|
305 |
#define NONATOMIC_FORCEOFF uint8_t sreg_save \ |
|
306 |
__attribute__((__cleanup__(__iCliParam))) = 0 |
|
307 |
#endif /* __DOXYGEN__ */ |
|
308 |
|
|
309 |
#endif |
include/libdragonfly/i2c.h | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (c) 2007 Colony Project |
|
3 |
* |
|
4 |
* Permission is hereby granted, free of charge, to any person |
|
5 |
* obtaining a copy of this software and associated documentation |
|
6 |
* files (the "Software"), to deal in the Software without |
|
7 |
* restriction, including without limitation the rights to use, |
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
9 |
* copies of the Software, and to permit persons to whom the |
|
10 |
* Software is furnished to do so, subject to the following |
|
11 |
* conditions: |
|
12 |
* |
|
13 |
* The above copyright notice and this permission notice shall be |
|
14 |
* included in all copies or substantial portions of the Software. |
|
15 |
* |
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
23 |
* OTHER DEALINGS IN THE SOFTWARE. |
|
24 |
**/ |
|
25 |
|
|
26 |
|
|
27 |
/** @file i2c.h |
|
28 |
* @brief Header file for I2C |
|
29 |
* |
|
30 |
* Contains functions for I2C. |
|
31 |
* |
|
32 |
* @author Kevin Woo and Suresh Nidhiry, Colony Project, CMU Robotics Club |
|
33 |
**/ |
|
34 |
|
|
35 |
|
|
36 |
#ifndef _I2C_H_ |
|
37 |
#define _I2C_H_ |
|
38 |
|
|
39 |
#include <stddef.h> |
|
40 |
|
|
41 |
/** @brief Address of slave receive handler function **/ |
|
42 |
typedef void (*fun_srecv_t)(char); |
|
43 |
|
|
44 |
/** @brief Address of master receive handler function**/ |
Also available in: Unified diff