NIOS Robot Group

Total Page:16

File Type:pdf, Size:1020Kb

NIOS Robot Group

NIOS Robot Group Kelvin Bunn John Sellers Doug Messick Sean James

ECE 4006 Dr. Hamblen July 26, 2002

Georgia Institute of Technology School of Electrical & Computer Engineering - - 2

Table of Contents

Executive Summary page 3

Introduction page 5

Project Goals and Approach page 3

Equipment page 7

Project Design page 8

Gantt Chart page 9

Milestones page 10

Schematic of Program page 13

Tutorial page 14

Results page 16

Appendix A – Downloading to Flash Memory page 19

Appendix B – Sample Server Information Packet Code page 21

Appendix C – AmigoBot_test.c page 23

Appendix D – Source Code – AmigoBot_Commands.c page 24 - - 3

Executive Summary

The design of the project was to use an Altera NIOS board as the controller for an

AmigoBot that would track a moving object while avoiding all other nonmoving objects. The

NIOS board would have a RISC processor in flash memory along with a C program that would determine the velocity and orientation of the robot based on the data sent to it through the serial port of the NIOS board from the sonar sensors on the AmigoBot.

Communication was established between the NIOS board and the AmigoBot at 9600 bits per second. The NIOS board sent the sync0, sync1, sync2 commands to open a connection at which time the AmigoBot began to send back server information packets (SIP) every 100 milliseconds. The packets going to and from the AmigoBot all had the same format: a header, followed by a byte count, then the data, and finally a checksum. In the SIP was information pertaining to the status of the robot; specifically the sonar sensors. The packet was broken up and the sonar data extracted for use in determining the action of the robot. The range chosen for the robot to alter its position within was from 20 cm to 2 meters.

If the object was farther or closer than this, the robot would not move. When an object was located within this range, a client packet was sent from the NIOS board to the AmigoBot instructing it to move forward until it was 20 cm away from the target.

The results of the project did not meet all the design expectations. A connection was established between the NIOS board and the AmigoBot, SIPs were being sent from the robot to the NIOS board where they were broken up, a client command packet was sent back to the

AmigoBot based on the sonar data, and the AmigoBot was moving according to these instructions. However, the rate at which all of this was taking place was rather slow. In - - 4 addition, there was severe difficulty associated with tracking a moving object that moved left or right requiring the removal of states from the code that dealt with these actions. The final version of code could only deal with an object that moved away from the AmigoBot. The issues that hindered the entire completion of the design of the project were the rate of data transfer and the sonar readings. The sonar data would jump back and forth from high to low readings until it settled on the true reading requiring many packets to be sent before the NIOS board would send a movement command that fell within its distance parameters. The result of this was that the AmigoBot spent a good amount of the time sitting still when it should have been moving and the data from the sensors off center was even more wild than the on center sensors. The second issue was the rate of data transfer. The AmigoBot should have been capable of transfer rates of up to 38400 bits per second but the maximum transfer rate reached was 9600. Had the data transferring from the AmigoBot been four times faster, the difficulties associated with waiting for the sonar data to level out would have been much more manageable.

Despite these limitations, the project was a success. The AmigoBot did track an object moving away from it and did move to the desired distance from the target without hitting the target. In addition, the ground work has been set for other groups to expand upon the

AmigoBot/NIOS board project for further reaching applications in the future. - - 5

Introduction

The objective of this project was to demonstrate an AmigoBot capable of tracking moving objects, while avoiding objects that may inhibit successful tracking using the Altera

NIOS board as its controller. To successfully attain this goal, the design and implementation of this project was broken into several components: establish control of the NIOS board, establish control the AmigoBot using the NIOS board, analyze the data received from the

AmigoBot, and respond to the data.

The first step involved establishing communication with the AmigoBot. Specifically, creating client packets of information to send to the AmigOS server consisting of a two byte header (0xFA 0xFB), a byte count of the amount of data to be sent in the rest of the packet, the data, and a two byte checksum. Once communication was opened, the AmigoBot would begin sending server information packets (SIP) back that would tell the status of the robot.

Commands could now be sent to the robot that would control movement and position.

The second step commenced once the AmigoBot began to send SIPs back. In these packets was information pertaining to velocity of wheels, position, battery charge, and sonar data. With concern only for the sonar data, the packet was broken up and the sonar data extracted.

The third step was to design an algorithm that issued a response based on the sonar data. A state machine was setup with the sonar ranges as the determinate for which state was selected with different wheel velocities associated with each state and a default stop state for when the data did not meet the requirements for a state. - - 6

The AmigoBot is one of many intelligent mobile robots, fully equipped with eight range-finding sonar sensors and a differential drive. The low-level systems and electronics are managed by the onboard microcontroller loaded with the AmigOS, operating system software. The eight sonar sensors have an effective range of 10 cm to more than 5 meters; however, for this project the range of the sonar sensors was limited by the C code from 20 cm to 2 meters. The AmigoBot has an internal, rechargeable battery source and three input/output ports. Two of the ports are phone jacks: one located on top of the robot and one on the underside. The other is a nine pin serial port also located on the underside of the robot. The serial port requires a null modem serial cable in order to communicate with a computer. The packet protocol for communicating to the AmigOS server with client commands and from the

AmigOS with server information packets (SIP) consists of a two-byte header (0xFA, 0xFB), a byte count consisting of the number of data bytes following the byte count, the data, and a two byte checksum. Look in appendix B and C for examples of client commands and SIPs and look at the AmigoBot Technical Manual for more information.

The Altera NIOS development board is a highly versatile and configurable embedded processor device. It was used in conjunction with Quartus II software to develop a RISC processor for control of the NIOS board. The NIOS board has a serial port interface that is accessed through the UART_0 pin of the RISC processor and allows for connection speeds of up to 115200 bits per second. Its power source is a seven volt DC power supply but can be operated by a 7.2 volt dc rechargeable battery.

Calculating the checksum for a single command, in this case the rotate counterclockwise command with ten degrees the amount rotated, is found by adding in HEX

0D3B + 0A00 to get 173B resulting in the entire command looking like - - 7

unsigned char dheadpos10[] = {0xFA,0xFB,0x06,0x0D,0x3B,0x0A,0x00,0x17,0x3B}; //+10

with 0xFA 0xFB the header, 0x06 the byte count, 0x3B a positive integer value, 0x0A the 10 degrees in HEX (least significant byte), 0x00 (the most significant byte), and 0x17 0x3B the checksum.

Equipment

Hardware and Software Required

1. NIOS board version 2.0

2. Standard Serial Cable

3. Byteblaster cable and printer cable

4. AmigoBot version 1.0

5. Amigo leash

6. Male-to-male 9-pin null modem serial cable

7. Female-to-female 9-pin null modem serial cable with transfer (TX) line cut on one end

8. Quartus II

9. SerialSniffer 1.32

10. 7.2 Volt Rechargeable battery

11. Power connector that fits the NIOS board - - 8

Project Design

The design of the project consists of three major elements: the computer, the NIOS board, and the AmigoBot. The computer was used as a communication link for the NIOS board and the AmigoBot in the testing phase. Its purpose served to write and download the C program to the board and analyze the data returned from the AmigoBot through the use of the female-to-female cable connected to the serial port on the underside of the AmigoBot on one end and the com2 port of the computer on the other. In the final stages of the project, the computer served only to modify the C code and download it to the NIOS board.

Communication only took place between the NIOS board and the AmigoBot. The NIOS board sent commands to the AmigoBot which in return sent data back to the board. The NIOS board then broke up the data into usable chunks. This information was then used to determine the functions of the motor. Based on the change in sonar information, the AmigoBot would either move forward or stop to avoid running into objects. The data transfer of the design is illustrated in Figure 1. - - 9

Figure 1: Block diagram of the communication tools in data transfer

Gantt Chart

A Gantt chart was created for organization of the project and to keep the project on schedule for completion. The yellow blocks indicate when each section was worked on and the red blocks indicate deviations from the original schedule. The Gantt chart can be found below in figure 2. - - 10

May June July Tasks Duration Who 14 21 28 4 11 18 25 2 9 16 23

Obtain Hardware required for the design project 1w group

Run the Altera NIOS Embedded Processor Tutorial (Getting 1w group Started) and verify working board and computer system.

Run the Altera Tutorial (large tutorial manual) 1w group

Design the RISC processor 1w group

Transmit/receive data from the NIOS serial port 2w

Interface NIOS serial port with the AmigoBot 2w

Preliminary control of AmiboBot by the NIOS board 2w

Final functionality of the AmigoBot - Ready for Demo. 2w

Final Presentation and Report 1w group Figure 2: Gantt chart of NIOS Robot Group

Interfacing the NIOS serial port with the AmigoBot was the only task that required more time than originally planned. This was attributed to difficulties associated with the checksum calculations of the packets the NIOS board sent to the AmigoBot. Although delay with one section threatened to push back completion of the entire project, extra time and effort were invested in making sure the next section was completed on time.

Milestones

Obtaining Hardware and Software

This milestone was completed during the second week of class. It was necessary to obtain all the documentation from Professor Hamblen, as well as the AmigoBot. Mounting materials for the NIOS board were also obtained. - - 11

Complete NIOS Tutorials

The group completed this milestone on June 26, 2002. Each group member contributed time and insight into completing the tutorials. The issue of using Verilog versus VHDL was resolved by the school having licenses for Verilog only. Once this information was made available the tutorial was completed.

Preliminary Research

Each group member was responsible for researching different facets of the design project.

After completing the research, the group sat down to discuss ways to implement the findings.

The research included battery options for the NIOS board, sonar information, and information on the RISC processor.

C-program template

An initial C program template was established on May 30, 2002. The template began as a program that wrote to the monitor and LCD screen of the NIOS board. Later, the code was modified to program the UART of the Altera NIOS board. This required the use of predetermined function calls maintained in the NIOS.H library file.

Communication and Control of NIOS Board

Communication was established with the NIOS board on June 11, 2002. Using the C template to send UART commands, control of the NIOS board was confirmed and communication verified. - - 12

Communication with AmigoBot

Communication was established with the AmigoBot using source code written in C programming language. Four consecutive synchronization packets were sent to the AmigoBot to create open lines of communication. Each packet was complete with a header, a command, and a checksum. This milestone was completed on June 27, 2002.

Checksum Calculator

To successfully send commands to the AmigoBot, it was necessary to include in the command the correct checksum value. This presented a huge problem for the group. The checksum program provided in the AmigoBot manual did not compute the proper checksum. Therefore, it was necessary to figure out the correct procedure in computing the checksum. As a result, the checksum for each command was computed manually and hard-coded into the programs.

Validation of the checksum protocol was verified on July 9, 2002.

Baud Rate Communication Issues

In an effort to increase the speed of communication, the baud rates of both the AmigoBot and the NIOS board were increased. The initial settings were at 9600, but later increased to 38400.

This attempt was unsuccessful and the baud rate was returned to its original setting.

Programming/Downloading NIOS board (flash versus memory)

Downloading the C code to the NIOS board could be achieved using either flash or the erasable memory. Using the erasable memory presented issues with time. It was faster to flash - - 13 the memory of the NIOS board and allowed for repeated tests without having to download the code again. Therefore, the method chosen to program the NIOS board was the flash method.

Control of AmigoBot

Control of the AmigoBot was established on July 11, 2002 by first sending the enable motors command immediately followed by a velocity command. The major issues in completing this portion of the project were computing the checksum and sending the command before the

AmigoBot lost communication. Once these issues were resolved, all the AmigoBot commands were verified and full control of the AmigoBot was established.

Receiving Data from AmigoBot

Receiving data from the AmigoBot was halted when a serial cable and serial sniffer program had to be acquired. The serial cable, a nine pin null modem cable with transmit pin removed from one end. Later, the serial sniffer program was purchased that enabled the group to see the returned information in a hexadecimal format. The program was made available and data received on July 17, 2002.

Schematic of Program

The core of the program was the RISC processor. It was first designed during the

NIOS tutorial and later modified to set the urart_0, which operated through the serial port of the NIOS board, to a baud rate of 9600. Since the AmigoBot was already equipped with sonar - - 14 sensors, and the two devices on the NIOS board used for data testing, the LCD screen and the

LED display, were also setup during the tutorial, no other components were added to the processor. The processor core can be found below in figure 3.

Figure 3: Schematic of NIOS board completed from the tutorial

Tutorial

Steps

1. Follow the Quartus II tutorial to setup the RISC processor. During the tutorial, make

sure to set the baud rate of urart_0 in the RISC processor to 96001.

2. Create a C program that sends client commands to the AmigoBot2. - - 15

3. Connect the AmigoBot leash to the top of the robot and the other end to the male-to-

male null modem cable.

4. Connect one end of the female-to-female cable to the serial port on the underside of

the AmigoBot and the other end to com 2 of the computer. Make sure the end with the

TX line cut is connected to the computer3.

5. Open the SerialSniffer program and setup com 2 to 9600 baud rate with no parity and

8 data bits, 1 stop bit and no flow control. Make sure the connection is set to receive

hex only4.

6. Download the code to flash memory5, start the program, disconnect the serial cable

from the NIOS board, and connect the other end of the male-to-male cable to the

NIOS board.

7. Analyze the Server Information Packet from the AmigoBot for the sensor data6.

8. Modify C code to work with the sonar data.

9. Finish algorithm to deal with the different states of the AmigoBot.

10. Place target to be followed in front of AmigoBot. Make target move and watch

AmigoBot follow.

Superscript Notes

1. Directions for changing the UART_0 baud rate can be found on page 23 of the NIOS

tutorial.

2. Look at amigobot_test.c file in appendix C for execution of simple commands. - - 16

3. If the TX line is not cut on the computer end then what ever commands sent by the

NIOS board are overridden by the default signal sent by the computer and no

information will be sent back by the AmigoBot.

4. SerialSniffer can be obtained at www.flache.de. Programs such as HyperTerminal did

not work because it automatically converted the hex code to ASCII and there are non-

displayable characters in ASCII. To set SerialSniffer to hex mode only, go to Logging

-> Configure -> HEX only (in the complex output parameters box).

5. SDK worked at 115200 baud rate and the uart is now setup to work only at 9600 so it

would not connect to download the srec file. To download to flash memory look to

page 62 of the NIOS tutorial or look at downloading instructions in appendix A.

6. Look at Sample SIP code in appendix B.

Results

The results of the project can be measured in the performance of the AmigoBot. The amigobot_program.c program was downloaded to the NIOS board and the cable running from the board to the computer was switched with the cable running to the robot. The NIOS board opened a connection with the robot by sending the sync0, sync1, and sync2 packets. The

AmigoBot then began to send back its SIPs at 100 millisecond intervals. The program on the board takes each 32 byte long packet, breaks it up, and looks at the six bytes of data dealing with the sonar. Depending on the data, the robot will either move forward or stay stopped.

When the object in front of the robot moves back, the AmigoBot moves forward until it is 20 - - 17 cm away. The final packaging of the AmigoBot and NIOS board can be found below in figure

4.

Figure 4: Final packaging of NIOS board and AmigoBot

There were two major factors that limited the performance of the AmigoBot. The first was the limitations of the sonar sensors. The sonar readings would bounce back and forth from their maximum to minimum values until they settled on the actual value of the distance to the target. This delay caused the state machine on the NIOS board to revert to its default stopped state because the data did not meet any of the conditions of the predefined states.

Once the sonar data settled, the AmigoBot sent the actual distance to the NIOS board. If the target was not a close as it should have been, the NIOS board sent the command for the robot - - 18 to move forward. This delay in sonar readings also resulted in the removal of the states from code that dealt with tracking an object that moved left or right.

The second factor was the rate of data transfer between the AmigoBot and the NIOS board. The NIOS board supported transfer rates all the way up to 115200 bits per second and the AmigoBot manual claimed it could operate at up to 38400 bits per second; however, the fastest baud rate for communication between the board and robot that could be obtained in this project was 9600. Had the max baud rate of 38400 been achieved, the NIOS board would have had four times the amount of data to base its decisions from. Even with the delay in sonar readings, the sonar data would have leveled out much faster and more packets of good data would have been available to work with.

As it stands, the results obtained were encouraging. The NIOS board established communication with the AmigoBot, received data about its status, and returned a movement command to the robot instructing it to move to a certain distance from an object even if the object moved. Future groups using a NIOS board to control the AmigoBot would find the information obtained from this project of great value. Recommendations to future groups would be to find a way to establish a connection at 38400, create a faster, more efficient packet parsing procedure, keep interrupts enabled at all times so as to not risk loosing any data, and add more states for movement of a target to the left or right. - - 19

Appendix A - - 20

Downloading to flash memory

1. Open SDK shell

2. NIOS-build filename.c

3. srec2flash filename.srec

4. NIOS-run –p com1 filename.flash

5. Hold sw2 then sw4 then release sw2 then sw4 on NIOS board to clear memory

6. Open Quartus II -> open project -> NIOS_system_module.quartus

7. Processing -> open programmer -> add file -> NIOS_system_module.sof

8. Programming Hardware -> setup -> Byteblaster

9. Check the programming/configure box

10. Click Start button - - 21

Appendix B - - 22

Sample Server Information Packet code

FA FB 00 //sync0 received

FA FB 03 01 00 01 //sync1 received

FA FB 1D 02 47 65 6F 72 67 69 61 5F 31 31 32 00 50 69 6F 6E 65 65 72 00 41 6D 69 67 6F 00 E6 90 //sync2

FA FB 1F 32 00 00 00 00 00 00 00 00 00 00 78 0E 00 00 00 00 00 00 02 00 B7 98 04 BA 1A 01 00 FC 94 B3

FA FB 1F 32 00 00 00 00 00 00 00 00 00 00 78 0E 00 00 00 00 00 00 02 01 A8 00 05 DD 01 01 00 F2 20 DA

FA FB 1F 32 00 00 00 00 00 00 00 00 00 00 78 0E 00 00 00 00 00 00 02 02 A6 00 06 F8 0C 01 00 F5 3C C7

FA FB 1F 32 00 00 00 00 00 00 00 00 00 00 78 0E 00 00 00 00 00 00 02 03 BA 1A 07 CE 00 01 00 F7 2D CC

FA FB 1F 32 00 00 00 00 00 00 00 00 00 00 78 0E 00 00 00 00 00 00 02 00 A3 00 04 BA 1A 01 00 F5 FC CE

FA FB 1F 32 00 00 00 00 00 00 00 00 00 00 78 0E 00 00 00 00 00 00 02 01 AB 00 05 DD 01 01 00 FD 20 D6

00 B7 98 04 BA 1A //sensor data for sensors 0 and 4

01 A8 00 05 DD 01 //sensor data for sensors 1 and 5 - - 23

Appendix C - - 24

Appendix D

Recommended publications