Difference between revisions of "RGB Swarm Robot Project E-puck Code (outdated)"

From Mech
Jump to navigationJump to search
Line 26: Line 26:


===global_vars===
===global_vars===
* .c/.h: declare and define global variables and macros
* .c:

* .h:


===main===
===main===
* .c: This contains the entry point of the code and contains the initialization routines, main loop, and interrupt service routines.
* .c:
* .h: Contains variables, function prototypes, and delay function needed for main.
* .h:

=====void __attribute__((__interrupt__,auto_psv)) _T1Interrupt(void)=====

=====void __attribute__((__interrupt__,auto_psv)) _U2RXInterrupt(void)=====

=====int main(void)=====


===color_cal===
===color_cal===
* .c: Contains void calibrate_color(void) function to run the calibration routine.
* .c: Does some stuff
* .h: Contains function prototype and constant definitions for calibrate_color.
* .h: Declares some stuff

=====void calibrate_color(void)=====
=====void calibrate_color(void)=====

does all this stuff


===dsPIC_XBeePackets===
===dsPIC_XBeePackets===
* .c/.h: Contains functions and data structures for assembling and receiving XBee packets.
* .c:
* .h:


===send_packet===
===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.
* .c:
* .h: Contains function prototype.
* .h:

=====void send_packet(void)=====


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


===wheel_speed_coordinator===
===wheel_speed_coordinator===
* .c: Contains functions for robot motion control
* .c:
* .h: Function prototypes and variabls.
* .h:

=====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===
===e_acc===
* .c: Functions for reading the accelerometers (which is the color sensor).
* .c:
* .h: Function prototypes.
* .h:

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

<code><pre>
//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
</pre></code>

=====int e_get_acc_filtered(unsigned int captor, unsigned int filter_size)=====


===e_ad_conv===
===e_ad_conv===
Set up the ADCs on the puck. Original e-puck library code, with the following modifications
* .c:
* .h: Define constants and functional prototypes
* .h:

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.
<code><pre>
#define MIC_SAMP_FREQ 16384.0
</pre></code>

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.
<code><pre>
// 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
</pre></code>

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.
<code><pre>
#define ACC_SAMP_NB 140 // number of accelerometer samples to store
</pre></code>

* .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===
===e_init_port===

Revision as of 10:27, 4 September 2009

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

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:

e_led

  • .c:
  • .h:

e_motors_swarm

  • .c:
  • .h: