RP6 ROBOT BASE RP6-BASE RP6v2-BASE ©2007 - 2012 AREXX Engineering www.arexx.
RP6 Robot System Manual - English Version RP6-BASE-EN-20120115 for RP6 and RP6v2 IMPORTANT INFORMATION! Please read carefully! Before you start operating the RP6, RP6v2 or any of the additional equipment, you must read this manual and the manuals for add-on modules completely! The documentation contains information about how to operate the systems properly and how to avoid dangerous situations! Furthermore the manuals provide important details, which may be unknown to average users.
Legal Notice ©2007 - 2012 AREXX Engineering Nervistraat 16 8013 RS Zwolle The Netherlands Tel.: +31 (0) 38 454 2028 Fax.: +31 (0) 38 452 4482 "RP6 Robot System" is a trademark of AREXX Engineering. All other trademarks used in this document belong to their owners. This manual is protected by copyright. No part of it may be copied, reproduced or distributed without the prior written permission of the editor! Changes in product specifications and scope of delivery are reserved.
Contents 1. Introduction ................................................................................. 6 1.1. Technical support .................................................................... 7 1.2. Scope of delivery – RP6 ........................................................... 7 1.3. Scope of delivery - RP6v2 ........................................................ 8 1.4. The RP6v2 and Expansion possibilities ....................................... 8 1.5. Features and technical Data ..........
4.1.2. Configure Syntax Highlighting.............................................56 4.1.3. Opening and compiling sample projects...............................58 4.2. Program upload to the RP6 ..................................................... 60 4.3. Why C? And what's “GCC”? .................................................... 61 4.4. C – Crash Course for beginners ............................................... 62 4.4.1. Literature........................................................................
RP6 ROBOT SYSTEM - 1. Introduction 1. Introduction The RP6 is a low cost autonomous mobile robot system, designed for beginners as well as experienced electronics and software developers as an introduction to the fascinating world of robotics. The robot is delivered completely assembled. Thus it is very well suited for all users who are unexperienced with soldering and tinkering and want to concentrate on software development.
RP6 ROBOT SYSTEM - 1. Introduction 1.1. Technical support You may contact our support team via internet as follows (please read this manual completely before contacting the support! Reading the manual carefully will answer most of your possible questions already! Please also read appendix A – Troubleshooting): - through our forum: http://www.arexx.com/forum/ - by E-Mail: info@arexx.nl You will find our postal address in the legal notice at the beginning of this manual.
RP6 ROBOT SYSTEM - 1. Introduction 1.3. Scope of delivery - RP6v2 You should find the following items in your RP6v2 box: ● ● ● ● ● ● Completely assembled Robot RP6 USB Interface USB A->B cable 10pin flat cable RP6 CD-ROM Quickstart manual Experiment board NOT included! 1.4. The RP6v2 and Expansion possibilities The RP6v2 is a slightly improved Version of the orignial RP6. There are new Encoders and more expansion connectors and some other small improvements. The main change are the new Encoders.
RP6 ROBOT SYSTEM - 1. Introduction The main fuse has been changed from 2.5A to 3.15A, as there are now some additional power supply connectors and the power distribution has been improved. This allows usage of slightly higher power expansions. The Motor Drivers have been improved with new more powerful and more reliable MOSFETs. These have even lower resistance than the ones used before. All these modifications increase the cost significantly.
RP6 ROBOT SYSTEM - 1. Introduction It is possible to combine the RP6v2-M256-WIFI, RP6-M32 and several of the experiment PCBs – in total you would then have a Robot with 3 AVR Processors and around 80 I/O Ports for your applications. These can be connected to the Experiment PCBs via flat cables, where you can add your own sensor electronics or ready to use sensor modules (e.g. Ultrasonic or Infrared Rangers, Temperature, etc.).
RP6 ROBOT SYSTEM - 1. Introduction 1.5. Features and technical Data This section provides an overview of the robot's features and an introduction of some basic keywords, to make you familiar with the terminology used in this manual. Most of these keywords will be explained in later chapters.
RP6 ROBOT SYSTEM - 1. Introduction ● Powerful caterpillar drive unit in combination with a new gearing system for minimising noise (compared to the predecessor CCRP5...) ◊ Two powerful 7.2V DC-Motors ◊ Maximum speed ca. 25 cm/s – depending on charge state and quality of batteries, total weight and other conditions! ◊ Self-lubing, sintered bearings at all four 4mm wheel-axles ◊ Two rubber tracks ◊ Capable of traversing small obstacles (up to ca.
RP6 ROBOT SYSTEM - 1. Introduction ● Two free Analog to Digital Converter (ADC) Channels for external sensor systems (Alternatively useable as standard I/O Pins). ● Accurate 5V voltage regulation ◊ Maximum current supply: 1.5A ◊ Large copper-area for heat dissipation to the PCB ◊ Constant current should not get higher than 1A. More than this requires extra cooling! We recommend a maximum constant current value below 800mA. ● Replaceable 2.5A fuse on RP6 and 3.
RP6 ROBOT SYSTEM - 1. Introduction 1.6. What can the RP6 do? Well, directly taken out of the box – not much! It is the Software which enables the RP6 to actually do something – what this is exactly, is up to you and your creativity to teach the robot how to perform.
RP6 ROBOT SYSTEM - 1. Introduction 1.7. Application proposals and ideas The RP6 has been designed with good expansion possibilities.
RP6 ROBOT SYSTEM - 2. The RP6 in detail 2. The RP6 in detail This chapter describes the most important hardware components of the RP6 ROBOT SYSTEM. We will discuss the electronics, the microcontroller and the interaction of software and hardware. If you are already familiar with microcontroller technology and electronics, you will probably just glance through this chapter. Beginners in robotics however should study this chapter to gain insight to the RP6 basics.
RP6 ROBOT SYSTEM - 2. The RP6 in detail We can divide the Robot in five main functional units: ● Control System ● Power Supply ● Sensors, IR Communication and Displays (Sensors) – everything communicating with the outside world and measureing physical values. ● Drive System ● Expansion System 2.1. Control System As you can see in the diagram, the robot's central unit is an ATMEL ATMEGA32 8-Bit Microcontroller (see fig.). A microcontroller is a complete computer in a single chip.
RP6 ROBOT SYSTEM - 2. The RP6 in detail The controller is communicating to the world outside via 32 I/O Pins ("Input/Output Pins"), organized in "Ports", each composed of 8 I/O Pins. This way the MEGA32 provides 4 "Ports": PORTA to PORTD. The controller is able to read the logical status of these ports and process the information in software. Of course, the processor will equally use the ports to output logical signals in order to control small loads up to 20 mA currents (e.g. LEDs).
RP6 ROBOT SYSTEM - 2. The RP6 in detail 2.1.1. Bootloader There is a so called Bootloader located in a special memory area of the microcontroller. This tiny program is responsible for loading new user programs into the microcontroller's memory via the serial interface. The Bootloader communicates with the the RobotLoader software (original name was RP6Loader) on the host PC. Like this, no additional programming hardware is required.
RP6 ROBOT SYSTEM - 2. The RP6 in detail 2.3. Sensors Most sensors have been mentioned in preceding chapters, but now we will have a closer look at them. In the overview diagram you will find sensors outside of the blue-coloured area “Sensors”. Actually these sensors belong to other modules. However, the odometry encoders, the motor current sensors and the battery voltage sensor are sensors and will be discussed in this chapter, too! 2.3.1.
RP6 ROBOT SYSTEM - 2. The RP6 in detail brightest spot in the room! For example if you illuminate the floor with a very bright halogen-torch, the robot will follow the bright light spot on the floor. Of course you may try the opposite: the robot could be programmed to hide from bright light sources. You can refine this by mounting one or two additional LDRs at the backside of the robot.
RP6 ROBOT SYSTEM - 2. The RP6 in detail 2.3.4. Bumpers There is a small PCB with two micro switches with long levers mounted in front of the Robot. It protects the IR LEDs on the sensor-PCB from being damaged if the robot accidently hits an obstacle. With these switches the Microcontroller can detect collisions and reverse the robot's direction, turn around and then go on with moving forwards. The switches are connected to ports already used by LEDs.
RP6 ROBOT SYSTEM - 2. The RP6 in detail 2.3.6. Encoders The encoders work completely different compared to the previously discussed sensors. They consist of reflective interrupters and code wheels which are attached to one of the gearwheels in each gearing system. This setup is used to determine the rotational velocity of the Motors. Both encoder wheels have 36 segments (18 black and 18 white fields, see figure). While the gears rotate, these segments move along in front of the reflective interrupter.
RP6 ROBOT SYSTEM - 2. The RP6 in detail obstacles, ramps and uneven floors. On such surfaces, the encoders are extremely helpful, as they allow optimal speed regulation under all load conditions, completely independent of surface condition, motor load and Battery voltage. At a rate of 50 segments per second we have a speed of 1.25 cm/s assuming a value of 0.25mm per segment. This speed is the minimal speed, which can be controlled reliably (at least with the standard software implementation).
RP6 ROBOT SYSTEM - 2. The RP6 in detail Now we have found a way to reverse the motor's rotational direction. And how are we going to accelerate or slow down the motor? A DC-Motor will rotate faster the higher the voltage gets and we may control the motor speed by increasing or decreasing the voltage. Let's have a closer look at the H-bridge again. The figure shows what we can do. We generate a square wave at a fixed frequency and apply pulse width modulation, which changes the duty cycle.
RP6 ROBOT SYSTEM - 2. The RP6 in detail the obstacles! Apart from sensor circuits, additional controllers could be useful to perform additional tasks, e.g. the RP6 CONTROL M32 providing an extra MEGA32 microcontroller. Of course the expansion system has to be capable of connecting several expansion modules (see figure), while using a minimum number of signal lines and providing sufficient communication speed. 2.5.1. The I²C Bus The I²C Bus will satisfy these requirements.
RP6 ROBOT SYSTEM - 2. The RP6 in detail Immediately after the start-condition we have to send the 7 Bit long slave-address for the device to be addressed, followed by a bit defining whether we want to write or read data. The slave will respond by sending an ACK ("Acknowledge"). Any number of data bytes may follow and each individual received byte will have to be acknowledged by the slave (using the ACK-signal). Communication will be terminated with a stop-condition.
RP6 ROBOT SYSTEM - 2. The RP6 in detail A few modules can use the interrupt lines for signalling the master microcontroller either the arrival of new data, or whether a job has been completed and new commands are being expected. Not providing these lines would force the master device to repeatingly query some specific expansion modules for new data. Of course this method would be possible, but the alternative design with additional interrupt lines will usually reduce bus traffic and CPU load.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup 3. Hardware and Software Setup Before you start with setting up the RP6 or accessories, you have to read the following safety instructions carefully. Especially if children are handling the RP6 later on! Please read this chapter extra carefully! 3.1. Safety Instructions Due to the open frame architecture of the RP6, there are several sharp edges.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup All electric lines from and to the system must be connected before connecting and applying the supply voltage. Unexpected connecting or disconnecting plugs, cables or modules in an operating robot may damage or destroy parts of the system and additional components. 3.1.2. Environment of the Robot Do not operate the robot on table tops or in areas with high precipies, where it may fall down to the ground.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup 3.2. Software Setup Software setup comes next. Correctly installed software is required for all following chapters. You will need administrator rights to install, so please login as an administrator to your system.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup 3.2.2. WinAVR - for Windows First of all we will install WinAVR. WinAVR however is – as already indicated by its name – available for Windows only! Linux users may skip this section. WinAVR (pronounced “whenever”) is a package of useful and required tools for software development with AVR microcontrollers in the C-language.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup First of all you will have to deinstall any preceding – and as already stated probably obsolete - versions of the avr-gcc, avr-binutils and avr-libc. To start deinstall you may use your distributions package manager tool, search for “avr” and then deinstall the packages from your system, if the tool finds corresponding objects starting with “avr-”. You may easily check whether avr-gcc has been installed or not.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup All relevant installation files for avr-gcc, avr-libc and binutils can be found in the following directory: :\Software\avr-gcc\Linux Start by copying all install files to a directory on your hard disk – this is valid for both installation methods! In this case we will be using the Home directory (a standard shortcut for the Home directory is the swung dash or tilde-character: “~”).
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup 3.2.3.2. Manual install procedure If you prefer manual install or the automated install script fails, you may proceed with the following steps. The description has been derived from the following article: http://www.nongnu.org/avr-libc/user-manual/install_tools.html It can also be found as a PDF document in the AVR Libc Documentation on the CD: :\Software\Documentation\avr-libc-user-manual-1.6.7.pdf Please start on PDF page 90.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup Depending on your PC's performance this will take a few minutes – this is also true for the next two steps – especially for the GCC! GCC for AVR Using similar procedure as for Binutils, the GCC has to be patched, compiled and installed: > > > > > > > > > > > > > cd ~/RP6 bunzip2 -c gcc-4.1.1.tar.bz2 | tar xf cd gcc-4.1.1 patch -p0 < ../gcc-patch-0b-constants.diff patch -p0 < ../gcc-patch-attribute_alias.diff patch -p0 < ../gcc-patch-bug25672.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup 3.2.4. Java 6 The RobotLoader (see below for more information about it) has been designed for the Java environment and may be used in Windows and Linux (in theory, other operating systems such as OS X should work as well, but unfortunately AREXX Engineering does not support this so far). In order to run RobotLoader, you have to install a recent Java Runtime Environment (JRE).
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup 3.2.5. RobotLoader We created the RobotLoader to simplify the uploading process for new programs to the RP6 and all expansion modules (as long as these modules provide a microcontroller with a compatible bootloader). Additionally we implemented a few useful functions, e.g. a simple serial terminal program. You do not have to install the RobotLoader – instead you may simply copy the program somewhere to a new directory on your hard disk.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup 3.3. Connecting the USB Interface – Windows Linux users can skip this section! There are several ways to install the USB Interface Drivers. The simplest way is installing the drivers BEFORE connecting the device for the first time. The CD provides different install programs for the driver. For 32 and 64 Bit Windows XP, Server 2003, Vista and Win 7: :\Software\USB_DRIVER\CDM20814_Setup.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup 3.3.2. Driver uninstall If you should ever need to uninstall the driver (No, please do not uninstall anything now – this is just for your information): If you have been using the CDM-installation software you may uninstall tools by selecting Start --> Settings --> Control Panel --> Software. The list should contain an entry “FTDI USB Serial Converter Drivers”.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup 3.6. Inserting Batteries It's about time to get to the Robot itself. First of all the robot needs 6 batteries! We recommend to use high-quality NiMH Mignon batteries (manufacturers e.g.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup Please take out the black battery holder afterwards (see figure). Make sure that the main power switch is in the position “OFF”! The switch lever must point to the direction of the text “OFF” and the large cylindrical capacitor on the main board (see figure)! Before reactivating the robot, please check correct orientation of the batteries.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup The mainboard may now be put back onto the chassis. Move any cables between mainboard and plastic division bars or other chassis parts away by using your finger or a long screwdriver, in order to locate the mainboard flat and even on the chassis! Before fixing it again, please check for any cabling collisions between mainboard, chassis and gear-wheels! Now you may fix the main board by tightening the four screws – and we're done! 3.7.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup user program to execute anyway. Standby mode may be terminated via the USB Interface, by pressing the Start/Stop Button or by shortly switching the robot off and on. Even in standby mode the robot uses a small amount of energy (up to 5mA) – and please remember to turn off the RP6 completely if you do not want to use the system for a longer time! With a program in memory the robot will not automatically switch to standby mode.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup RobotLoader before you can open it again). The Virtual Comports will be labelled “/dev/ttyUSBx”, in which x represents a number, e.g. “/dev/ttyUSB0” or “/dev/ttyUSB1”. Also the standard comports labelled “/dev/ttyS0”, “/dev/ttyS1” will be shown as well. The RobotLoader remembers the previously selected port and will automatically preselect this port at program start (most of the presets and selections are remembered).
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup The selected file will now appear in the list. This way you may select other Hexfiles from your own programs or from the other examples and add them to the list (s. Screenshot, in which we already added a few hex files). The RobotLoader is able to manage several hexfiles in order to make the upload comfortable. With several expansion modules or different versions of programs you will appreciate this.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup This warning message will be displayed directly before test number 8 and must be acknowledged before the test will start. Please enter the lowercase letter 'x' in the terminal window and hit Enter (you will have to repeat this procedure whenever a similar message is displayed or a test has to be aborted...). At this point the program will output the menu text shown on the left.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup Battery sensor test is next. In fact, the sensor already has been tested as the RobotLoader has shown the battery voltage before.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup If you point a powerful torch at the sensors and illuminate them directly or if you hold the robot into bright sunlight, measurement values may rise to over 1000. In a rather dark room, values should be below 100.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup Next one is the IRCOMM test procedure, which can be startet by entering 'x'. The procedure starts transmitting IR data-packets, displays received packets in the terminal and automatically checks if the received data is OK (using rather powerful IR-diodes, the IRCOMM usually will receive it's own signals back. Only in the absence of any reflecting objects or a ceiling the system may eventually fail – but this would be a very unusual condition).
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup stantly be checking and supervising measurement values from encoders and current sensors. If something got damaged during the transport (e.g. a short circuit in one of the motors or a blocked gear – which should have been noticed in the previous testing phase after inserting the batteries) the monitored current values will rise to high levels and cause the test to be aborted immediately.
RP6 ROBOT SYSTEM - 3.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4. Programming the RP6 At last, we have reached the programming section. 4.1. Configuring the source code Editor We will start by setting up a small development environment. The so-called “source code” of our C programs needs to be entered and edited somehow! Of course we will not use text processing systems like OpenOffice or Word! This may not be obvious for everyone and therefore we explicitly emphasize this.
RP6 ROBOT SYSTEM - 4. Programming the RP6 You are now entering the options dialog, which allows you to change several settings. However we will only add new entries to the tools menu. To proceed, select “C/C++” in the dropdown list to the “Scheme:”menu! Click on “Add”! The dialog on the left should appear. Please exactly enter the things you see on the screenshot. The phrase “%d” refers to the directory of the selected file and “%d\make_all.
RP6 ROBOT SYSTEM - 4. Programming the RP6 As an alternative method to “%d/make_all.bat” you may also simply enter “make” into the field “Command” and “all” into the “Parameters” field. In fact, the batch file simply executes exactly these commands, but the batch file simplifies starting the compiler from Windows Explorer. Now click OK – and a new entry will be displayed in the list: ...click on “Add” once again! Just like for make all, you now have to enter all you see on the screenshot and click on OK.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.1.2. Configure Syntax Highlighting Another setting you may change is the Syntax Highlighting. You can add a few “Keywords” to the standard C/C++ Scheme.
RP6 ROBOT SYSTEM - 4. Programming the RP6 After customizing and opening a sample project according to the next section PN2 should look like in the following screenshot: On the left side you see all sample projects in a treeview, the the source editor (featuring the previously discussed syntax highlighting) is on the right and and the tool output (in this case the compiler output) is on the bottom. You can customize PN2 in various other ways and it provides a great number of useful functions.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.1.3. Opening and compiling sample projects Let's try if everything works fine and open all the sample projects: Select “Open Project(s)” in the “File” menu. In the standard file select dialog, you have to search for the subdirectory “RP6Base_Examples” in the directory of the example programs. Open the file “RP6BaseExamples.ppg”, which is a PN2 project group. It will load all example programs and the RP6Library as well into the Projects list.
RP6 ROBOT SYSTEM - 4. Programming the RP6 The compiler will generate a great number of temporary files (using file extensions like “.o, .lss, .map, .sym, .elf, .dep”). You do not have to look at any of these files and you may use the newly created tool “make clean” to easily delete these files! Only the hexfile will is an important result for you! And “make clean” will not delete the hexfile.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Also very helpful is an overview labelled “AVR Memory Usage” at the end: Size after: AVR Memory Usage ---------------Device: atmega32 Program: 6858 bytes (20.9% Full) (.text + .data + .bootloader) Data: 148 bytes (7.2% Full) (.data + .bss + .
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.3. Why C? And what's “GCC”? The programming language C is widely being in use – in fact, C is the standard language, which anyone interested in software development should have used at least once. C compliers are available for nearly every microcontroller currently on the market and for this reason, all recent robots by AREXX Engineering (ASURO, YETI and RP6) can be programmed in C.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.4. C – Crash Course for beginners This chapter only provides a very short introduction to C-programming, discussing only the absolutely required minimum amount of things used for RP6. This section has to be seen as an overview of general possibilities and methods of C. We will present a few examples and basics, but further investigation on these topics is up to the reader! So this chapter is not more than a tiny crash course.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Additional information can also be found on the WinAVR-Homepage and in the WinAVR PDF-documentation, respectively: http://winavr.sourceforge.net/ http://winavr.sourceforge.net/install_config_WinAVR.pdf And especially the AVR-LibC documentation: http://www.nongnu.org/avr-libc/user-manual/index.html which can also be found as a PDF on the RP6 CD! Of course you do not have to read all these tutorials and books! This list is only a guide for gathering more information.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Anyone feeling bored by the tiny sample program may find a more attractive "Hello World" program in the RP6 example directory, including a running light with the LEDs and some more text outputs! Now let's discuss the program in Listing 1 and explain it line by line! Line 1 - 3: /* A small and simple "Hello World" C Program for the RP6! */ These are comment lines and will not be interpreted by the compiler.
RP6 ROBOT SYSTEM - 4. Programming the RP6 functions, but is not needed in a microcontroller system. We only need to add this return value to meet the standard C-conventions (and as we will see later, programs for microcontrollers will usually never terminate). This tiny program gave you a first impression of C-programming. Now we have to discuss some other basics before we can go on with example programs. 4.4.3.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.4.4. Variables First we'll have a look at storing and reading data to and from RAM. Data access is done through variables. C knows several data types for variables. Basically we will use 8, 16 or 32 Bits integer data types, which may be used either signed or unsigned. The deserved value range determines the required number of bits for defining a storage location for a variable.
RP6 ROBOT SYSTEM - 4. Programming the RP6 In order to use a variable in a program we have to declare it first by defining the data type, a name and eventually an initial value for this variable. The name must start with an alphabetic character (including the underscore “_”), and may contain numbers. However the variable's naming convention excludes a great number of special characters, e.g. “äöüß#'[]²³|*+-.,<>%&/(){}$§=´°?!^”.
RP6 ROBOT SYSTEM - 4. Programming the RP6 z++; z++; z++; z--; z--; z--; // // // // // // abbreviation for z = z + 1; which implies z is now 9 z = 10 // z++ is called “incrementing z” z = 11 ... z = 10 // z-- is called “decrementing z” z = 9 z = 8 ... We previously used the data type “char”. However in most cases we prefer standard data types in all RP6 programs.
RP6 ROBOT SYSTEM - 4. Programming the RP6 One more example: 1 2 3 4 5 6 7 8 9 10 uint16_t myFavoriteVariable = 16447; if( myFavoriteVariable < 16000) // If myFavoriteVariable < 16000 { // then: writeString("myFavoriteVariable is less than 16000!\n"); } else // else: { writeString("myFavoriteVariable is greater than or equal to 16000!\n"); } “myFavoriteVariable” is set to 16447, which will result in an output “myFavoriteVariable is greater than or equal to 16000!“.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.4.6. Switch-Case Often we will have to compare a variable to a great number of different values and decide to execute further program code according to the result of these comparisons. Of course, we could use a great number of if-then-else conditional statements, but the language provides a more elegant method by using a switch-case-construct.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.4.7. Loops We need loops if operations need to be repeated a number of times. Let's demonstrate the basic principle in an example: 1 2 3 4 5 6 7 8 uint8_t i = 0; while(i < 10) { writeString("i="); writeInteger(i, DEC); writeChar('\n'); i++; } // // // // // // as long as i is less than 10... ... repeat the following code: output "i=", output the "DECimal" value of i and ... ... a line-break. increment i.
RP6 ROBOT SYSTEM - 4. Programming the RP6 You may simply build endless loops with while- or for-loops: while(true) { } or for(;;) { } In both cases the command block will be executed “for ever” (respectively until the microcontroller receives an external reset signal or the program terminates the loop by executing the “break”-instruction). For the sake of completeness we finish this overview by describing the “do-while”loop, which may be considered as an alternative to the standard “while”-loop.
RP6 ROBOT SYSTEM - 4.
RP6 ROBOT SYSTEM - 4.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.4.9. Arrays, Strings, Pointers... A great number of further interesting C-features are waiting to be discussed, but for details we will have to refer to available literature! Most of the program examples can be understood without further study. In the remaining sections of this crash course we describe only a few examples and concepts in a short overview, which of course is not very detailed. First of all we will discuss arrays.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.4.10. Program flow and interrupts As discussed before, a program will be executed basically instruction after instruction from the top to the bottom. Apart from this standard behaviour, there is flow control with conditional jumps, loops and functions. Beneath these usualy things, there are so-called “interrupts”. They may be generated by several hardware modules (Timer, TWI, UART, external Interrupts etc.) and require the microcontrollers's immediate attention.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.4.11. The C-Preprocessor In this chapter we will briefly discuss the C-preprocessor, which has been used in the preceding programming samples already in the line: #include "RP6RobotBaseLib.h"! The preprocessor evaluates this command before starting the GCC-compiling process. The command line #include "file" inserts the contents of the specified file at the include's position. Our example program includes the file RP6BaseLibrary.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.5. Makefiles The “Make”-tool simplifies the compiling process by automatically executing a great number of jobs required to compile a C program. The automated process is defined in a so-called “Makefile”, including all command sequences and informations for the compile process of a project. We provide these makefiles for all RP6 example projects, but of course you may create makefiles for your own projects as well.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.6. The RP6 function library (RP6Library) The RP6 function library (abbr. RP6Library or RP6Lib) provides a great number of lowlevel functions to control the RP6 hardware. With this library, you usually don't have to care about all the hardware specific details of the Robot and the Microcontroller. Of course, you do not need to read the 300 pages long datasheet of the ATMEGA32 Microcontroller in order to be able to write programs for the RP6.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.6.2. UART Functions (serial interface) A few of the RP6Library's functions have been used in the previous C crash course already, such as the UART functions. These functions allow us to transfer text messages through the robot's serial interface to and from the PC (or to another microcontroller). 4.6.2.1. Transmitting data void writeChar(char ch) This function transmits a single 8-Bit ASCII character via the serial interface.
RP6 ROBOT SYSTEM - 4. Programming the RP6 void writeStringLength(char *data, uint8_t length, uint8_t offset); Whenever you need to output text with a predefined length and/or offset, you can use this function. An example: writeStringLength("ABCDEFG", 3, 1); Output: “BCD” writeStringLength("ABCDEFG", 2, 4); Output: “EF” This function however will occupy RAM for these strings as well and has been designed for handling dynamic texts. This function is for example used by writeIntegerLength.
RP6 ROBOT SYSTEM - 4. Programming the RP6 void writeIntegerLength(uint16_t number, uint8_t base, uint8_t length); This function is a variant for writeInteger, enabling you to specify the number of digits (length) to be displayed. If the number's length is below the specified limit, the function will add leading zeros. If the number's length exceeds the specified limit, the function will only display the trailing digits.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.6.3. Delay and timer functions Microcontroller programs often have to be delayed completely for some time, or need to wait a period of time before a specific action is performed. The RP6Library also provides functions for these purposes. It uses one of the MEGA32's timers to achieve relatively accurate delay control, which is independent from other program flow or interrupts which could disturb delay routines.
RP6 ROBOT SYSTEM - 4. Programming the RP6 RP6Library offers an universal module for general purpose usage. Stopwatches allow you to handle a number of tasks “simultaneously” – at least this is what you will see from your point of view outside of the microcontroller. The RP6 provides eight 16bit Stopwatches (Stopwatch1 to Stopwatch8), which may be started, stopped, set and read.
RP6 ROBOT SYSTEM - 4. Programming the RP6 We are using Stopwatch1 and Stopwatch2 here, which get started at lines 9 and 10 respectively. Afterwards the Stopwatch counters are running. The infinite loop (at lines 16 up to 37) constantly checks, whether the Stopwatches exceed a predefined level. The if-condition in line 19 for example controls the running light and checks, whether the stopwatch has been running for at least 100ms since the last reset to zero.
RP6 ROBOT SYSTEM - 4. Programming the RP6 setStopwatchX(uint16_t preset) This macro sets the counter of stopwatch X to a given value. Examples: setStopwatch1(2324); setStopwatch2(0); setStopwatch3(2); setStopwatch4(43456); getStopwatchX() This returns the counter level of stopwatch X. Examples: if(getStopwatch2() > 1000) { ... } if(getStopwatch6() > 12324) { ... } 4.6.4. Status LEDs and Bumpers void setLEDs(uint8_t leds) This function allows you to control the 6 Status LEDs.
RP6 ROBOT SYSTEM - 4. Programming the RP6 The Microcontroller executes these functions very fast and you will not see that the LEDs turn off, although the Pin is set to input for a few instruction cycles. Of course you should not call these functions frequently without a delay of a few ms in between.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Now, as we are performing background tasks anyway, we can run some other (smaller) tasks as well along with the bigger things – such as bumper evaluation. This is a simple and fast task which you would usually perform in the main loop anyway. To automatically check the bumpers you have to call this function: void task_Bumpers(void) frequently from the main loop (s. a. chapter about driving functions, in which we will discuss this in detail).
RP6 ROBOT SYSTEM - 4. Programming the RP6 C allows us to define pointers to functions and call these functions without pre-defining the function in the library. Usually a function needs to be defined in our Library at the time of compilation in order to be callable. This method allows us to use self-defined functions as so-called “Event Handlers”. Pressing down a bumper will automatically result in calling a predefined dedicated function (within 50ms).
RP6 ROBOT SYSTEM - 4. Programming the RP6 The program will react on alterations of the bumper status once-only by outputting the current status of both bumpers. For example, if you press down the right bumper, the output would be: Bumper Status has changed: - Left bumper has not been activated.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.6.5. Read ADC values (Battery, Motorcurrent and Light sensors) There are a lot of sensors connected to the ADC (Analog to Digital Converter), as described in chapter 2. Of course, the RP6Library provides a function to read the measured ADC values: uint16_t readADC(uint8_t channel) This function returns a 10 Bit value (0...1023) and requires a 16 Bit variable for sensor values.
RP6 ROBOT SYSTEM - 4. Programming the RP6 In analogy to the bumper sensors, we may automatically perform ADC measurements and simplify the main program by using a comfortable function: void task_ADC(void) which will shorten the time required to evaluate all ADC channels in a program. Calling this function will subsequentially read all ADC channels in “background mode” (whenever there is some spare time, the measurements are started / read out...) and store the results in predefined variables.
RP6 ROBOT SYSTEM - 4. Programming the RP6 voltage at intervals of 300ms. The program will issue a warning as soon as the battery voltage drops below a level of approximately 6V. 4.6.6. ACS – Anti Collision System In contrast to the CCRP5, which used a small co-processor, the Anti Collision System of the RP6 has been directly implemented on the MEGA32. This architecture needs some more programming effort, but also allows custom modifications and adaptations.
RP6 ROBOT SYSTEM - 4. Programming the RP6 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 #include "RP6RobotBaseLib.
RP6 ROBOT SYSTEM - 4. Programming the RP6 also watch the LEDs. And then just move your hand or an object directly in front of the robot! Several sources of interference are known to affect the ACS! Some types of fluorescent lamps and similar light sources may virtually blind the robot or at least decrease sensitivity. If you encounter such problems you may start by deactivating all possible interfering sources of light.
RP6 ROBOT SYSTEM - 4. Programming the RP6 and robot's expansion boards mounted on the top). You will be able to extend the communication range by adding some more IR LEDs (for example controlled by another MOSFET with a large capacitor and a small series resistor).
RP6 ROBOT SYSTEM - 4. Programming the RP6 By the way: RC5data_t is a special pre-defined datatype, containing the RC5 Device Address, the Toggle Bit the Key code (respectively a data value). You may use these data just like ordinary variables with the following identifiers: rc5data.device, rc5data.toggle_bit, rc5data.key_code The CD provides a sample program that shows how to use this.
RP6 ROBOT SYSTEM - 4. Programming the RP6 gram's loop – otherwise the automatic control will not work! Frequently calling from the main program simply implies to call this function at each and every main loop cycle. Calling the function at intervals of 10 up to 50 milliseconds will be sufficient, but its better to call the function at considerably shorter intervals. Calling the function more frequently will not cause any problems, as a hardware timer is controlling the timing.
RP6 ROBOT SYSTEM - 4. Programming the RP6 void moveAtSpeed(uint8_t desired_speed_left, uint8_t desired_speed_right) This function adjusts the setpoint speed. Both parameters will define the desired speed for the left and right motor. Frequently calling the motionControl function (as described in the previous chapter) results in regulation of the speed to the setpoint values. Setting these values to zero, initiates a slowdown, followed by complete deactivation of the PWM modules.
RP6 ROBOT SYSTEM - 4. Programming the RP6 as 70⋅5=350 counted encoder-segments per second (corresponding to ca. 8 up to 8.7 cm/s – depending on the real encoder resolution). The minimal controllable rotational speed is around 10⋅5=50 and the maximal rotational speed is approximately 200⋅5=1000 .
RP6 ROBOT SYSTEM - 4. Programming the RP6 In this example program, the RP6 will first drive forwards – which is the default setting for movements after a reset. We are using one of the stopwatches to wait 4 seconds and then the direction is reversed. In line 16 and 18 the current rotational direction is determined and changed accordingly. This repeats at intervals of 4 seconds, which will cause the robot to drive forwards and backwards the whole time.
RP6 ROBOT SYSTEM - 4. Programming the RP6 The function: uint8_t isMovementComplete(void) can be used to check if movement-commands are completed. If there are unfinished movement-commands, the return value will be “false”. Whenever a move-command has to be aborted, e.g. at detection of an obstacle, you can terminate all movements by calling: void stop(void) which will stop all movements.
RP6 ROBOT SYSTEM - 4. Programming the RP6 In order to perform such sequential processes, we always have to set the blockingparameter to true! You may even perform rudimentary reaction on obstacles with the blocking-parameters set to true – by using event handlers. These event handlers will be called anyway, no matter if the blocking parameter is set true! However this method may fail in more complex situations.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.6.11. I²C Bus Functions At the end of this chapter we will focus on the I²C-Bus functions, which can be used for communication with other Microcontrollers and expansion modules. There are two versions of I²C-Bus functions – one for slave and another one for master mode. Attention: You can not use both versions simultaneously! You may include one of both versions only and you need to make sure that they are listed in the makefile.
RP6 ROBOT SYSTEM - 4. Programming the RP6 The arrays and the variable for general calls are called: I2CTWI_readRegisters, I2CTWI_writeRegisters and I2CTWI_genCallCMD The readable registers are named I2CTWI_readRegisters and the writeable registers I2CTWI_writeRegisters. The I2CTWI_genCallCMD variable stores the most recently received General Call command. Data exchange in slave mode works completely with these registers.
RP6 ROBOT SYSTEM - 4. Programming the RP6 This example shows how a very simple slave program could look like: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 #include "RP6RobotBaseLib.h" #include "RP6I2CslaveTWI.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.6.11.2. I²C Master In Master mode, the ATMEGA32's TWI module can be used to control other devices/Microcontrollers/sensors through the I²C Bus. void I2CTWI_initMaster(FREQ) This function initializes the TWI module as master. Of course the Master mode does not require an address – but we have to specify the data transmission frequency for the TWI module. You have to define the frequency in kHz by using the parameter FREQ.
RP6 ROBOT SYSTEM - 4. Programming the RP6 void I2CTWI_transmitBytes(uint8_t targetAdr, uint8_t *msg, uint8_t numberOfBytes) Basically this function will transfer up to 20 Bytes to the specified address. For transferring greater data blocks, you may increase the I2CTWI_BUFFER_SIZE constant in the Header file. In order to specify a register for data transfer you may simply use the first byte of the buffer. Using all these functions is rather simple, e.g.
RP6 ROBOT SYSTEM - 4.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Apart from the requestedDataReady Handler there is an Event Handler for error-processing. Whenever an error occurs in data transfers, e.g. by a non-responding slave, a special Event Handler will be called.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.7. Example Programs The CD / Website contains quite a few short example programs, demonstrating the robot's basic functionality. Most of these examples are quite simple and far away from optimized solutions. You have to consider most of the progrmas as a starting point for your own programs.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 1: “Hello World”-Program featuring a running LED-light Directory: \RP6BaseExamples\Example_01_LEDs\ File: RP6Base_LEDs.c The program will output messages on the serial interface, thus you should connect the robot to your PC and watch the output in the RobotLoader Terminal! The robot does not move in this example program! You may simply put the robot on a table next to your PC.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 3: Question-and-Answer Program Directory: \RP6BaseExamples\Example_02_UART_02\ File: RP6Base_SerialInterface_02.c This program will output messages on the serial interface The robot does not move in this example program! This more complex example is a little question-and-answer dialog, in which the robot will ask four simple questions and you may reply by entering any answer in the terminal.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 6: The Robot is driving in a circle Directory: \RP6BaseExamples\Example_05_Move_01\ File: RP6Base_Move_01.c ATTENTION: The robot will move in this example program! Please remove the cable between the PC and the robot after program upload and put the robot in a big free area! You must provide a free area of at least 1m x 1m or even 2m x 2m.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 9: Excursion – Finite state machines Directory: \RP6BaseExamples\Example_05_Move_04_FSM\ File: RP6Base_Move_04_FSM.c This program will output messages on the serial interface The robot does not move in this example program! For more complex programs, the simple methods we discussed so far may not be sufficient.
RP6 ROBOT SYSTEM - 4. Programming the RP6 To show you the basic principle, this example has been reduced to its essentials. A state machine consists of different states and transitions between them. In our example we have four states: STATE_START and STATE_1 up to 3. We may also visualize the state machine above with the following graph: “S” is the start state.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 10: Finite state machines, Part 2 Directory: \RP6BaseExamples\Example_05_Move_04_FSM2\ File: RP6Base_Move_04_FSM2.c ATTENTION: The robot will move in this example program! Now let's try out an FSM with a moving robot! The program is quite simple. First Status LED 5 is blinking. With this, the Robot wants to tell us: “Would somebody push the left Bumper, please?”.
RP6 ROBOT SYSTEM - 4. Programming the RP6 viour's outputs and forces the system to feed the motor-control with its own commands. Obviously “Escape” has higher priority than “Cruise”. With these two very basic behaviours, the robot will already start to cruise around and explore its' environment. The sensor system simply consists of two sensors for detecting collisions. Of course this is nothing for very complex behaviours.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 13: LDRs – Light sensors Directory: \RP6BaseExamples\Example_06_LightDetection\ File: RP6Base_LightDetection.c This program will output messages on the serial interface The robot does not move in this example program! This sample program demonstrates how to use the two light sensors. In order to indicate which sensor is most intensely illuminated (or whether both sensors are illuminated equally) we use the StatusLEDs.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 15: Remote control by using a universal RC5 IR RC Directory: \RP6BaseExamples\Example_08_TV_REMOTE\ File: RP6Base_TV_REMOTE.c ATTENTION: The robot will move in this example program! This example program enables you to control the robot just like a Remote Controlled Car by using a standard RC5 IR remote control. Compared to standard functionality for most RC-Cars, we added a few extra movements.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 17: I²C Bus Interface – Master Mode Directory: \RP6BaseExamples\Example_I2C_MASTER_02\ File: RP6Base_I2C_MASTER_02.c This program demonstrates how to use the Master Mode of the I²C Bus. Of course you will have to connect a suitable slave device to the I²C Bus before running this program. We added PCF8591 routines to this example program.
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 20: I²C Bus Interface – Slave Mode Directory: \RP6BaseExamples\Example_I2C_SLAVE\ File: RP6Base_I2C_SLAVE.c Initially this program will not perform anything visible from the outside. You will have to add an expansion module to the robot, which takes over control and acts as I²C master. It makes sense to equip the robot with several additional Microcontrollers.
RP6 ROBOT SYSTEM - 5. Experiment Board 5. Experiment Board There is already an experiment expansion module for assembling your own circuits included in the delivery of the robot (only with the original RP6! Not included with RP6v2!). The module is supplied as a kit. You will have to CORRECTLY insert and solder the connectors by yourself. Pay special attention to the correct polarity - check the PCB's white silkscreen printing.
RP6 ROBOT SYSTEM - 6. Closing words 6. Closing words Here, this small introduction to the world of robotics ends. We hope you enjoyed all activities with the RP6 so far! All beginnings are difficult, especially this complex topic, but once you mastered the first hurdles, you will have a lot of fun with robotics and you will easily learn a lot. As soon as you got familar with C-programming, you may start your own interesting projects.
RP6 ROBOT SYSTEM - APPENDIX APPENDIX A - Troubleshooting This appendix lists a number of problems and possible causes, solutions and/or suggestions how to avoid problems. The list may be extended and updated from time to time! 1.
RP6 ROBOT SYSTEM - APPENDIX 3. While moving, the robot repeatedly generates resets and halts the program! ● The batteries do not provide the system with enough power! ● The batteries are malfunctioning (poor quality or too old) and causing voltage drops during operations, which will automatically result in a reset.
RP6 ROBOT SYSTEM - APPENDIX 6. The robot generates strange noises when moving! ● Strange noises may have several reasons. You will have to open the robot to check the gears and motors. The power cables may have moved into the gearing system? Just a few rattling noises are quite normal and will not cause problems! At high speeds the robot certainly will generate more noise (but definitely not reach the extreme sound levels of the old predecessor CCRP5-system).
RP6 ROBOT SYSTEM - APPENDIX 7. With every program, the motors just accelerate very shortly up to a high speed, and then immediately stop. Subsequently four red LEDs start blinking! ● The simplest possibility: You loaded a self-written or modified example program to the robot and forgot to execute “powerON();” before starting the motors! ● Did you modify the software (especially the library) in any way? Try some other programs and the self-test program.
RP6 ROBOT SYSTEM - APPENDIX 8.
RP6 ROBOT SYSTEM - APPENDIX 9. My battery charger does not charge the batteries inside the robot! ● Did you correctly connect the battery charger? Check polarities of cables, and plugs. ● Did you correctly insert the batteries? Check for defective or loose contacts. Check polarities of cables, plugs and batteries.
RP6 ROBOT SYSTEM - APPENDIX 12. The robot fails to exactly turn a specific angle. ● This is normal behaviour and the manual already explained the reasons for these deviations! Caterpillar drive units will always cause deviations by slipping and sliding. Also the Encoders have to be calibrated in order to work as intended. See appendix B for more details. 13. Why does even an extremely short program occupy 7 KB of memory? ● Each program always includes the RP6Library, which will occupy over 6.
RP6 ROBOT SYSTEM ● APPENDIX Usual beginner mistakes are: ■ Adding a semicolon at the wrong location – e.g. closing a loop or an if-statement. Often you are allowed to insert a semicolon-symbol there, but it will not work as you may have intended! ■ Providing if/else-constructs with accolades at wrong positions – this may easily happen if your program's indentation structure is bad. ■ Using incorrect data types for variables – e.g.
RP6 ROBOT SYSTEM - APPENDIX B – Encoder calibration The effective encoder's resolution er. The caterpillar's rubber tracks self. Additionally, manufacturing compensate for these deviations calibrate the encoder resolution. depends on the real wheel and rubber track diametget pressed into the surface or get impressed themtolerances cause variations in diameter sizes.
RP6 ROBOT SYSTEM - APPENDIX Improved methods for distance- and positioning-measurements Encoder measurements will never get 100% accurant. If you need better navigation, you will have to use additional sensors. For example, the University of Michigan in the USA designed a tiny trailer carrying the encoder sensors for one of their big caterpillar-robots. The robot pulls the trailer, which has been connected by a pivotable metallic rod.
RP6 ROBOT SYSTEM - APPENDIX C – Connector pinouts This overviews provides you with the most important connector pinouts on the mainboard. Additionally we extended the list by a number of details for usage. For the sake of completeness we start by defining the connector pin assignments for the expansion connector once again (s. chapter 2): At the main-board pin 1 is located at the side of the whitecoloured labels XBUS1 and XBUS2, respectively, or at the label “1” next to the plug.
RP6 ROBOT SYSTEM - APPENDIX Make sure that you check if your Hardware uses the correct voltage levels. It must be 5V TTL – if it is standard RS232 then it will be +-12V which could damage the pins. In this case you need a RS232 level shifter like the MAX232 or similar. In the same way you have to use a proper 3.3V level shifter if you use low voltage devices. If you want to use the Bootloader you have to connect MRESET to the RTS pin. The other pins are usually not required.
RP6 ROBOT SYSTEM - APPENDIX New Connectors on the RP6v2 The RP6v2 has several additional connectors. Close to the voltage regulator IC1 there are two 4 pin +5V power connectors, which are ideal to supply large loads (Servos, LED spots or similar). There is also a 3 pin connector for +UB (unregulated battery voltage). The pinout is directly printed onto the PCB. Right next to these connectors you find a 5 pin header for the I2C Bus and supply voltage.
RP6 ROBOT SYSTEM - APPENDIX D – Recycling and Safety instructions Recycling Disposal of the RP6 in domestic waste is not allowed! For disposal, the robot must be delivered to the local recycling centre or any other recycling centre for electronics! Please ask you local sales contact for details.