ECE 477 Digital Systems Senior Design Project Rev 8/09

Homework 9: Software Design Considerations

Team Code Name: __Hoard______Group No. _2_____

Team Member Completing This Homework: _____Jay Zifer______

E-mail Address of Team Member: _____jzifer @ purdue.edu

Evaluation:

SCORE

/

DESCRIPTION

10 /

Excellent – among the best papers submitted for this assignment. Very few corrections needed for version submitted in Final Report.

9 /

Very good – all requirements aptly met. Minor additions/corrections needed for version submitted in Final Report.

8 /

Good – all requirements considered and addressed. Several noteworthy additions/corrections needed for version submitted in Final Report.

7 /

Average – all requirements basically met, but some revisions in content should be made for the version submitted in the Final Report.

6 /

Marginal – all requirements met at a nominal level. Significant revisions in content should be made for the version submitted in the Final Report.

* /

Below the passing threshold – major revisions required to meet report requirements at a nominal level. Revise and resubmit.

* Resubmissions are due within one week of the date of return, and will be awarded a score of “6” provided all report requirements have been met at a nominal level.

Comments:

Grader: George Hadley Score: 9/10

1) Technical writing style is pretty good. All important details seem to be mentioned and given adequate detail.

2) The paper is perhaps a little light on references. Are you using some particular method for your robot swarm coordination scheme? References for any papers or research you’re using for this would be very helpful.

1.0  Introduction

HOARD (Horde of Autonomous Robotic Devices) is a collection of small robots and an immobile control unit. The robots will navigate autonomously and communicate with each other over an ad-hoc RF network via MRF24J40MA modules [1]. The control unit’s purpose is to initialize the robots and tell them what function to serve. Each individual robot is equipped with a belt of IR LEDs and sensors for object avoidance and directional proximity to the other agents. The central part of the bots and the control unit is a PIC18F26J13 microcontroller [2]. The code will be organized in a “flag-driven” fashion in embedded C. They will use their capabilities to accomplish tasks utilizing swarm behavior, such as seeking out a “chemical spill”, simulated by light, in an area using their ambient light sensors.

2.0  Software Design Considerations

The heart of each bot and the control unit is a PIC18F26J13 microcontroller. This micro features three registers to control the general IO pins. The IR sensors are spread across the PORTA and PORTC registers, taking up pins RA0, RA1, RA2, RA3, RA5, and RC2. These will each be processed through the built in ATD module of the PIC18F26J13. The six IR LEDs are wired to pin RC1, controlled by the PORTC registers. All of these pins are enabled via the TRISA and TRISC registers. The sensor pins are made inputs by setting the associated TRISC and TRISA bits high. The TC7 bit of TRISC is set low to enable it as an output. The LEDs are spread across the bot and turn on and off simultaneously. Working together, the LEDs and sensors will tell other bots the relative proximity of the broadcasting bot and allow the broadcasting bot to see reflections of its own light and know its proximity to obstacles.

The ambient light sensors each require a pin on the micro. They are wired to pins RB2 and RB3, associated with the PORTB register. Both of these pins are configured as inputs by setting the second and third bits of the TRISB register high. These will act as receptors in our chemical spill simulation. The input will be passed through the ATD module of the micro to get a reading. The ATD module on the micro will output a 10 or 12 bit number based off the analog signal it is given. This is more than accurate enough to distinguish bright light from dim and will serve the purposes of these bots well.

Each bot is outfitted with two Sol Robotics GM3 motors wired through the PORTB pins. By using the half bridge setting of the PIC18F26J13’s enhanced PWM mode, each motor to only need two pins to function, one for power and the other for direction. This is enabled by setting the PxM bits of the CCPxCON register to 10. One motor uses the RB4 and RB5 pins and the other uses the RB6 and RB7 pins, each configured via the TRISB as outputs. This makes for a very pin efficient method of controlling the speed and direction of the bots.

The last part to interface with the micro is the MRF24J40MA module. It handles the RF communication between the different bots, and allows them to exchange information. The module has five relevant pins to connect to the micro. The SDO and INT lines connect to the RC4 and RB0 pins respectively. Both of their TRIS register pins are set high configuring them as inputs. The SDI, SCK, and SC lines connect to the RC5, RC3, and RC6 pins respectively. The TRISC register has their bits set low enabling them as outputs. The SC pin acts as an active low enable pin for the RF module, not allowing it to act unless it is set. The INT pin works through the interrupt structure of the micro. In the INTCON0 register, the external interrupt for pin INT0 (shared by RB0) must be enabled. Also, in INTCON2 the external interrupt pins should be set to trigger on a rising edge. For the serial communications, the SSP0CON1 should have the SSPEN high to enable the ports, and the SSPM bits set to 0000, initializing the SCK at one quarter of the system clock. The SSP0STAT register should have the SMP bit high, setting the micro as the master, and the CKE low, causing transmissions to occur on a SCK change from idle to active.

The PIC18F26J13 is intended to operate on a “flag-driven” code loop. It is being coded in C using the MPLAB IDE. It will continuously be polling its sensors, checking for new packets to decode, determining what direction to move, and checking if it is time for it to transmit. The interrupt it will receive from the RF module will send it to a short subroutine where it will quickly dump the data from the module’s RXFIFIO to the microcontroller’s SSP1BUF. That data will then be stored in data memory to be later processed in the main loop. The PIC18F26J13 has 64 KB of flash program memory as well as 3.8 KB of SRAM data memory. The data memory is divided into 16 pages of general purpose registers and special function registers. The stack pointer will be set to 00000 upon reset. This is an invalid address and must be changed in the initialization of the micro.

We have added an additional four LEDs to our design, two green and two red. They are connected to the RA6 and the RC0 pins respectively. We intend to use them as visual indicators of the bot’s status when it is running. They should prove to be very useful as status indicators in the debugging process as well.

Figure 2.1 PIC18F26J13 Memory Map

00000h
00018h / Reset Vector
Interrupt Vectors
00018h
0FFF8h / Flash Program Memory
0FFF8h
0FFFFh / Flash Configuration Word
10000h
10FFFh / SRAM Data Memory

3.0  Software Design Narrative

The main loop of the program takes care of nearly all of the major functions of the bots. It starts by initializing all the internal registers of the PIC18F26J13. Next it will wait for the control unit to send out the mode to operate in. The loop will then begin running by first checking if it is that particular bot’s turn to transmit information. This will be done through a flag set in the interrupt routine. Next it will check to see if it has any new data to decode. This will also be handled by a flag set in the interrupt routine. Following these, the bot will always poll its sensors and record the data. Afterwards it will analyze what it knows and decide what direction it needs to be moving in.

Progress: Only the initializations have been written and tested.

The transmission function will cover having the bot send out relevant information to the rest of the swarm as well as managing the ad-hoc network. It will start by loading up the micro’s SSP1BUF and sending it to the RF module, then telling the module to transmit. The packets will contain data relevant to the current program, such as bot ID, ambient light being sensed, how long that light has been seen, or if the bot is within sight of a different bot who has found light. Then the IR LEDs on the bot will light up to show the other bots the current transmitter’s location. After this, the transmitter will send a second packet asking for the next robot to transmit. If there is a response within a reasonable time, it will exit the transmission function. If there is no response, the robot will assume the other bot has been lost and send a new packet informing the other bots that they may be missing a member. If that bot is unresponsive long enough, it will be dropped from the group. This would be done by invalidating data known about that bot from each other bot’s memory and adjusting ID numbers in the table to reflect that it is gone. If the transmitting bot finds that it is the last in the round robin, it will send out a packet searching for unknown bots in range. If there is a response, the transmitting bot tells the others to add a new bot to their tables and gives the new bot an ID. After all this, the transmission routine ends.

Progress: This code has not been written. We are still testing and learning to use the RF modules.

Packet decoding should be fairly simple in these robots. The data will have been dumped into memory from the interrupt routine and ready to be analyzed. If that routine ran, there will be a flag set to send the code into this function. Based off what program is currently being run, the data will be interpreted in a different way. The data will be placed into a table keeping track of the status of each bot.

Progress: This code is not yet written.

Sensor polling will occur on every pass through the main loop. The micro will get the values of the six IR sensors as well as the readings from the ambient light sensors after they’ve been run through the ATD module. Then, based off what robot had IR LEDs on, the bot would record the IR data in the appropriate table entry.

Progress: ATD has been sucessfully tested, but this function has not been put into code yet.

Directional decisions will be made based off of the sensor data that has been collected up to that point and the mode the bot Is being run in. Priority will be given to avoiding obstacles over performing the swarm task. A bot is of little use if it is running into walls. The bots will be able to see their own IR LED reflections to know their proximity to objects. When they are moving toward an obstacle they will see high IR light in one of the front three sensors. They should then turn until the light is on one of the back three sensors before they proceed forward. Similarly, if they are seeing a bot, they should turn until they sense that robot’s IR in one of their front three sensors before they move forward. If the robots are not in direct sight of a bot that they want to move towards, we intend to pass information so that they can move towards someone else who can see the desired bot. Unless a bot is searching the environment for something, they should never be moving aimlessly about. The decisions are intended to make sure every bot has an intelligently chosen target to be moving towards in the case that a goal has been found.

Progress: This code is not yet written

Motor drivers will be simple functions telling the bot to either turn left, turn right, back up, go straight or stop. It is a simple matter of adjusting the direction bit being sent out and modifying the PWM.

Progress: These functions have been written and tested.

The packet reception interrupt routine is intended to be as quick as possible. The data will be transferred from the RF module to the micro and unloaded into memory. A flag will be set saying that a new packet has been received and the routine will return to the main loop.

Progress: This code has not been written.

4.0  Summary

The Hoard Robotics project intends to have multiple robots utilizing swarm behavior to accomplish tasks. These robots use RF to communicate relevant information to one another and IR to communicate relative location. The robots are built on the PIC18F26J13 microcontroller and are coded in embedded C. They make use of the built in ATD, PWM, and SPI to a great degree to function. We hope to have eight bots working together simultaneously to accomplish goals in a quick and sophisticated manner.
List of References

[1]  Microchip Technology. “MRF24J40MA Data Sheet”, [Online], Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39776C.pdf . [Accessed March 24, 2011]

[2]  Microchip Technology. “PIC18F47J13 Family Data Sheet”, [Online], Available: http://ww1.microchip.com/downloads/en/DeviceDoc/39974A.pdf . [Accessed March 24, 2011]


Appendix A: Flowchart/Pseudo-co de for Main Program