RGB Swarm Robot Project E-puck Code (outdated)

From Mech
Jump to navigationJump to search

This page documents the e-puck code for the RGB Sensing Swarm Robotics project. The code on the e-puck was written in C and compiled using Microchip's MPLAB C Compiler for dsPIC DSCs (student version).

This code is a branch of the Swarm Project E-puck Code.

Tasks

Complete

  • Restructured code to make more modular.
    • Split dsPIC_XBeePackets and wheel_speed_coordinator into h and c files
    • Pulled packet assembling code out of main and created send_packet() function in send_packet.h/c.
    • Pulled a bunch of variables and defines (NUM_DATA_SETS, NUMBERS_PER_SET, DATATYPE_BYTELENGTH , DATA_ARRAY_LENGTH , ADDITIONAL_NUMS, notRTS, T1_INT_FLAG, x_i, u_i, w_i, x_sum, w_sum, MAX_WHEEL_V_TICKS, deadband, COMMR, SAFEDIST, MINDIST, u_x_ideal, u_y_ideal, x_motion_integral, y_motion_integral, SQUARE) that were scattered across h files into global_vars.h/c. Makes it easy to include them in a particular file with the extern keyword.
  • Added color_cal() function in color_cal.h/c
  • Added wheelSpeedSingleBot to wheel_speed_coordinator

To Do

  • Finish color_cal
  • Make the vision system position information updater smarter.
  • Replace wheelSpeedSingleBot with the three step move controller from NUtest.c
  • Implement new algorithm


Project Package

The source code for the project is available here: Media:RGB_Swarm_Puck_Code_working_version.zip. Open swarm_epucks.mcw and you should be good to go.

Description of the files and functions

global_vars

  • .c/.h: declare and define global variables and macros


main

  • .c: This contains the entry point of the code and contains the initialization routines, main loop, and interrupt service routines.
  • .h: Contains variables, function prototypes, and delay function needed for main.
void __attribute__((__interrupt__,auto_psv)) _T1Interrupt(void)
void __attribute__((__interrupt__,auto_psv)) _U2RXInterrupt(void)
int main(void)

color_cal

  • .c: Contains void calibrate_color(void) function to run the calibration routine.
  • .h: Contains function prototype and constant definitions for calibrate_color.
void calibrate_color(void)

dsPIC_XBeePackets

  • .c/.h: Contains functions and data structures for assembling and receiving XBee packets.

send_packet

  • .c: Contains the void send_packet(void) function which fills an array with data and calls the needed XBee functions to send a packet.
  • .h: Contains function prototype.
void send_packet(void)

PI_consensus_estimator

  • .h: Contains functions and data structures for the PI consensus estimator.
  • This will probably be replaced by the algorithm for sensor consensus.

wheel_speed_coordinator

  • .c: Contains functions for robot motion control
  • .h: Function prototypes and variabls.
void wheelSpeed(int *vL, int *vR)

Return needed wheel speeds for the inertial consensus estimator based on the group goal.

void wheelSpeedSingleBot(float gotox, float gotoy, int *vL, int *vR)

Return needed wheel speed to get this individual bot to (gotox, gotoy). It's a hacked fix. Should be replaced with the 3 step motion controller from NUtest.c.

e_acc

  • .c: Functions for reading the accelerometers (which is the color sensor).
  • .h: Function prototypes.

This is original e-puck library code with the following modifications:

//changed by Sam, July 10, default offset is 2000. we want 0 for RGB sensor.
static int centre_z = 0;			//zero value for z axe
int e_get_acc_filtered(unsigned int captor, unsigned int filter_size)

e_ad_conv

Set up the ADCs on the puck. Original e-puck library code, with the following modifications

  • .h: Define constants and functional prototypes

MIC_SAMP_FREQ sets the baseline sampling frequency for the ADC, everything else must be a fraction of this. 16384 Hz is the highest possible.

#define MIC_SAMP_FREQ 16384.0	

ACC_PROX_SAMP_FREQ sets the sampling frequency for the accelerometers (color sensor). We found in testing that the puck become non-responsive with this set to 8192 Hz or 16384 Hz.

// sampling frequency for the accelerometres and proximetres
//#define ACC_PROX_SAMP_FREQ 256.0	// WARNING: should be a fraction of MIC_SAMP_FREQ
#define ACC_PROX_SAMP_FREQ 4096	//			to ensure a good timing precision
									// So your options are: 1  2  4  8  16  32  64  128  
									//  256  512  1024  2048  4096  8192  16384

ACC_SAMP_NB is the number of samples to store. We can do an average of up to this many samples. This is set to 140 so we can average 136 samples, which is 4 projector periods.

#define ACC_SAMP_NB  140	// number of accelerometer samples to store
  • .c: Functions and interrupt service routines for ADCs. Original e-puck library, no modifications.
e_init_ad_scan(ALL_ADC)

Call to setup ADC and have it work in the background. Use e_acc functions to access data.

e_init_port

  • .c/.h: Initializes the ports on the e-puck. File is from the standard e-puck library.
e_init_ports(void)

This function sets up ports on the e-puck.

e_led

  • .c/.h: This is a standard e-puck library file that contains functions for manipulating LEDs.
void e_set_led(unsigned int led_number, unsigned int value)

Set led_number (0-7) to value (0=off 1=on higher=inverse).

E-puck LED numbering.png


e_motors_swarm

  • .c/.h: This file is a modified version of the e_motors.h e-puck library file. This version keeps track of the robot's position and orientation, and the motor stepping function contains code to update the robot's position when the wheels turn.
void e_init_motors(void)

Call this function before other motor functions to initialize the motors.

void e_set_speed_left(int motor_speed)/void e_set_speed_right(int motor_speed)

Set the motor speed in steps/second.

void e_get_configuration(float *xptr, float *yptr, float *thetaptr)

Updates variables with current x, t, and theta (position and orientation) of the center reference point.

void e_set_configuration(float x, float y, float theta)

Sets x, y, theta to values.

void e_get_configuration_front(float *xptr, float *yptr, float *thetaptr)

Updates variables with current x, t, and theta (position and orientation) of the front reference point (used for motor control).