Roomba Tank
CSC 460 Project 3
Macros | Typedefs | Enumerations | Functions | Variables
remote.c File Reference
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "../roomba/roomba.h"
#include "../rtos/os.h"
#include "../uart/uart.h"

Go to the source code of this file.

Macros

#define F_CPU   16000000
 
#define QSize   10
 

Typedefs

typedef enum laser_states LASER_STATES
 
typedef enum servo_states SERVO_STATES
 

Enumerations

enum  laser_states { OFF = 0, ON }
 
enum  servo_states {
  FULL_BACK = 0, HALF_BACK, DEAD_ZONE, HALF_FORWARD,
  FULL_FORWARD
}
 

Functions

int buffer_isFull (int *front, int *rear)
 
int buffer_isEmpty (int *front, int *rear)
 
void buffer_enqueue (int val, int *queue, int *front, int *rear)
 
int buffer_dequeue (int *queue, int *front, int *rear)
 
void enablePORTL6 ()
 
void disablePORTL6 ()
 
void enablePORTL2 ()
 
void disablePORTL2 ()
 
void enablePORTL5 ()
 
void disablePORTL5 ()
 
void enablePORTH3 ()
 
void disablePORTH3 ()
 
void ADC_init ()
 
void Servo_Init ()
 
void Idle ()
 
void Laser_Task ()
 
void Servo_Task ()
 
void Set_Photocell_Threshold ()
 
void LightSensor_Task ()
 
void Get_Sensor_Data ()
 
void Reverse ()
 
void Bump_Back ()
 
void Manual_Drive ()
 
void Auto_Drive ()
 
void Roomba_Task ()
 
void Bluetooth_Send ()
 
void Bluetooth_Receive ()
 
void a_main ()
 

Variables

uint8_t LASER = 0
 
uint8_t SERVO = 1
 
uint8_t PHOTO = 2
 
uint8_t SCREEN = 3
 
uint8_t ROOMBA = 4
 
uint8_t MODE = 5
 
uint8_t IdlePID
 
uint8_t RoombaTestPID
 
uint8_t RoombaTaskPID
 
uint8_t BluetoothSendPID
 
uint8_t BluetoothReceivePID
 
uint8_t LaserTaskPID
 
uint8_t ServoTaskPID
 
uint8_t LightSensorTaskPID
 
uint8_t GetSensorDataTaskPID
 
int laserState
 
int servoState
 
int lastServoState
 
char roombaState
 
int wallState
 
int bumpState
 
uint16_t photocellReading
 
uint16_t photoThreshold
 
int AUTO
 
int servoQueue [QSize]
 
int servoFront
 
int servoRear
 
int laserQueue [QSize]
 
int laserFront
 
int laserRear
 
int roombaQueue [QSize]
 
int roombaFront
 
int roombaRear
 
MUTEX laserMutex
 
MUTEX servoMutex
 
MUTEX sensorMutex
 

Macro Definition Documentation

#define F_CPU   16000000

Definition at line 1 of file remote.c.

#define QSize   10

Queue globals

Definition at line 58 of file remote.c.

Typedef Documentation

typedef enum laser_states LASER_STATES
typedef enum servo_states SERVO_STATES

Enumeration Type Documentation

Enumerator
OFF 
ON 

Definition at line 42 of file remote.c.

Enumerator
FULL_BACK 
HALF_BACK 
DEAD_ZONE 
HALF_FORWARD 
FULL_FORWARD 

Definition at line 47 of file remote.c.

Function Documentation

void a_main ( )

Application level main function. Creates the required tasks and then terminates

Definition at line 548 of file remote.c.

void ADC_init ( )

Initializes A to D conversion.

Definition at line 173 of file remote.c.

void Auto_Drive ( )

Auto mode, Drive straight forward.

Definition at line 426 of file remote.c.

void Bluetooth_Receive ( )

Receive the joystick, laser, and mode data from the base station over bluetooth.

Definition at line 486 of file remote.c.

void Bluetooth_Send ( )

Send the photocell reading back to the base station.

Definition at line 472 of file remote.c.

int buffer_dequeue ( int *  queue,
int *  front,
int *  rear 
)

Dequeues the value from the specified buffer and returns it.

Definition at line 105 of file remote.c.

void buffer_enqueue ( int  val,
int *  queue,
int *  front,
int *  rear 
)

Enqueues the value into the specified buffer.

Definition at line 94 of file remote.c.

int buffer_isEmpty ( int *  front,
int *  rear 
)

Returns 1 if the buffer is empty.

Definition at line 87 of file remote.c.

int buffer_isFull ( int *  front,
int *  rear 
)

Returns 1 if the buffer is full.

Definition at line 80 of file remote.c.

void Bump_Back ( )

Drive straight backwards

Definition at line 386 of file remote.c.

void disablePORTH3 ( )

Sets PORTH3 to low.

Definition at line 162 of file remote.c.

void disablePORTL2 ( )

Sets PORTL2 to low.

Definition at line 136 of file remote.c.

void disablePORTL5 ( )

Sets PORTL5 to low.

Definition at line 149 of file remote.c.

void disablePORTL6 ( )

Sets PORTL6 to low.

Definition at line 123 of file remote.c.

void enablePORTH3 ( )

Sets PORTH3 to high.

Definition at line 156 of file remote.c.

void enablePORTL2 ( )

Sets PORTL2 to high.

Definition at line 130 of file remote.c.

void enablePORTL5 ( )

Sets PORTL5 to high.

Definition at line 143 of file remote.c.

void enablePORTL6 ( )

Sets PORTL6 to high.

Definition at line 117 of file remote.c.

void Get_Sensor_Data ( )

Get the bumper and virtual wall data packets from the Roomba.

Definition at line 335 of file remote.c.

void Idle ( )

Idle task to run when nothing else is ready.

Definition at line 198 of file remote.c.

void Laser_Task ( )

Checks the laserQueue, if something is available to dequeue, do it and turn the laser state on or off depending on the value.

Definition at line 207 of file remote.c.

void LightSensor_Task ( )

Sample the lightsensor and if a spike is detected, then the roomba is hit and it is time to die. Every half a second also recalculate the threshold value to account for the roomba moving between light and dark places.

Definition at line 295 of file remote.c.

void Manual_Drive ( )

Drive in the direction the joystick is pointing.

Definition at line 393 of file remote.c.

void Reverse ( )

Do the opposite of the Roombas current state.

Definition at line 353 of file remote.c.

void Roomba_Task ( )

Determine what movement to make based on sensors, and whether it is in manual or auto mode.

Definition at line 433 of file remote.c.

void Servo_Init ( )

Initializes Timer4 to control the servo. Timer4 is configured as phase and frequency PWM mode with a prescaler of 64 and non-inverted PWM. OCR4A=375 Then sets the servo to the middle. 0 degrees = 125, 90 degrees = 375, and 180 degrees= 625.

Definition at line 181 of file remote.c.

void Servo_Task ( )

Slowly move the servo to the desired goal (servoState). If the servo is in the deadzone, do not move.

Definition at line 229 of file remote.c.

void Set_Photocell_Threshold ( )

Takes three readings from the photocells and averages them to get a threshold for what the room is currently like.

Definition at line 260 of file remote.c.

Variable Documentation

int AUTO

Definition at line 37 of file remote.c.

uint8_t BluetoothReceivePID

Definition at line 21 of file remote.c.

uint8_t BluetoothSendPID

Definition at line 20 of file remote.c.

int bumpState

Definition at line 32 of file remote.c.

uint8_t GetSensorDataTaskPID

Definition at line 25 of file remote.c.

uint8_t IdlePID

Definition at line 17 of file remote.c.

uint8_t LASER = 0

Definition at line 10 of file remote.c.

int laserFront

Definition at line 65 of file remote.c.

MUTEX laserMutex

Definition at line 73 of file remote.c.

int laserQueue[QSize]

Definition at line 64 of file remote.c.

int laserRear

Definition at line 66 of file remote.c.

int laserState

Definition at line 27 of file remote.c.

uint8_t LaserTaskPID

Definition at line 22 of file remote.c.

int lastServoState

Definition at line 29 of file remote.c.

uint8_t LightSensorTaskPID

Definition at line 24 of file remote.c.

uint8_t MODE = 5

Definition at line 15 of file remote.c.

uint8_t PHOTO = 2

Definition at line 12 of file remote.c.

uint16_t photocellReading

Definition at line 34 of file remote.c.

uint16_t photoThreshold

Definition at line 35 of file remote.c.

uint8_t ROOMBA = 4

Definition at line 14 of file remote.c.

int roombaFront

Definition at line 69 of file remote.c.

int roombaQueue[QSize]

Definition at line 68 of file remote.c.

int roombaRear

Definition at line 70 of file remote.c.

char roombaState

Definition at line 30 of file remote.c.

uint8_t RoombaTaskPID

Definition at line 19 of file remote.c.

uint8_t RoombaTestPID

Definition at line 18 of file remote.c.

uint8_t SCREEN = 3

Definition at line 13 of file remote.c.

MUTEX sensorMutex

Definition at line 75 of file remote.c.

uint8_t SERVO = 1

Definition at line 11 of file remote.c.

int servoFront

Definition at line 61 of file remote.c.

MUTEX servoMutex

Definition at line 74 of file remote.c.

int servoQueue[QSize]

Definition at line 60 of file remote.c.

int servoRear

Definition at line 62 of file remote.c.

int servoState

Definition at line 28 of file remote.c.

uint8_t ServoTaskPID

Definition at line 23 of file remote.c.

int wallState

Definition at line 31 of file remote.c.