Project

General

Profile

Revision 1864

Added by Alex Zirbel over 13 years ago

Added comments (doxygen style) to linefollow and linedrive.

View differences:

trunk/code/projects/traffic_navigation/main.c
2 2
 * main.c for Traffic Navigation
3 3
 * Runs the highest level behavior for the Dynamic Traffic Navigation (DTM) SURG
4 4
 *
5
 * Author: Benjamin Wasserman, Colony Project, CMU Robotics Club
6
 */
5
 * Author: Benjamin Wasserman, Colony Project, CMU Robotics Club */
7 6

  
8 7
#include <dragonfly_lib.h>
9 8
#include <wl_basic.h>
trunk/code/projects/linefollowing/lineDrive.c
1
/**
2
 * @file lineDrive.c
3
 *
4
 * Provides functions to implement line driving behavior.  This program extends
5
 * the behavior of the line-following program by following lines automatically
6
 * and implementing behaviors to deal with commands passed to lineDrive.
7
 *
8
 * @author Dan Jacobs
9
 * @date 11-1-2010
10
 */
11

  
1 12
#include "lineDrive.h"
2 13

  
3
int state[5];
14
int state[5];       //! Stores a queue of sub-commands to be executed
4 15
int stateCounter;
5 16
int stateLength;
17

  
18
//! Whether lineDrive is currently paused. Set to 0 on initialization.
6 19
int stopped=1;
7 20

  
8 21

  
9

  
22
/**
23
 * Starts the line following procedure. Must be called before other
24
 * line-following functions will work.  This function essentially resets the
25
 * state of line-following.
26
 */
10 27
void lineDrive_init()
11 28
{
12 29
	lineFollow_init();
......
17 34
}
18 35

  
19 36

  
20

  
37
/**
38
 * Follows a line and executes whatever command is next on the queue.
39
 * @param speed The speed with which to drive along the line.
40
 */
21 41
int doDrive(int speed)
22 42
{
23 43
	if(stopped)
......
97 117
}
98 118

  
99 119

  
120
/** Starts the line-drive process if paused. */
100 121
void start(void){stopped=0;}
122

  
123
/** Pauses the line-drive process. Default is started. */
101 124
void stop(void){stopped=1;}
102 125

  
103 126

  
127
/**
128
 * Defines a merge command in the direction specified.  A merge is a switch
129
 * of lanes.
130
 * @param dir Left or right, defined by ILEFT or IRIGHT
131
 */
104 132
int merge(int dir)
105 133
{
106 134
	if(stateLength!=0)return ERROR;
......
109 137
	return NORMAL;
110 138
}
111 139

  
140
/**
141
 * Executes an intersection turn where the intersection type is specified by the
142
 * parameters. 
143
 * @param type A valid defined intersection type
144
 * @param dir The direction to turn at the intersection
145
 */
112 146
int turn(int type, int dir)
113 147
{
114 148
	if(stateLength!=0)return ERROR;
trunk/code/projects/linefollowing/lineFollow.c
1
/**
2
 * @file lineFollow.c
3
 *
4
 * Takes care of following a line. Running this program is done by calling the
5
 * init() function and then the lineFollow(speed) command.  However, direct use
6
 * of this class is discouraged as its behavior is used by lineDrive.c, which
7
 * extends this class to provide behavior functionality.
8
 *
9
 * @author Dan Jacobs
10
 * @date 11-1-2010
11
 */
12

  
1 13
#include "lineFollow.h"
2 14

  
3 15
#define CODESIZE 5 
......
13 25
int disableBarCode=0;
14 26

  
15 27

  
28
/** 
29
 * Initializes line following. Must be called before other line-following
30
 * behavior will work.
31
 */
16 32
void lineFollow_init()
17 33
{
18 34
	analog_init(0);
......
22 38
}
23 39

  
24 40

  
25

  
41
/** 
42
 * Follows a line at the given speed.
43
 * @param speed The speed with which to follow the line.
44
 */
26 45
int lineFollow(int speed)
27 46
{
28 47
	int colors[5];
......
72 91
}
73 92

  
74 93

  
94
/**
95
 * Implements the left merge, assuming a line exists to the left.  Works by
96
 * turning off the line at an increasing angle and waiting to hit another line
97
 * on the left.
98
 */
75 99
int mergeLeft()
76 100
{
77 101
	motor_l_set(FORWARD, 200);
......
96 120
}
97 121

  
98 122

  
123
/**
124
 * Implements the right merge, assuming a line exists to the right.  Works by
125
 * turning off the line at an increasing angle and waiting to hit another line
126
 * on the right.
127
 */
99 128
int mergeRight()
100 129
{
101 130
        motor_r_set(FORWARD, 200);
......
121 150

  
122 151

  
123 152

  
153
/**
154
 * Turns left at a cross of two lines.  Assumes that we are at lines in a cross
155
 * pattern, and turns until it sets straight on the new line.
156
 * @return 1 if the turn was executed successfully, 0 otherwise.
157
 */
124 158
int turnLeft()
125 159
{
126 160
        motor_l_set(BACKWARD, 200);
......
142 176

  
143 177

  
144 178

  
179
/**
180
 * Turns right at a cross of two lines.  Assumes that we are at lines in a cross
181
 * pattern, and turns until it sets straight on the new line.
182
 * @return 1 if the turn was executed successfully, 0 otherwise.
183
 */
145 184
int turnRight()
146 185
{
147 186
        motor_r_set(BACKWARD, 200);
......
245 284
}
246 285

  
247 286

  
287
//! A simple function to return the minimum of two integers.
248 288
int min(int x, int y){return x>y ? y : x;}
289
//! A simple function to return the maximum of two integers.
249 290
int max(int x, int y){return x<y ? y : x;}
250 291

  
251 292
void motorLeft(int speed){
......
255 296
void motorRight(int speed){
256 297
        ((speed-=127)>=0)?motor_r_set(FORWARD, 160+speed*95/128):motor_r_set(BACKWARD, 160-speed*95/127);
257 298
}
258

  

Also available in: Unified diff