Satellite Stations

The hardware and software requirements for satellite stations are specified in Section Components of Project 4. Each satellite station is unaware of the presence of the other satellite stations. These stations do not make any decisions regarding the trajectories they follow. They just maintain the radius and speed transmitted to them. Therefore, the software component is simple and we are confident that just by inspecting the AVR source code given in Listing 1 one can understand the logic of this module.

A Complete Satellite-Station

Figure 1 shows our assembled satellite-stations. We have used 2 Mega 2560 and 1 Mega 1280 boards. The wiring schematics between the Roomba robots and the micro-controller boards are similar to the one given in Section Hardware of Project 1. The CE, CSN and the IRQ pins of the radios are connected to the Arduino pin no. 8, 9, and 2 respectively. .



Figure 1: Three satellite stations.

Source Code

We now give the complete source code for the satellite-stations in Listing 1.
/*
 * satellite_station.c
 *  Author: Rayhan
 */ 

#include "radio.h"
#include "uart.h"
#include "roomba.h"
#include 
#include 
#include 

uint8_t this_station_addr[5] = { 0xE4, 0xE4, 0xE4, 0xE4, 0xE4 }; 
volatile uint8_t rxflag = 0;
radiopacket_t packet;

int16_t previous_radius = 0;
int16_t current_radius = 500;
int16_t previous_speed = 0;
int16_t current_speed = 50;


void reset_radio()
{
	PORTB &= ~_BV(PB6);
	_delay_ms(100);
	PORTB |= _BV(PB6);
	_delay_ms(100);
}

void radio_rxhandler(uint8_t pipenumber)	
{
	rxflag = 1;
}

/*
packet contents: bytes 0:1 radius, 0th byte is the high byte
				 bytes 2:3 speed, 3rd byte is the high byte
*/
int16_t read_speed(uint8_t* message_content)
{
	
	int16_t speed = message_content[0];
	speed = (speed << 8) + message_content[1];
	return speed;
}

int16_t read_radius(uint8_t* message_content)
{
	int16_t radius = message_content[3];
	radius = (radius << 8) + message_content[4];
	return radius;
}

int main(void)
{
	
	DDRB |= _BV(PB6) | _BV(PB7);
	DDRA |= _BV(PA3);
	
	reset_radio();
	Radio_Init();
	Radio_Configure_Rx(RADIO_PIPE_0, this_station_addr, ENABLE);
	Radio_Configure(RADIO_2MBPS, RADIO_HIGHEST_POWER);
	
	uart1_init(UART_57600);
	Roomba_Init();
	
	sei();
    while(1)
    {		
        while (rxflag){
			if (Radio_Receive(&packet) != RADIO_RX_MORE_PACKETS){
				rxflag = 0;
			}
			previous_speed = current_speed;
			current_speed = read_speed(packet.payload.message.messagecontent);
			previous_radius = current_radius;
			current_radius = read_radius(packet.payload.message.messagecontent);	
			Roomba_Drive(current_speed, current_radius);
		}
    }
}
Listing 1:Embedded AVR code for the satellite stations. A full-blown RTOS is not necessary.