Project

General

Profile

Revision 1554

View differences:

include/libwireless/sensor_matrix.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 sensor_matrix.h
28
 * @brief Definitions for sensor matrices
29
 *
30
 * Contains functions and declarations for using sensor matrices.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef SENSOR_MATRIX_H
36
#define SENSOR_MATRIX_H
37

  
38

  
39
/**
40
 * @defgroup sensormatrix Sensor Matrix
41
 * @brief the robot sensor matrix
42
 *
43
 * These functions and structures are used for localization
44
 * to determine the relative directions of robots.
45
 *
46
 * @{
47
 **/
48

  
49
#define MAXIMUM_XBEE_ID		0x10
50
#define READING_UNKNOWN		0xFF
51

  
52
/**
53
 * @struct SensorMatrix
54
 *
55
 * A sensor matrix.
56
 **/
57
//TODO: the order of member variables in this struct should be changed in case the compile packs the struct
58
// In order to achieve the best packing, the variables should be listed in order of decreasing memory size.
59
// Thus, pointers should be first, followed by int, followed by char.
60
typedef struct
61
{
62
	/**
63
	 * The number of robots in the token ring.
64
	 **/
65
	int numJoined;
66
	/**
67
	 * The element representing a robot is true if that robot
68
	 * is in the token ring and false otherwise.
69
	 **/
70
	unsigned char joined[MAXIMUM_XBEE_ID];
71

  
72
	// on the bayboard, we don't include the matrix to save memory.
73
#ifndef BAYBOARD
74
	/**
75
	 * The matrix. Each row represents the readings of one
76
	 * robot.
77
	 **/
78
	unsigned char matrix[MAXIMUM_XBEE_ID][MAXIMUM_XBEE_ID];
79
#endif
80
} SensorMatrix;
81

  
82
/**@brief Create a sensor matrix **/
83
void sensor_matrix_create(void);
84
/**@brief Set a reading in a sensor matrix **/
85
void sensor_matrix_set_reading(int observer, int robot, int reading);
86
/**@brief Get a reading in a sensor matrix **/
87
int sensor_matrix_get_reading(int observer, int robot);
88
/**@brief Set whether the robot is in the token ring **/
89
void sensor_matrix_set_in_ring(int robot, int in);
90
/**@brief Get whether the robot is in the sensor ring **/
91
int sensor_matrix_get_in_ring(int robot);
92
/**@brief Get the number of robots which have joined the token ring **/
93
int sensor_matrix_get_joined(void);
94
/**@brief Get the maximum size of the sensor matrix **/
95
int sensor_matrix_get_size(void);
96

  
97
/** @} **/ //end defgroup
98

  
99

  
100
#endif
101

  
include/libwireless/wireless.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 wireless.h
28
 * @brief Contains definitions for the wireless library.
29
 *
30
 * Contains functions for the wireless library.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef WIRELESS_H
36
#define WIRELESS_H
37

  
38
//Note: If this is raised above 16, we will need to do
39
//something about frame numbers for TX Status packets.
40
/**
41
 * The maximum number of packet groups.
42
 **/
43
//TODO: a PacketGroupHandler is at least 10 bytes (I don't know if function pointers are 2 bytes
44
// or 4 bytes).  That means that in the c file, your array of packet groups is at least 160 bytes.
45
// Normally that might be fine (the robot's avr chips have 4k SRAM), but austin's chip only has
46
// 1k SRAM, so if this number can be reduced or if the size of the struct could be reduced, that would be a plus.
47
#define WL_MAX_PACKET_GROUPS 16
48

  
49
/**
50
 * @defgroup wireless Wireless
51
 * @brief Wireless definitions.
52
 *
53
 * Contains functions and definitions for dealing with wireless functionality.<br><br>
54
 *
55
 * The wireless library provides a modular method for dealing with
56
 * wireless packets, by allowing packet groups to be registered.
57
 * A packet group is a collection of packets which share a packet
58
 * group code. Each packet in the group also has a type. A packet
59
 * group code and type are sent with each packet. When a packet
60
 * with a group code registered in the wireless library is
61
 * received, the corresponding event handler is called. The
62
 * event handler uses the packet type and other information
63
 * stored in the packet to respond.<br><br>
64
 *
65
 * This architecture allows different wireless functionality to be
66
 * defined and handled separately, making it simpler and more
67
 * efficient to take advantage of the XBee's wireless functionality.
68
 *
69
 * @{
70
 **/
71

  
72
/**
73
 * @struct PacketGroupHandler
74
 * A PacketGroupHandler represents a packet group, and is used to
75
 * register a packet group with the wireless library. It contains
76
 * handlers for various events which can occur related to a packet
77
 * group.
78
 **/
79
//TODO: the order of member variables in this struct should be changed in case the compile packs the struct
80
// In order to achieve the best packing, the variables should be listed in order of decreasing memory size.
81
// Thus, pointers should be first, followed by int, followed by char.
82
typedef struct
83
{
84
	/**
85
	 * The group code for this packet group. This number
86
	 * must be unique. The maximum number of packet groups
87
	 * is defined by WL_MAX_PACKET_GROUPS.
88
	 **/
89
  //TODO: if this number must be less than or equal to WL_MAX_PACKET_GROUPS, don't you only need
90
  // one byte for it and it can be made an unsigned char?
91
	unsigned int groupCode;
92

  
93
	/**
94
	 * Called every half second (not in interrupt,
95
	 * but in wl_do).
96
	 **/
97
	void (*timeout_handler) (void);
98

  
99
	/**
100
	 * Called when a transmit status packet is received
101
	 * from the XBee where the first four bits of the frame
102
	 * are  the group code.
103
	 *
104
	 * @param frame the last four bits of the frame
105
	 * @param received is true if we received an ack, 0 if
106
	 * we did not.
107
	 **/
108
	void (*handle_response) (int frame, int received);
109

  
110
	/**
111
	 * Called when we receive a packet from this group.
112
	 *
113
	 * @param type the packet type
114
	 * @param source the 16-bit address of the XBee this
115
	 * packet was sent from
116
	 * @param packet the packet received
117
	 * @param length the length of the packet
118
	 **/
119
	void (*handle_receive) (char type, int source, unsigned char* packet, int length);
120

  
121
	/**
122
	 * Called for any cleanup when the network is turned off.
123
	 **/
124
	void (*unregister) (void);
125

  
126
} PacketGroupHandler;
127

  
128
/**@brief Initialize the wireless library **/
129
int wl_init(void);
130
/**@brief Uninitialize the wireless library **/
131
void wl_terminate(void);
132
/**@brief Perform wireless library functionality **/
133
void wl_do(void);
134
/**@brief Register a packet group with the wireless library **/
135
void wl_register_packet_group(PacketGroupHandler* h);
136
/**@brief Unregister a packet group with the wireless library **/
137
void wl_unregister_packet_group(PacketGroupHandler* h);
138

  
139
/**@brief Send a packet to a specific robot in any PAN **/
140
int wl_send_robot_to_robot_global_packet(char group, char type, char* data, int len, int dest, char frame);
141
/**@brief Send a packet to a specific robot in our PAN **/
142
int wl_send_robot_to_robot_packet(char group, char type, char* data, int len, int dest, char frame);
143
/**@brief Send a packet to all robots **/
144
int wl_send_global_packet(char group, char type, char* data, int len, char frame);
145
/**@brief Send a packet to all robots in our PAN **/
146
void wl_send_pan_packet(char group, char type, char* data, int len, char frame);
147

  
148
/**@brief Set the PAN we are using **/
149
int wl_set_pan(int pan);
150
/**@brief Get the PAN we are using **/
151
int wl_get_pan(void);
152
/**@brief Set the channel we are using **/
153
int wl_set_channel(int channel);
154
/**@brief Get the channel we are using **/
155
int wl_get_channel(void);
156
/**@brief Get the 16-bit address of the XBee module **/
157
int wl_get_xbee_id(void);
158
/**@brief Set the com port on a computer, undefined on the robot.**/
159
void wl_set_com_port(char* port);
160

  
161
/** @} **/ // end defgroup
162

  
163
#endif
164

  
include/libwireless/wl_token_ring.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 wl_token_ring.h
28
 * @brief Declarations for the token ring packet group
29
 * 
30
 * Contains declarations for the token ring packet group.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef WL_TOKEN_RING_H
36
#define WL_TOKEN_RING_H
37

  
38
/**
39
 * @defgroup tokenring Token Ring
40
 * @brief Wireless library token ring implementation
41
 *
42
 * This packet group is used to form a token ring, which
43
 * keeps track of the relative directions of the robots
44
 * from one another.
45
 *
46
 * @{
47
 **/
48

  
49
/**@brief Register the token ring group with the wireless library.**/
50
int wl_token_ring_register(void);
51
/**@brief Unregister the token ring group with the wirelss library.**/
52
void wl_token_ring_unregister(void);
53
/**@brief Set the functions called to turn the bom on and off.**/
54
void wl_token_ring_set_bom_functions(void (*on_function) (void), void (*off_function) (void),
55
  int (*max_bom_function) (void));
56

  
57
/**@brief Join the token ring **/
58
int wl_token_ring_join(void);
59
/**@brief Leave the token ring **/
60
void wl_token_ring_leave(void);
61

  
62
/**@brief Return the number of robots in the token ring **/
63
int wl_token_get_robots_in_ring(void);
64
/**@brief Return whether a given robot is in the token ring **/
65
int wl_token_is_robot_in_ring(int robot);
66

  
67
/**@brief Begin iterating through robots in the token ring **/
68
void wl_token_iterator_begin(void);
69
/**@brief Returns whether there are more robots to iterate through **/
70
int wl_token_iterator_has_next(void);
71
/**@brief Returns the ID of the next robot in the token ring **/
72
int wl_token_iterator_next(void);
73

  
74
/**@brief Return the latest BOM reading between two robots **/
75
int wl_token_get_sensor_reading(int source, int dest);
76
/**@brief Return the latest BOM reading between us and another robot **/
77
int wl_token_get_my_sensor_reading(int dest);
78
/**@brief Return the number of robots in the sensor matrix.*/
79
int wl_token_get_num_robots(void);
80
/**@brief Return the number of non-null elements in the sensor matrix*/
81
int wl_token_get_matrix_size(void);
82

  
83
/** @} **/ //end token ring group
84

  
85
#endif
include/libwireless/xbee.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 xbee.h
28
 * @brief Contains definitions for using the XBee
29
 *
30
 * Contains definitions for interfacing with the 
31
 * XBee module, from either a robot or a computer.
32
 * To use a robot, define ROBOT in wl_defs.h, and
33
 * to use a computer, don't define ROBOT.
34
 *
35
 * @author Brian Coltin, Colony Project, CMU Robotics Club
36
 **/
37

  
38
#ifndef XBEE_H
39
#define XBEE_H
40

  
41
/**
42
 * The port to use the XBee from on the computer.
43
 * Also, a backup port if the other is used.
44
 **/
45
#ifndef ROBOT
46
#define XBEE_PORT_DEFAULT "/dev/ttyUSB1"
47
#endif
48

  
49
/**
50
 * @defgroup xbee XBee
51
 * @brief Interface with the XBee module
52
 *
53
 * Interface with the XBee module.
54
 *
55
 * @{
56
 **/
57

  
58
/*Definitions*/
59
/**@brief Unset PAN, uses XBee default **/
60
#define XBEE_PAN_DEFAULT 0xFFFF
61
/**@brief Unset channel, uses XBee default **/
62
#define XBEE_CHANNEL_DEFAULT 0
63
/**@brief Broadcast to all robots in the PAN **/
64
#define XBEE_BROADCAST 0xFFFF
65
/**@brief No special options **/
66
#define XBEE_OPTIONS_NONE 0x00
67
/**@brief Do not receive a TX_STATUS message from this packet **/
68
#define XBEE_OPTIONS_DISABLE_RESPONSE 0x01
69
/**@brief Send the packet to all PANS **/
70
#define XBEE_OPTIONS_BROADCAST_ALL_PANS 0x04
71
/**@brief A transmit status packet **/
72
#define XBEE_TX_STATUS 0x89
73
/**@brief A packet received from another XBee **/
74
#define XBEE_RX 0x81
75

  
76
/**@brief Initialize the XBee library **/
77
int xbee_lib_init(void);
78
/**@brief Uninitialize the XBee library **/
79
void xbee_terminate(void);
80
/**@brief Get a packet from the XBee **/
81
int xbee_get_packet(unsigned char* packet);
82
/**@brief Send a packet to the XBee **/
83
int xbee_send_packet(char* packet, int len, int dest, char options, char frame);
84
/**@brief Set the PAN ID for the XBee **/
85
int xbee_set_pan_id(int id);
86
/**@brief Get the XBee's PAN ID **/
87
unsigned int xbee_get_pan_id(void);
88
/**@brief Set the channel the XBee is currently using **/
89
int xbee_set_channel(int channel);
90
/**@brief Get the channel the XBee is currently using **/
91
int xbee_get_channel(void);
92
/**@brief Get the XBee's 16-bit address **/
93
unsigned int xbee_get_address(void);
94
/**@brief Set the com port on a computer, undefined on the robot**/
95
void xbee_set_com_port(char* port);
96

  
97
/**@}**/ //end defgroup
98

  
99
#endif
include/libwireless/wl_basic.h
1
/**
2
 * @file wl_basic.h
3
 * @brief High Level Wireless Packet Sending-Receiving Functions
4
 *
5
 * Abstracted wireless functionality for sending and receiving packets
6
 *
7
 * @author Christopher Mar, Colony Project, CMU Robotics Club
8
 **/
9

  
10
/**
11
 * @defgroup wl_basic Wireless Basic
12
 * @brief Wireless abstraction for easily sending and receing packets.
13
 *
14
 * A high level abstraction of the wireless library.
15
 *
16
 * This will allow you to easily send and receive packets.
17
 *
18
 * @{
19
 **/
20

  
21
#ifndef WL_BASIC_H
22
#define WL_BASIC_H
23

  
24
#include <wireless.h>
25

  
26
/** @brief default wireless group for basic sending and receiving packets **/
27
#define WL_BASIC_GROUP 8
28

  
29
/** @brief PacketGroupHandler struct for Basic Group **/
30
PacketGroupHandler wl_basic_group_handler;
31

  
32
/**
33
 * @brief struct that contains relevant packet information
34
 **/
35
struct PacketInfo {
36
    char new_flag;
37
    char type;
38
    int source;
39
    unsigned char* data;
40
    int length;
41
};
42

  
43
/**
44
 * @brief current packet information, correct after wl_basic_do()
45
 **/
46
struct PacketInfo current_packet;
47

  
48
/** @brief init wireless for Basic Group **/
49
int wl_basic_init( void (*handle_receive) (char type, int source, unsigned char* packet, int length) );
50
/** @brief init wireless for Basic Group with default packet handling **/
51
int wl_basic_init_default( void );
52
/** @brief internal function to register a packet handler function **/
53
void wl_basic_register_handler( void (*handle_receive) (char type, int source, unsigned char* packet, int length) );
54
/** @brief send a packet to a single robot in Basic Group **/
55
void wl_basic_send_robot_packet( char type, char* data, int len, int dest );
56
/** @brief send a packet to all robots in Basic Group **/
57
void wl_basic_send_global_packet( char type, char* data, int len );
58
/** @brief internal default packet handler if none is specified on init **/
59
void wl_basic_packet_receive_handler( char type, int source, unsigned char* packet, int length );
60
/** @brief wrapper for wl_do() to return packet data buffer **/
61
unsigned char* wl_basic_do_default( int *length );
62
/** @} **/ // end defgroup
63

  
64
#endif
65

  
include/libwireless/wl_defs.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 wl_defs.h
28
 * @brief Definitions for Wireless
29
 *
30
 * Contains definitions for wireless packet groups, packet types,
31
 * debugging information, etc.
32
 *
33
 * @author Brian Coltin, Colony Project, CMU Robotics Club
34
 **/
35

  
36
#ifndef WL_DEFS_H
37
#define WL_DEFS_H
38

  
39
//comment out this line if using a computer hooked up to an xbee
40
//#define ROBOT
41

  
42
//uncomment this line for debug information
43
//#define WL_DEBUG
44

  
45
// Packet Groups and Types
46

  
47
// Error group
48
#define WL_ERROR_GROUP 1
49

  
50
#define WL_ERROR_STRING_TYPE 1
51

  
52
// Token Ring group
53
#define WL_TOKEN_RING_GROUP 2
54

  
55
#define WL_TOKEN_PASS 1
56
#define WL_TOKEN_SENSOR_MATRIX 2
57
#define WL_TOKEN_BOM_ON 3
58
#define WL_TOKEN_JOIN 4
59
#define WL_TOKEN_JOIN_ACCEPT 5
60

  
61
// timing constants
62
#ifndef FIREFLY
63
#define BOM_DELAY 100
64
#else
65
#define BOM_DELAY 200
66
#endif
67

  
68
#define DEATH_DELAY 4
69
#define JOIN_DELAY 8
70

  
71
#ifdef WL_DEBUG
72

  
73
#ifdef ROBOT
74
#include <serial.h>
75
#endif
76

  
77
#ifdef ROBOT
78
#define WL_DEBUG_PRINT( s ) usb_puts( s )
79
#else
80
#define WL_DEBUG_PRINT( s ) printf( s )
81
#endif
82

  
83
#ifdef ROBOT
84
#define WL_DEBUG_PRINT_INT( i ) usb_puti(i)
85
#else
86
#define WL_DEBUG_PRINT_INT( i ) printf("%i", i)
87
#endif
88

  
89
#else
90

  
91
#define WL_DEBUG_PRINT( s )
92
#define WL_DEBUG_PRINT_INT( i )
93

  
94
#endif
95

  
96
#endif
97

  
include/libwireless/queue.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 queue.h
28
 * @brief A queue implementation
29
 * 
30
 * Implements a queue, a first in, first out data structure.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef WIRELESS_QUEUE_H
36
#define WIRELESS_QUEUE_H
37

  
38
#ifndef ROBOT
39
#include <pthread.h>
40
#endif
41

  
42
struct node_def;
43

  
44
/**
45
 * @defgroup queue Queue
46
 * @brief A queue implementation
47
 * 
48
 * A queue implementation.
49
 *
50
 * @{
51
 **/
52

  
53
/**
54
 * @struct Queue
55
 * Represents a queue, a first in, first out data structure.
56
 **/
57
typedef struct
58
{
59
	/**
60
	 * The head of the queue, the next item to be removed.
61
	 **/
62
	struct node_def* head;
63
	/**
64
	 * The tail of the queue, the last item added.
65
	 **/
66
	struct node_def* tail;
67
	/**
68
	 * The number of elements in the queue.
69
	 **/
70
	int size;
71
	
72
#ifndef ROBOT
73
	pthread_mutex_t lock;
74
#endif
75
} Queue;
76

  
77
/** @brief Create a new queue **/
78
Queue* queue_create(void);
79
/** @brief Destroy a queue **/
80
void queue_destroy(Queue* q);
81
/** @brief Add an element to a queue **/
82
int queue_add(Queue* q, void* item);
83
/** @brief Remove an element from a queue **/
84
void* queue_remove(Queue* q);
85
/** @brief Remove all instances of a given element from a queue **/
86
void queue_remove_all(Queue* q, void* item);
87
/** @brief Get the size of a queue **/
88
int queue_size(Queue* q);
89
/** @brief Check if the queue is empty **/
90
int queue_is_empty(Queue* q);
91

  
92
/** @} **/
93

  
94

  
95
#endif
include/libwireless/wl_error_group.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 wl_error_group.h
28
 * @brief Error Packets
29
 *
30
 * A packet group for sending error packets.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

  
35
#ifndef WL_ERROR_GROUP_H
36
#define WL_ERROR_GROUP_H
37

  
38
/**
39
 * @file wl_error_group.h
40
 * @brief A packet group for error messages.
41
 *
42
 * A packet group for sending and receiving error
43
 * messages.
44
 *
45
 * @author Brian Coltin, Colony Project, CMU Robotics Club
46
 **/
47

  
48
/**
49
 * @defgroup wlerror Error Packets
50
 * @brief Functions for sending and receiving error packets
51
 * 
52
 * Functions for sending and receiving error packets.
53
 * 
54
 * @{
55
 **/
56

  
57
/**@brief Register this packet group with the wireless library **/
58
void wl_error_register(void);
59
/**@brief Unregister this packet group with the wireless library **/
60
void wl_error_unregister(void);
61
/**@brief Send a string in an error packet **/
62
void wl_error_send_string(char* str);
63

  
64
/** @} **/ // end defgroup
65

  
66
#endif
include/libdragonfly/lights.h
1
// FIXME remove
2
typedef unsigned char uint8_t;
3

  
4

  
5
/**
6
 * Copyright (c) 2007 Colony Project
7
 * 
8
 * Permission is hereby granted, free of charge, to any person
9
 * obtaining a copy of this software and associated documentation
10
 * files (the "Software"), to deal in the Software without
11
 * restriction, including without limitation the rights to use,
12
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
13
 * copies of the Software, and to permit persons to whom the
14
 * Software is furnished to do so, subject to the following
15
 * conditions:
16
 * 
17
 * The above copyright notice and this permission notice shall be
18
 * included in all copies or substantial portions of the Software.
19
 * 
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
 * OTHER DEALINGS IN THE SOFTWARE.
28
 **/
29

  
30

  
31
/**
32
 * @file lights.h
33
 * @brief Contains declarations for managing the orbs.
34
 *
35
 * Contains declarations for using the orbs and PWM.
36
 *
37
 * @author Colony Project, CMU Robotics Club
38
 * Based on Firefly Library, by Tom Lauwers and Steven Shamlian
39
 **/
40

  
41
#ifndef _LIGHTS_H_
42
#define _LIGHTS_H_
43

  
44
/**
45
 * @addtogroup orbs
46
 * @{
47
 **/
48

  
49
/**
50
 * Quick start: call orb_init_pwm or orb_init_binary, depending on which mode you want to use. Call orb*set or
51
 * orb*set_color to set the orbs.
52
 * 
53
 * The orbs have two modes of operation: PWM mode and binary mode. In PWM mode, a pwm signal is generated by a hardware
54
 * timer and the orbs can be set to a value of 0 through 255. In binary mode, the orbs can only be turned on or off and
55
 * a value of 0 means "off" and any other value means "on". The mode can be chosen on initialization and can be changed
56
 * at runtime using the orb_set_mode function.
57
 *
58
 * Operation (PWM mode): On timer overflow, all LEDs with a value>0 are turned on and the output compare value for the
59
 * first LED is loaded. On compare match, the corresponding LED is turned off and the next output compare value is
60
 * loaded. All masks are precomputed and sorted by time when setting the values.
61
 *
62
 * The data structure (pwm_t) containing the PWM times and masks is triple buffered. This is because the buffer the ISR
63
 * is reading from may only be modified on timer overflow before the next PWM sequence is started, because otherwise the
64
 * next OCR value might be sed to a value smaller than the current timer value, resulting in the remaining channels not
65
 * being turned off in that PWM period (flash to on). When using two buffers, the page flip can only occur on a timer
66
 * overflow for the same reason. So after writing a buffer and marking it for page flip, neither of the buffers could be
67
 * modified because the front buffer is read by the ISR and the back buffer could be switched at any time. So the
68
 * calling thread would have to be delayed by up to one full PWM period (8ms in the current implementation, but
69
 * 20ms-50ms would be a reasonable value to expect here). To avoid this, triple buffering is used.
70
 *
71
 * The code for applying the orbs is fairly optimized. See the apply_orbs function for some time measurements and
72
 * further nodes.
73
 *
74
 * The PWM frequency is 120Hz (8ms period time). The next lower frequency (determined by the prescaler) is 30 Hz which
75
 * is too slow (orbs flicker).
76
 *
77
 * The orbs code is thread safe, which means that the functions may be called from another interrupt handler. If there
78
 * are multiple concurrent calls to the orb*set* functions, one of them is ignored and the orbs are never left in an
79
 * inconsistent state. For example, if the orbs are set to green by the main thread and to red by an interrupt handler,
80
 * the resulting color will be either red or green, but never yellow.
81
 * Thread safety is achieved by grabbing a lock at the beginning of all functions that modify the orb code and releasing
82
 * the lock at the end. If the lock is already taken, the function just returns doing nothing.
83
 *
84
 * Some performance measurements:
85
 *   - Time for setting new orb values (PWM mode):       35us-72us (depending on the degree to which the array is
86
 *                                                                  already in the correct order)
87
 *   - Time for setting new orb values (binary mode):        5.5us
88
 *
89
 *   - Interrupt time (PWM mode only):                         8us (overflow)
90
 *                                                            10us (output compare)
91
 *                                                             6us (last output compare)
92
 *                                                            30us (output compare, all value equal)
93
 *
94
 *   - Maximum total interrupt time per period:               64us
95
 *   - Maximum CPU usage for interrupts (PWM mode only):     <0.8%
96
 *
97
 *   - Maximum contiguous synchronized block:                 30us (output compare interrupt, all values equal)
98
 *
99
 * There are some potential optimizations left. See the source code for more information.
100
 *
101
 * A note on robustness: if the output compare interrupt is disabled for too long, either due to a long ISR or a long
102
 * synchronized code block, the orbs will flicker to brighter values for being turned off too late. With software PWM,
103
 * there's nothing at all to be done about that. The problem can be alleviated by using a lower PWM frequency, but then
104
 * the orbs will start flickering all the time due to the low update frequency.
105
 * Some measurements: with 100us synchronized blocks, the flickering is accepptably low. Longer synchronized blocks
106
 * mean more flickering. At 1ms synchronized blocks, the flickering is quite bad, especially for low orb values. Note
107
 * that orb value 0 never flickers at all because the corresponding channels are not turned on at all.
108
 * Test code (note the _delay_us restrictions!)
109
 *   orb_set (1,1,1); while (1) { SYNC { for (uint8_t m=0; m<10; ++m) { _delay_us(10); } } }
110
 **/
111

  
112
/** @} **/ //end addtogroup
113

  
114
/**
115
 * @addtogroup orbs
116
 * @{
117
 **/
118

  
119
// ***** Predefined colors *****
120
/** @brief Red **/
121
#define RED       0xE0
122
/** @brief Orange **/
123
#define ORANGE    0xE4
124
/** @brief Yellow **/
125
#define YELLOW    0xE8
126
/** @brief Lime **/
127
#define LIME      0x68
128
/** @brief Green **/
129
#define GREEN     0x1C
130
/** @brief Cyan **/
131
#define CYAN      0x1F
132
/** @brief Blue **/
133
#define BLUE      0x03
134
/** @brief Pink **/
135
#define PINK      0xA6 
136
/** @brief Purple **/
137
#define PURPLE    0x41
138
/** @brief Magenta **/
139
#define MAGENTA   0xE3
140
/** @brief White **/
141
#define WHITE     0xFE
142
/** @brief Turn the orb off **/
143
#define ORB_OFF   0x00
144

  
145

  
146

  
147
// ***** Initialization *****
148

  
149
/** @brief Enables the orbs in default mode **/
150
void orb_init(void);
151

  
152
/** @brief Enables the orbs in binary mode **/
153
void orb_init_binary (void);
154

  
155
/** @brief Enables the orbs in PWM mode **/
156
void orb_init_pwm (void);
157

  
158

  
159

  
160
// ***** Mode setting *****
161

  
162
/** Specification of the orb mode **/
163
typedef uint8_t orb_mode_t;
164

  
165
/** @brief PWM mode **/
166
#define orb_mode_pwm 0
167

  
168
/** @brief Binary mode **/
169
#define orb_mode_binary 1
170

  
171

  
172
/** @brief Switches the orbs to the specified mode **/
173
void orb_set_mode (orb_mode_t mode);
174

  
175
/** @brief Disables the orb timer, but does not change the mode **/
176
void orb_disable_timer (void);
177

  
178
/** @brief Enables the orb timer, but does not change the mode **/
179
void orb_enable_timer (void);
180

  
181

  
182

  
183
// ***** Setting RGB colors *****
184

  
185
/** @brief set the specified orb to a specified color
186
* 	@deprecated This function indexes from 0 instead of 1 **/
187
void orb_n_set (uint8_t num, uint8_t red, uint8_t green, uint8_t blue);
188

  
189
/** @brief Set both orbs to a specified color **/
190
void orb_set(uint8_t red, uint8_t green, uint8_t blue);
191

  
192
/** @brief Set orb1 to a specified color **/
193
void orb1_set(uint8_t red_led, uint8_t green_led, uint8_t blue_led); 
194

  
195
/** @brief Set orb2 to a specified color **/
196
void orb2_set(uint8_t red_led, uint8_t green_led, uint8_t blue_led);
197

  
198
void orbs_set (uint8_t red1, uint8_t green1, uint8_t blue1, uint8_t red2, uint8_t green2, uint8_t blue2);
199

  
200

  
201

  
202
// ***** Settings predefined colors *****
203

  
204
/** @brief set the specified orb to the specified color
205
* 	@deprecated This function indexes from 0 instead of 1 **/
206
void orb_n_set_color(uint8_t num, uint8_t col);
207

  
208
/** @brief Set orb1 to a specified color **/
209
void orb1_set_color(uint8_t col);
210

  
211
/** @brief Set orb2 to a specified color **/
212
void orb2_set_color(uint8_t col);
213

  
214
/** @brief set the orbs to specified colors **/
215
void orbs_set_color(uint8_t col1, uint8_t col2);
216

  
217
/** @brief Set both orbs to a specified color **/
218
void orb_set_color(uint8_t col);
219

  
220

  
221

  
222
/** @} **/ //end addtogroup
223

  
224
#endif
include/libdragonfly/spi.h
1
/**
2
 * @file spi.h
3
 * @brief Definitions for SPI
4
 * @author Colony Project, CMU Robotics Club
5
 **/
6

  
7
/**
8
 * @addtogroup spi
9
 * @{
10
 **/
11

  
12
#ifndef __SPI_H__
13
#define __SPI_H__
14

  
15
#define DOUBLE_SCK 1
16
#define SPR0_BIT 1
17

  
18
#define MASTER 1
19
#define SLAVE 0
20

  
21
#define MOSI _BV(PB2)
22
#define MISO _BV(PB3)
23
#define SS   _BV(PB0)
24
#define SCLK _BV(PB1)
25

  
26
typedef void (*spi_fun_recv_t)(char);
27
typedef void (*spi_fun_recv_complete_t)(void);
28

  
29
/** 
30
* @brief Initialize SPI
31
* 
32
* @param spi_fun_recv_t The function that handles SPI data, byte for byte.
33
* @param spi_fun_recv_complete_t  Called on a completed transmission - typically for cleaning up.
34
*/
35
void spi_init (spi_fun_recv_t, spi_fun_recv_complete_t);
36

  
37
/** 
38
* @brief Initialize SPI transfer.
39
* 
40
* @param char The number of bytes to transfer.
41
*/
42
void spi_transfer (char);
43

  
44
/**@}**/ //end group
45

  
46
#endif
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/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*/
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff