Page 1
RP6v2 99 Washington Street Melrose, MA 02176 Phone 781-665-1400 Toll Free 1-800-517-8431 Visit us at www.TestEquipmentDepot.com...
Page 2
Version RP6v2-BASE-EN-20121221 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 situ- ations! Furthermore the manuals provide important details, which may be unknown to average users.
Contents 1. Introduction ................. 6 1.1. Technical support ..............7 1.2. Scope of delivery - RP6v2 ............7 1.3. The RP6v2 and Expansion possibilities ........8 1.4. Features and technical Data ............ 11 1.5. What can the RP6 do? ............14 1.6.
Page 5
4.1. Configuring the source code Editor .......... 53 4.1.1. Creating menu entries............53 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.
Beginning of 2012 the original RP6 (which was released in 2007) got a small refresh and is now called RP6v2. For simplicity, we still call it RP6 most of the time in the doc - umentation materials. The System itself did not require many changes, so the inten- tion was not to develop a completely new Robot, but only to improve some details.
All software updates, new versions of this manual and further informations will be published on this site. 1.2. Scope of delivery - RP6v2 You should find the following items in your RP6v2 box: Completely assembled Robot ● RP6 USB Interface ●...
RP6 ROBOT SYSTEM - 1. Introduction 1.3. 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.
Page 9
I/O. The most powerful expansion module is the new RP6v2-M256-WIFI which will be re- leased in 2012. Beneath the large ATMEGA2560 (16MHz, 256KB Flash, 8K SRAM) it also contains a 2.4GHz 802.11g WLAN radio module.
Page 10
RP6 ROBOT SYSTEM - 1. Introduction Here we would like to repeat the note about the RP6 Website (this note in section 1.1 has often been overlooked in the past): The CD-ROM can only be updated very rarely (if at all). Software and Documentation Updates can only be found on our Homepage: Before you install any Software from the CD, you should check...
Most of these keywords will be explained in later chapters. Features, components and technical data of the RP6 and RP6v2: ● Powerful Atmel ATMEGA32 8-Bit Microcontroller ◊ Speed 8 MIPS (=8 Million Instructions per Second) at 8MHz clock frequency ◊...
Page 12
◊ Two current sensors providing a measurement range up to ca. 1.8A for each motor. This allows to quickly sense blocked or heavily loaded motors. ◊ MOSFET Drivers have been slightly improved on RP6v2 (lower loss, more robust) ● Two high resolution encoders for speed- and motion-control ◊...
Page 13
◊ Constant current should not get higher than 1A. More than this requires extra cooling! We recommend a maximum constant current value below 800mA. ● Replaceable 3.15A fuse on RP6v2 ● Low standby current of less than 5mA (1mA typ. and ca. 17 up to 40mA in use, of course this depends on system load and activity (LEDs, Sensors etc.).
RP6 ROBOT SYSTEM - 1. Introduction 1.5. 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 ex- actly, is up to you and your creativity to teach the robot how to perform. The attrac- tion of robotics bases on the fascinating process of implementing new ideas or optim- izing and improving excisting things! Of course you may start by simply executing and modifying the prepared sample programs to have a look at the standard features, but...
RP6 ROBOT SYSTEM - 1. Introduction 1.6. Application proposals and ideas The RP6 has been designed with good expansion possibilities. If you equip your RP6 with some additional sensor circuits, you can “teach” your Robot some of the following things (some of the following tasks will turn out to be quite complex and the list is roughly sorted in order of complexity): ●...
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.
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. ●...
Page 18
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.
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.
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”.
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.
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 ac - cidently hits an obstacle.
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 in- terrupters 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.
RP6 ROBOT SYSTEM - 2. The RP6 in detail 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.
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.
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.
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).
Page 28
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 com- mands are being expected. Not providing these lines would force the master device to repeatingly query some specific expansion modules for new data.
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.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup All electric lines from and to the system must be connected before connecting and ap- plying the supply voltage. Unexpected connecting or disconnecting plugs, cables or modules in an operating ro- bot may damage or destroy parts of the system and additional components.
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 ad- ministrator to your system. We suggest that you first read the whole chapter and then sub- sequently follow the instructions step by step! We need to assume, that you have basic knowledge in working with com-...
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 Win dows only ! Linux users may skip this section. WinAVR (pronounced “whenever”) is a package of useful and required tools for soft - ware development with AVR microcontrollers in the C-language.
Page 33
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-”.
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup All relevant installation files for avr-gcc, avr-libc and binutils can be found in the fol- lowing directory: <CD-ROM-Drive>:\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: <CD-ROM-Drive>:\Software\Documentation\avr-libc-user-manual-1.6.7.pdf...
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 in- stalled: >...
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 we do not support this so far).
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 microcontrol - ler with a compatible bootloader). Additionally we implemented a few useful functions, e.g.
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 in- stalling the drivers BEFORE connecting the device for the first time. The CD provides different install programs for the driver.
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 -->...
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 AA batteries which specify a real world capacity of at least 2000mAh (optimal capacity is around 2500mAh). Please do not use standard alkaline batteries, which would turn out to be extremely expensive over time and also cause unnecessary environmental pollution.
Page 42
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup Please take out the black battery holder afterwards (see figure). Make sure that main power switch is in the position “OFF”! The switch lever must point to the direction of the text “OFF”...
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 main- board, chassis and gear-wheels! Now you may fix the main board by tightening the four screws –...
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup user program to execute anyway. Standby mode may be terminated via the USB In- terface, 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.
Page 45
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 standard comports labelled “/dev/ttyS0”, “/dev/ttyS1” will be shown as well. The RobotLoader remembers the previously selected port and will automatically pre- select this port at program start (most of the presets and selections are remembered).
Page 46
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup 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.
Page 47
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup knowledged 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...).
Page 48
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup botLoader has shown the battery voltage before. The battery check is now repeated to complete the list: ##################################################################### ##################################################################### ## Test #3 ## ### Voltage Sensor Test ### Be sure that you are using good accumulators! Enter "x"...
Page 49
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup the robot into bright sunlight, measurement values may rise to over 1000. In a rather dark room, values should be below 100. Start the test by typing 'x' + Enter: ## Test #5 ## ### Light Sensor Test ### Please get yourself a small flashlight! While the test runs, move it in front of the Robot...
Page 50
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup cedure 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 re- flecting objects or a ceiling the system may eventually fail –...
Page 51
RP6 ROBOT SYSTEM - 3. Hardware and Software Setup 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 - 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.
Page 54
RP6 ROBOT SYSTEM - 4. Programming the RP6 You are now entering the options dialog, which allows 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 ap-...
Page 55
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 sim- plifies starting the compiler from Windows Explorer.
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. You may directly Copy & Paste ([CTRL]+ [C] = copy, [CTRL]+[V] = paste/insert) them into the dialog-field: int8_t int16_t int32_t int64_t uint8_t uint16_t uint32_t uint64_t Then click “Sort”...
Page 57
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 (fea - turing the previously discussed syntax highlighting) is on the right and and the tool output (in this case the compiler output) is on the bottom.
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”...
Page 59
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”...
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 + .noinit) This indicates that our program occupies 6858 Bytes in memory and reserves 148...
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 lan- guage, which anyone interested in software development should have used at least once.
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.4. C – Crash Course for beginners This chapter only provides a very short introduction to C-pro- gramming, 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.
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.
Page 64
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"...
RP6 ROBOT SYSTEM - 4. Programming the RP6 functions, but is not needed in a microcontroller system. We only need to add this re - turn value to meet the standard C-conventions (and as we will see later, programs for microcontrollers will usually never terminate).
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.
Page 67
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 num- bers.
RP6 ROBOT SYSTEM - 4. Programming the RP6 z++; // abbreviation for z = z + 1; which implies z is now 9 z++; // z = 10 // z++ is called “incrementing z” z++; // z = 11 ... z--;...
Page 69
RP6 ROBOT SYSTEM - 4. Programming the RP6 One more example: 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");...
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: uint8_t i = 0; while(i < 10) // as long as i is less than 10... // ...
RP6 ROBOT SYSTEM - 4. Programming the RP6 You may simply build endless loops with while- or for-loops: while(true) { } 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).
Page 73
RP6 ROBOT SYSTEM - 4. Programming the RP6 Let's explain the idea in a small example with two simple functions and the alerady known main-function: void someLittleFunction(void) writeString("[Function 1]\n"); void someOtherFunction(void) writeString("[Function 2 – something different]\n"); main(void) // Always start an RP6-program by calling this function! initRobotBase();...
Page 74
RP6 ROBOT SYSTEM - 4. Programming the RP6 An example will demonstrate the basic idea: void outputSomething(uint8_t something) writeString("[The following value was passed to this function: "); writeInteger(something, DEC); writeString("]\n"); uint8_t calculate(uint8_t param1, uint8_t param2) writeString("[CALC]\n"); return (param1 + param2); main(void) initRobotBase();...
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 re - maining sections of this crash course we describe only a few examples and concepts in a short overview, which of course is not very detailed.
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.
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 inserts the contents of the specified file at the in- #include "file"...
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 com- pile process of a project.
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 low- level 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.
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 mes- sages through the robot's serial interface to and from the PC (or to another microcon- troller).
Page 81
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”...
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 func- tion will add leading zeros.
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.
Page 84
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.
Page 85
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 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() >...
Page 87
RP6 ROBOT SYSTEM - 4. Programming the RP6 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. The LED Portpins should be controlled with the predefined functions only! There are resistors to protect the bumper ports, but if the pins are set to low level output AND a bumper switch is closed at the same time, the port terminal will conduct a bit more...
Page 88
RP6 ROBOT SYSTEM - 4. Programming the RP6 Now, as we are performing background tasks anyway, we can run some other (smal- ler) 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.
Page 89
RP6 ROBOT SYSTEM - 4. Programming the RP6 C allows us to define pointers to functions and call these functions without pre-defin- ing 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”.
Page 90
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 de- scribed in chapter 2. Of course, the RP6Library provides a function to read the meas- ured ADC values: uint16_t readADC(uint8_t channel) This function returns a 10 Bit value (0...1023) and requires a 16 Bit variable for...
Page 92
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”...
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.
Page 94
RP6 ROBOT SYSTEM - 4. Programming the RP6 #include "RP6RobotBaseLib.h" void acsStateChanged(void) writeString_P("The ACS-status has changed! "); if(obstacle_left) // Obstacle on the left writeChar('o'); else writeChar(' writeString_P(" | R: "); if(obstacle_right) // Obstacle on the right writeChar('o'); else writeChar(' if(obstacle_left && obstacle_right) // Obstacle in the middle? writeString_P("...
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.
Page 96
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 anoth- er MOSFET with a large capacitor and a small series resistor). Synchronisation to the ACS operation is controlled by the task_ACS() function, which must be called frequently from the main-loop in order to handle reception of IR-sig- nals –...
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.
Page 98
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.
Page 99
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.
Page 100
RP6 ROBOT SYSTEM - 4. Programming the RP6 counted encoder-segments per second (corresponding to ca. 8 up to 70⋅5=350 8.7 cm/s – depending on the real encoder resolution). The minimal controllable rota- tional speed is around and the maximal rotational speed is approximately 10⋅5=50 200⋅5=1000 .
Page 101
RP6 ROBOT SYSTEM - 4. Programming the RP6 In this example program, the RP6 will first drive forwards – which is the default set- ting for movements after a reset. We are using one of the stopwatches to wait 4 seconds and then the direction is reversed.
Page 102
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 block- ing-parameter 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 mas- ter mode.
Page 105
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 re- ceived General Call command.
Page 106
RP6 ROBOT SYSTEM - 4. Programming the RP6 This example shows how a very simple slave program could look like: #include "RP6RobotBaseLib.h" #include "RP6I2CslaveTWI.h" // Include the I2C Library file (!!!) // ATTENTION: do not forget to add this to the Makefile (!!!) #define CMD_SET_LEDS 3 // LED command, which should be received // through the I2C Bus...
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 –...
Page 108
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 trans- ferring greater data blocks, you may increase the I2CTWI_BUFFER_SIZE constant in the Header file.
Page 109
RP6 ROBOT SYSTEM - 4. Programming the RP6 For example if you would like to read register 22 from a slave device with address 10: I2CTWI_transmitByte(10, 22); uint8_t result = I2CTWI_readByte(10); The following function allows you to read several bytes: void I2CTWI_readBytes(uint8_t targetAdr, uint8_t * messageBuffer, uint8_t numberOfBytes);...
Page 110
RP6 ROBOT SYSTEM - 4. Programming the RP6 Apart from the requestedDataReady Handler there is an Event Handler for error-pro- cessing. Whenever an error occurs in data transfers, e.g. by a non-responding slave, a special Event Handler will be called. It has to be registered with this function: void I2CTWI_setTransmissionErrorHandler(void (*transmissionErrorHandler) (uint8_t)) The handler must have the signature pattern:...
RP6 ROBOT SYSTEM - 4. Programming the RP6 4.7. Example Programs The CD / Website contains quite a few short example programs, demonstrating the ro- bot'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.
Page 112
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 1: “Hello World”-Program featuring a running LED-light Directory: <RP6Examples>\RP6BaseExamples\Example_01_LEDs\ File: RP6Base_LEDs.c The program will output messages on the serial interface, thus you should con- nect 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.
Page 113
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 3: Question-and-Answer Program Directory: <RP6Examples>\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 ter - minal.
Page 114
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 6: The Robot is driving in a circle Directory: <RP6Examples>\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.
Page 115
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 9: Excursion – Finite state machines Directory: <RP6Examples>\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 suf- ficient.
Page 116
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 ex- ample 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”...
Page 117
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 10: Finite state machines, Part 2 Directory: <RP6Examples>\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.
Page 118
RP6 ROBOT SYSTEM - 4. Programming the RP6 viour's outputs and forces the system to feed the motor-control with its own com- mands. 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.
Page 119
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 13: LDRs – Light sensors Directory: <RP6Examples>\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 in - dicate which sensor is most intensely illuminated (or whether both sensors are illu- minated equally) we use the StatusLEDs.
Page 120
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 15: Remote control by using a universal RC5 IR RC Directory: <RP6Examples>\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.
Page 121
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 17: I²C Bus Interface – Master Mode Directory: <RP6Examples>\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.
Page 122
RP6 ROBOT SYSTEM - 4. Programming the RP6 Example 20: I²C Bus Interface – Slave Mode Directory: <RP6Examples>\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.
RP6 ROBOT SYSTEM - 5. Experiment Board 5. Experiment Board There is an experiment expansion module for assembling your own circuits available as a seperate option. The module is supplied as a kit. You will have to CORRECTLY insert and solder the connectors by yourself.
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 with 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 from it.
RP6 ROBOT SYSTEM - APPENDIX APPENDIX A - Troubleshooting This appendix lists a number of problems and possible causes, solutions and/or sug- gestions how to avoid problems. The list may be extended and updated from time to time! 1. The robot can not be powered on – none of the LEDs lights and the ro- bot does not react on the start/stop button! The USB-Interface is connected to the robot, but not to the PC! This connec- ●...
Page 126
RP6 ROBOT SYSTEM - APPENDIX 3. While moving, the robot repeatedly generates resets and halts the pro- gram! The batteries do not provide the system with enough power! ● The batteries are malfunctioning (poor quality or too old) and causing ●...
Page 127
RP6 ROBOT SYSTEM - APPENDIX 5. RobotLoader does not show any Ports! Check if the port is used from another application. The Ports are only shown ● if not used by any other application – use “refresh portlist” menu item to up- date the list.
Page 128
Even if the oil is not damaging the electronic components, the fluid may damage the encoder wheels/stickers, which can soak any flu- ids very well and this will drastically influence reflectivity (the RP6v2 Stickers are a bit more robust, but still should not be oiled at all)! Additionally rotat-...
Page 129
However, deviations and fluctuations between 40 and 60% can be considered as tolerable. Most of the duty cycle values should be in the range of 45 up to 55% for RP6v2. During tests the test-program will deactivate the motor-control and run the engines at a fixed PWM-value. Speed measure- ment values will be shown in encoder counts per 200ms.
Page 130
RP6 ROBOT SYSTEM - APPENDIX 8. The Rubber tracks do not move smoothly / are bent First: A slight assymetrical rotatation is nothing to worry about – especially ● when the track runs freely and is not touching the ground. Though, if this is more severe and causes high variation of the movement speed within a turn, you should check it a bit more in detail.
Page 131
RP6 ROBOT SYSTEM - APPENDIX 9. The Motors could be damaged, how do I check them and how can I re- place them? When the robot is still under warranty, you should contact us beforehand. ● You can check the Motors by removing the gray plastic side covers on the ●...
Page 132
(We advise you to copy the complete terminal's contents to a text-file e.g. by Menu “Options-->Save Terminal”). Replacement of parts has been simplified for RP6v2. The two Motors and En- ● coders now have connectors and can be disconnected from the Mainboard.
Page 133
RP6 ROBOT SYSTEM - APPENDIX 11. 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. ●...
Page 134
RP6 ROBOT SYSTEM - APPENDIX guidelines how to assign keys. Check the output codes in the terminal, which will display the key-codes for the RC5 example program! 14. The robot fails to exactly turn a specific angle. This is normal behaviour and the manual already explained the reasons for ●...
Page 135
RP6 ROBOT SYSTEM - APPENDIX No idea! ;-) You will have to be more specific in describing your problems to ● the support. We often receive questions like “Why is this program malfunc- tioning?”. Dot. Of course, we need a bit more detailled description of what the program is supposed to do at all and what is not working! Otherwise this quickly turns out to be a quiz game...
Page 136
RP6 ROBOT SYSTEM - APPENDIX diately posting a new topic – start by searching for your problem using dif- ferent search queries!). You can also try using a general web search engine. - 136 -...
RP6 ROBOT SYSTEM - APPENDIX B – Encoder calibration The effective encoder's resolution depends on the real wheel and rubber track diamet- er. The caterpillar's rubber tracks get pressed into the surface or get impressed them- self. Additionally, manufacturing tolerances cause variations in diameter sizes. To com- pensate for these deviations we will have to perform some measurements and calib- rate the encoder resolution.
Page 138
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.
RP6 ROBOT SYSTEM - APPENDIX C – Connector pinouts This overviews provides you with the most important connector pinouts on the main- board. Additionally we extended the list by a number of details for usage. For the sake of completeness we start by defining the con- nector pin assignments for the expansion connector once again (s.
Page 140
5V supply voltage. The Pinout is intended for Sharp IR distance Sensors of the GP2Dxxx Series. On the new RP6v2 there is already a 220µF electrolytic capacitor in the power supply line which is required to support the high pulse current that such sensors need.
Page 141
RP6 ROBOT SYSTEM - APPENDIX New Connectors on the RP6v2 The RP6v2 has several additional connectors compared to the original RP6. 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).
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.
Need help?
Do you have a question about the RP6v2 and is the answer not in the manual?
Questions and answers