Difference between revisions of "Swarm Robot Project E-puck Code"

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


=main.h=
=main.h=
==#define notRTS SELECTOR3==
Defines the SELECTOR3 pin (this used to be connected to the selector switch on the original extension module that we have replaced with the XBee board) as the notRTS pin.

==#define notCTS SELECTOR2==
Defines the SELECTOR2 pin (this used to be connected to the selector switch on the original extension module that we have replaced with the XBee board) as the notCTS pin.

==#define SQUARE(x) ((x) * (x))==
This macro squares a number.

==#define AGENT_ID 1...#if (AGENT_ID == 1)...==
This allows you to give the robots an ID number for setting parameters for different robots (change the AGENT_ID and recompile for each robot). This is sometimes useful for testing purposes if you wish to give each agent a different set of initial parameters.

==float robotX robotY robotTheta==
These global variables hold the (X,Y) coordinates and the orientation (in radians) of the robot (-PI to PI).

==#define NUM_DATA_SETS 5 ==
Number of statistics on which you are running the consensus estimator. This this particular case, 5. (Ix, Iy, Ixx, Ixy, Iyy)

==#define NUMBERS_PER_SET 2==
Number of variables in each data set (see above) that the consensus estimator needs to transmit to other agents. In this case, 2 because there is <tt>x_i</tt> and <tt>w_i</tt>.

==#define DATATYPE_BYTELENGTH 4 ==
Number of bytes in each data type (float = 4 bytes long)
==#define DATA_ARRAY_LENGTH (NUM_DATA_SETS*NUMBERS_PER_SET)==
Total number of data in packet
==#define ADDITIONAL_NUMS 5==
Additional number of data to be appended to data frame

void delay(long time){ //250 is about 1 ms
long i;
for (i=0; i<time; i++){
}
}
#endif


=e_init_port.h/.c=
=e_init_port.h/.c=

Revision as of 19:00, 19 January 2009

This page documents the e-puck code for the 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).

Go back to Swarm_Robot_Project_Documentation

Description of the files:

  • main.c: This contains the entry point of the code and contains the initialization routines, main loop, and interrupt service routines.
  • e_epuck_ports.h: Contains I/O pin definitions.
  • main.h: Contains global variables, macros, and the delay function.
  • e_init_port.h/.c: Initializes the ports on the e-puck. File is from the standard e-puck library.
  • e_led.h/.c: Handes LED manipulation functions. File is from the standard e-puck library.
  • e_motors_swarm.h/.c: Motor control and dead reckoning functions. This is a modified version of the standard e_motors.h/.c library file, with dead reckoning functions added.
  • dsPIC_XBeePackets.h: Contains functions and data structures for assembling and receiving XBee packets.
  • PI_consensus_estimator: Contains functions and data structures for the PI consensus estimator.

main.c

This contains the entry point of the code and contains the initialization routines, main loop, and interrupt service routines.

main(void)

This is the entry point of the code, and contains initialization routines and the main (infinite) loop.

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

This is the interrupt service routine (ISR) for Timer1. This is the "system tick" and triggers every 0.2 seconds. It sets a flag to indicate that the interrupt has been triggered. This is a low priority interrupt.

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

This is the interrupt service routine (ISR) for the UART receiver buffer. This interrupt will trigger whenever a byte comes in on the serial port. This is a high priority interrupt; the PIC will other tasks to run this ISR.

main.h

#define notRTS SELECTOR3

Defines the SELECTOR3 pin (this used to be connected to the selector switch on the original extension module that we have replaced with the XBee board) as the notRTS pin.

#define notCTS SELECTOR2

Defines the SELECTOR2 pin (this used to be connected to the selector switch on the original extension module that we have replaced with the XBee board) as the notCTS pin.

#define SQUARE(x) ((x) * (x))

This macro squares a number.

#define AGENT_ID 1...#if (AGENT_ID == 1)...

This allows you to give the robots an ID number for setting parameters for different robots (change the AGENT_ID and recompile for each robot). This is sometimes useful for testing purposes if you wish to give each agent a different set of initial parameters.

float robotX robotY robotTheta

These global variables hold the (X,Y) coordinates and the orientation (in radians) of the robot (-PI to PI).

#define NUM_DATA_SETS 5

Number of statistics on which you are running the consensus estimator. This this particular case, 5. (Ix, Iy, Ixx, Ixy, Iyy)

#define NUMBERS_PER_SET 2

Number of variables in each data set (see above) that the consensus estimator needs to transmit to other agents. In this case, 2 because there is x_i and w_i.

#define DATATYPE_BYTELENGTH 4

Number of bytes in each data type (float = 4 bytes long)

#define DATA_ARRAY_LENGTH (NUM_DATA_SETS*NUMBERS_PER_SET)

Total number of data in packet

#define ADDITIONAL_NUMS 5

Additional number of data to be appended to data frame

void delay(long time){ //250 is about 1 ms long i; for (i=0; i<time; i++){ } }

  1. endif

e_init_port.h/.c

e_led.h/.c

e_motors_swarm.h/.c