You are on page 1of 56

Diploma Thesis

Development of a sensor module for a four-legged robot that learns to walk

by

Sonia Mara Seoane Puga

Period: March 2007 - July 2007 Tutor at the University of Applied Sciences Ravensburg-Weingarten: Prof. Dr. rer. nat. Wolfgang Ertel

Declaration
Hereby I declare that this report has never been accepted in substance of any degree. I have composed it myself as a result of my own investigations, except where otherwise stated.

Weingarten, Germany, 31th July 2007

_____________________________________ Sonia Mara Seoane Puga

Acknowledgment
I would like to thank my tutor at the University of Applied Science Ravensburg-Weingarten Prof. Dr. Wolfgang Ertel for his trust and for giving me the opportunity to do my Diploma Thesis at the Robocup laboratory. I would also like to express my gratitude to all the team in the labor especially to Markus Schneider, Joachim Feucht, Christoph Weber, Michel Tokit and Joachim Fessler for their support and helpful advises.

Finally, but not least I express my most sincere gratitude and respect to my family, for their moral and economic support during my studies in Germany, David Perille for his encouragement and support and to all my friends in Weingarten for all the wonderfull moments that we lived together in this time.

Universidad de Vigo

TABLE OF CONTENTS 1 PRECEDENTS. .............................................................................................2 1.1 General Precedents.............................................................................................. 2 1.1.1 3D Walking Robot .......................................................................................... 2 1.1.2 2D Crawling robot .......................................................................................... 3 2 OBJECTIVE AND JUSTIFICATION OF THE PROJECT. ..............................4 2.1 2.2 3 Objective of the project....................................................................................... 4 Justification of the project................................................................................... 4

DESCRIPTION OF THE PROJECT. .............................................................5

3.1 What is Bioloid? ................................................................................................. 5 3.1.1 Hardware and Software................................................................................... 5 3.1.2 Assembling the Robots. .................................................................................. 6 3.1.3 Behavior Control Program............................................................................ 11 3.1.4 Motion Editor................................................................................................ 12 3.2 Sensor Module for Distance Measurement....................................................... 12 3.2.1 Mechanical Design........................................................................................ 14 3.2.1.1 Feedback sensor ME16........................................................................ 14 3.2.1.2 Atmega16 Microcontroller. ................................................................. 15 3.2.1.3 EAGLE- Easily Applicable Graphical Layout Editor. ........................ 17 3.2.2 Microcontroller Software. C Code................................................................ 24 3.2.2.1 Protocol Communication..................................................................... 25 3.2.2.2 Atmega 16 Microcontroller Programming. ......................................... 28 3.2.2.3 Serial COM Port Number to the PC.RS-232 to RS-485...................... 36 3.2.2.4 Flashing to the microcontroller............................................................ 39 3.2.2.5 Ant8 Logic Analyzer ........................................................................... 43 4 5 6 7 8 9 Diploma Thesis Markus Schneider. .............................................................45 4.1 Result of the wheels. ......................................................................................... 46 CONCLUSIONS ..........................................................................................48 FUTURE WORK ..........................................................................................50 LIST OF FIGURES ......................................................................................51 REFERENCES ............................................................................................52 APPENDIX...................................................................................................53

Sonia Maria Seoane Puga

Universidad de Vigo

PRECEDENTS.

1.1

General Precedents. This project is based on the Thesis of Michel Tokic that is explained in these following precedents, that is a short explanation in the next points: 1.1.1 3D Walking Robot

Figure 1.1 Walking Robot

This robot is one example of reinforcement learning applied to a simple hardware walking robot. The robot learns to walk forwards based on odometry feedback.

The robot can perform four different actions involving movement of its frame moving the body up, down, left and right. When the body is on the ground the frame may move forward or backward.

This robot can only move in one dimension (left or right). It can move its frame relating to the body in 3 dimensions (horizontal, vertical, rotation).

Sonia Maria Seoane Puga

Universidad de Vigo

The simulator makes tests of different environments and allows a prediction of the real robots performance. The modular design of the system implements other learning algorithms.

1.1.2 2D Crawling robot

Figure 1.2 Crawling Robot.

In this other robot, Michel Tokic in his Diploma (Appendix [11]) built a robot which consists of an arm with two freedom degrees, a board held by two static feet as well as two wheels in the rear part of the board. There is a wheel Feedback sensor for measuring distance.

Moreover, this other version of the robot can only move in one dimension (backwards and forwards). The arm of this little robot has 2 degrees of freedom, it means it can move up-down and backwards-forwards.

Sonia Maria Seoane Puga

Universidad de Vigo

OBJECTIVE AND JUSTIFICATION OF THE PROJECT.

2.1

Objective of the project.

The aim of this project is a small walking robot. Its researched in the field of artificial intelligence. The goal is that a legged robot learns to walk by itself in different environments.

The main objective is working in -controller programming and hardware design to measure distance of the robot. Microcontrollers of the Atmega 16 family with the IDE AVR Studio and PonyProg2000 software are used. The EAGLE Layout Editor was used for hardware design.

2.2

Justification of the project. The task was, to build a robot and then equipped it with a sensor module,

which can measure the distance of the robot. This sensor module consist of a microcontroller board, which can be connected to two sensors (wheels), this microcontroller was programmed as it was mentioned above is an Atmega16 on which the protocol used by Bioloid was implemented. In addition it was also programmed a simple reinforcement learning algorithm on the robot. The algorithm was made by my college Markus Schneider. Firstly, in collaboration with my college the robot was built only with one leg due to it was much more easy to test several algorithms, to finally built the four legged robot.

Sonia Maria Seoane Puga

Universidad de Vigo

DESCRIPTION OF THE PROJECT.

3.1

What is Bioloid?

The Bioloid Comprehensive Kit from Robotics is based on small serial controlled servos that allow build a lot of different shapes robots.

This Bioloid Kit includes a CM-5 mcu (Atmel ATMega128), 18 AX-12+ serially controlled servo's, 1 AX-S1 Sensor module, Rechargeable battery pack (9.6V), 2 Programming Utilities (freeware), and an assortment of frames, nuts & bolts.

3.1.1 Hardware and Software.

The hardware of the Bioloid consists of three types:

Dynamixel: Works like a joint or a sensor. The AX-12 Dynamixel is an actuator that is used as a moving joint with an angle unit. The AX-S1 Dynamixel is a sensor unit that can measure both, distance and sound.

CM-5 module: The CM-5 module is an Atmel ATMega128 microcontroller. This is the main controller of Bioloid robot. The batteries that are placed here supply power to the connected Dynamixel, which also recharges the battery (9.6V).

Atmega 128 microcontroller is one of the c which has a dual UART or DUART that combines two UARTs.

Sonia Maria Seoane Puga

Universidad de Vigo There are two differentiated software parts provided by the Bioloid Kit:

Behavior Control Programmer: Graphic interface that allows creating sequences through CAD tools. It is used to implement the motion the robot according to the information received through input devices such as sensors AX-12 and AX-S1.

Motion editor: Graphic modular interface that allows to program sequences of events/movements with interchangeable blocks. Motion Editor is a software that helps the creation of robot motions

The Motion Editor could be used to easily generate small blocks of movements. These sequences could then be used within the Behavior Control Program to implement the logic of the robot.

3.1.2 Assembling the Robots. The CM-5 interfaces connected via a TTL Serial Network, the diagram below shows the 3 wire serial network. This serial network is used to connect motors (AX-12) and sensors (AX-S1) The Dynamixel can be connected together with the use of the frame. Also, the frame connects the Dynamixel and the CM-5.

The Dynamixel is controlled using a pc by the CM5 controller:

Sonia Maria Seoane Puga

Universidad de Vigo

Figure3.1 Serial Connection.

Bus Expansion.

Its possible to build any kind of robot. It would be necessary to use 3 additional line bus connectors on the CM-5. In this case we use a bus expansion board, as we can see in the figure below, which is used in wiring.

Figure3.2 Bus Expansion.

Sonia Maria Seoane Puga

Universidad de Vigo

Arrangement of Pins. A small 3-wire cable is used to connect the servos to the controller. It only needs the header on the cable which is connected to the microcontroller.

The figure below shows how the pins on a Dynamixel unit are connected. Two of the connectors inside the Dynamixel are connected pin to pin. This is how it is possible to connect like a chain configuration. Pin1 and Pin 2 are where the power supply wires are connected.

Figure3.3 Pins Connection.

AX-12 Physical and Electrical Characteristics. All standard servos are connected on a 3-wire bus to the Bus expansion as we have mentioned before.

Figure3.4 Wire Connection to the Bus

Sonia Maria Seoane Puga

Universidad de Vigo

Frequently Used Behavior Control Routines. Location Unit. . The ax-12 servos are able to move towards positions in a 300 degrees angle with a resolution of 1024. This means a precision of nearly 0.3 degrees.

Figure3.5 Location Unit

The AX-12 Sensor Module.

Figure3.6 AX-12 Sensor

Sonia Maria Seoane Puga

Universidad de Vigo

The most important features are the communication speed. At 1,000,000 bps, it can send several commands to many servos and get instant results. Most features about it are:

1,000,000 bps communications Speed Full feedback on Position, Speed, Load, Voltage, and Temperature. Can be set to full rotation mode (gear motor mode) Full 300 degree movement in 1024 increments Full control over speed in 1024 increments Full control over max torque in 1024 increments Built-in LED that can be used as a status indicator Automatic shutdown based on voltage, load or temperature Single cable network connections Control 100's of AX-12 with only 2 data ports Synchronized servo movements Servo movement range can be set by the user

Sonia Maria Seoane Puga

10

Universidad de Vigo 3.1.3 Behavior Control Program.

Figure3.7 Behavior Control Program.

The functionality accessible in the Behavior Control Program has a series of commands are introduced in order to allow the programmer to ask for all the functionality of the AX-12, AX-S1 and the CM-5 mcu module, within the CM-5 includes playing motion sequences, external pushbuttons and the CM-5's timer.

Sonia Maria Seoane Puga

11

Universidad de Vigo 3.1.4 Motion Editor.

Figure3.8 Motion Editor

The Motion Editor package allows the user to move the robot motors simply by INC or DEC the number that describes the motors current position.

Motions are built up frame by frame in an animation sequence. This allows quite complicated animations" to be programmed and tested. Once a motion has been defined, it can then be downloaded into the CM-5's FLASH and called from the Behavior Control Program.

3.2

Sensor Module for Distance Measurement. First of all, the aim of the project is to build a sensor being able to measure

the distance when the robot is moving backward and forward. The first try for designing this sensor module was to create a sensor mouse and taking the signal of those encoders. It meant the sensor to have X-Y axis and a distance between 2 points. When this board was built, it was found that the mouse didnt

Sonia Maria Seoane Puga

12

Universidad de Vigo send one clear signal, so it was decided to use the sensor ME-16 that we would connect to a wheel used in Diploma Thesis of Michel Tokic.

It was thought that using this wheel there could be some problems or errors when the robot is moving. In the case of backward and forward there is no problem because it is measurable but it could happen that the robot moves to the right and to the left, but this is either no problem because it means the sensor is sending only noise So, the result of the sensor will be nearly zero and that is no problem, because the used learning algorithm will try to maximize the moved distance Therefore, measurements to the side will just be ignored.

During this project two boards were developed. The first board was used for only one wheel, for a robot with one leg as in the picture below. This first experiment was successful but the real goal was the reinforcement learning with 4 legs.

First, It was used the Atmel evaluation board and a protoboard perforated, very easy to built the entire circuit, the most important problems were with the speed because the robot works to 1,000,000 bps and both microcontroller could not read what the other sent. It was implemented on high speed and there were no problems with packets with some noise.

After that, next tests were try to send the correct signal from the wheel, testing in different surfaces and the result was roughly floor, therefore, It was obtained good results and also small noise.

In this case, we evaluated other reinforcement learning algorithms such as Q-learning and TD-learning. That extends the state space to two dimensions and moves in two-dimensional trajectories, (Up-down and backwards-forwards).

Sonia Maria Seoane Puga

13

Universidad de Vigo

Figure3.9 Robot with one leg

3.2.1 Mechanical Design 3.2.1.1 Feedback sensor ME16

Figure3.10 Sensor ME-16

Sonia Maria Seoane Puga

14

Universidad de Vigo The more emphasized features would be of small size, low cost, quick and easy assembly. Two channel quadrature output with optional index pulse, TTL compatible single ended outputs, resolutions up to 300 counts per revolution (1200 pulses by quadrature), single +5V power supply

It is used an opto-electronic Two Canal Incremental Encoder to measure the locomotion of the robot, the current supply and two signal connections (TTL Signal). To differentiate now whether the wheel moves forwards or backwards, it is used signal administrations already evaluated. It is plugged to the robot board and connected by a 4pin Molex.

One of the administrators is directly connected with the external Interrupt of the microcontroller, to inform by a signal-level which changes when the Encoder Disc has to be moved by itself. The external interrupt will be triggered on rising and falling edges. In the case of forward, both signal administrations have different signal levels. In the other case, both signal administrations have the same signal level

3.2.1.2 Atmega16 Microcontroller.

The first challenge is to select a microcontroller which fits the requirements of this task. To operate the Dynamixel actuators, the main controller must support TTL level half duplex UART.

To take advantage of the high-speed interface of the AX-12 to connect to this bus, a microcontroller that can communicate at 1,000,000 bps is needed.

It is necessary to have the ability to place the transmit lead in a high impedance state when receiving data from the sensor module. Also a power

Sonia Maria Seoane Puga

15

Universidad de Vigo source in the range of 8-12V is used. Due to this an ATMEGA 16 ATMEL is used, it has the required conditions.

In the first board it was used ATmega 16 PDIP but for the last version of the project, it was used the tiny one, ATmega 16 TQFP, for doing it as smaller as possible. The robot is heavy enough and it has neither too much space around it for the board to be fixed.

Figure3.11 Pinout Atmega 16

The real differences in size of both boards can be seen in the picture below.

On the right picture, they are shown bottom and top sides of the second board. It is important to observe the size of the tiny microcontroller in the bottom side of the board with respect to the other board on the left.

This board is a small controller one on which it is possible to build or add different sensors because it has power supply inputs, and it also interrupts inputs of microcontroller. Moreover, it is suited for experiments with optical encoders, infrared sensors, or other ones like ultrasonic.

Sonia Maria Seoane Puga

16

Universidad de Vigo

Figure3.12 Two boards: on the left is the Atmega 16 PDIP board and on the right is the top and bottom of the Atmega 16 TQFP board

3.2.1.3 EAGLE- Easily Applicable Graphical Layout Editor. The Eagle PCB layout software enables to produce a schematic, to turn this schematic into a PCB board, and, optionally, it has an auto router layout the signal traces on the PCB. It has a tutorial which covers a few basics of using the schematic editor and it includes a section on producing user-defined parts.

.Atmega16 PDIP The picture below is the first board done, and it also includes the following schematics .sch file and board .brd file.

Sonia Maria Seoane Puga

17

Universidad de Vigo

Figure3.13 First Sensor board for one leg robot

Schematic .sch In relation with the first board which was done, the only difference between both schematics, it is that ISP interface is not used here. (it will be explained later in the point 4.2.2.4.4),

It is flashed directly by RS232 serial cable from the PC to the Atmel Evaluations board because it is possible to insert the device into the socket, to program it and to take it out easily again and to connect it to the sensor board.

The board uses the ATmega16 microcontroller with a 16 MHz crystal.

The power regulator on the board converts the 9-12V coming from the robot into 5V DC, which is needed by the microcontroller. The bus connector can be plugged for communication among the microcontroller and the Robot.

Sonia Maria Seoane Puga

18

Universidad de Vigo

Figure3.14 Schematic for one leg robot

Sonia Maria Seoane Puga

19

Universidad de Vigo

Board .brd

Figure3.15 Board for one leg Robot

The circuit designed to the robot, consist in the following components, as it can see in the figure 4.14, basically in, microcontroller Atmega 16, power supply 5V, that this voltage is which is supported in it, a 16MHz crystal and 3 State Buffer to communicate the board and the robot that follows RS-485 protocol.

Sonia Maria Seoane Puga

20

Universidad de Vigo

Atmega16 TQFP. Improved and last version

Figure3.16 Second Sensor Board 4 legged robot

This board contains the same components as the first one does, with the difference that here the ISP 10-pin connector is used for programming the device directly on the board circuit serial.

In this case, it is used the same cable connected to the robot to use the same power supply, very useful to take the robot in anywhere connected to the board.

Sonia Maria Seoane Puga

21

Universidad de Vigo

Figure3.17 ISP Serial Interface

Schematic .sch

Sonia Maria Seoane Puga

22

Universidad de Vigo

Figure3.18 Schematic file for second board 4 legged robot

Sonia Maria Seoane Puga

23

Universidad de Vigo

Board .brd

Figure3.19 Board file for second board four legged robot

3.2.2 Microcontroller Software. C Code

In closed collaboration with my college Markus Schneider, the entire program for Serial Communication and Wheels program was created and implemented, the respective comments and the code, are both described in the Appendix.In the next point will be explained.

Sonia Maria Seoane Puga

24

Universidad de Vigo

Besides, all the steps that should be followed for programming the initialization, and the necessary information for writing the Microcontroller Atmega 16 program, are explained in the following points.

3.2.2.1 Protocol Communication. In order to communicate at 1,000,000 bps with a protocol which is half duplex, it would be needed to take together TX and RX and to take TX off line when it was not necessary Moreover, in half duplex UART, all the other devices need to be in input mode while one device is transmitting. The Main Controller that controls the Dynamixel actuators sets the communication direction to the input mode, and only when it is transmitting an Instruction Packet, it changes the direction to the output one.

Communication: In the following system connection, the main controller sends an

instruction packet with the ID set to N, only the Dynamixel unit with this ID value will answer its respective status packet and perform the required instruction. Thus, there is only one ID for each Dynamixel unit or sensor module.

Figure 3.20 Communication

Sonia Maria Seoane Puga

25

Universidad de Vigo

There are two types of packets Instruction Packet (sent from the main controller to the Dynamixel actuators) Status Packet (sent from the Dynamixel actuators to the main controller.)

Instruction Packet The structure of the instruction packet is the following: OxFF 0xFF ID LENGTH INSTRUCTION PARAMETER1 PARAMETER

N CHECK SUM

The meaning of each packet byte definition is the following ones: 0xFF 0xFF The two 0xFF bytes indicate the start of an incoming packet.

ID The unique ID of a Dynamixel unit. There are 254 available ID values, ranging from 0x00 to 0xFD.

Broadcasting ID

ID 0xFE is the Broadcasting ID which indicates all of

the connected Dynamixel units. Packets sent with this ID apply to all Dynamixel units on the network. Thus, packets sent with a broadcasting ID would not return any status packets. LENGTH The length of the packet where its value is Number of

parameters (N) + 2 INSTRUCTION The instruction for the Dynamixel actuator to perform. This is used if more information additionally to the

PARAMETER0N

instruction byte is needed.

Sonia Maria Seoane Puga

26

Universidad de Vigo CHECK SUM following. Check Sum = ~ (ID + Length + Instruction + Parameter1 + ... Parameter N) If the calculated value is larger than 255, the lower byte will be defined as the checksum value. The computation method for the Check Sum is as the

Status Packet (Return Packet) The structure of the status packet is the following: 0xFF 0xFF ID LENGTH ERROR PARAMETER1

PARAMETER2PARAMETER N CHECK SUM The meaning of these parameters is the same than before, only the new parameter is the ERROR: The byte representing errors is sent from the Dynamixel unit. The meaning of each bit is as in the following chart:

Sonia Maria Seoane Puga

27

Universidad de Vigo

Figure3.21 Error Byte

3.2.2.2 Atmega 16 Microcontroller Programming.

UART A universal asynchronous receiver/transmitter, usually UART is a type of "asynchronous receiver/transmitter", computer hardware that translates data between parallel and serial interfaces. Used for serial data telecommunication, a UART converts bytes of data, from asynchronous start-stop bit current represented as binary electrical impulses. From the diagram below, the transmitter and receiver share the UDR (UART Data Register). Actually they only share the UDR address: The UDR register is divided into the transmitter and the receiver register so that received data cannot overwrite data being written into the transmit register. Consequently you cannot read back data you had written into the transmitter register.

Sonia Maria Seoane Puga

28

Universidad de Vigo

As both parts of the UART, the transmitter and the receiver share the Baud Rate Generator and the control registers. The recovery units are used for asynchronous data reception. And the clock generation logic consists of synchronization logic for external clock input used by synchronous Slave operation, and the baud rate generator.

Figure3.22 USART Block Diagram

Baud Rate Generator The UART Baud Rate Generator defines the clock used for transmitting and receiving data via the UART. Unlike the timer clock, which can be prescaled

Sonia Maria Seoane Puga

29

Universidad de Vigo in some steps, the UART clock can be divided so much precisely, resulting errorfree data transfer.

Figure3.23 Clock Generation Logic,

This clock is used by the Data Recovery Logic: It samples the data and therefore filters it a bit, so that few errors are made. While this is received, it takes three samples: The two (or three) equal samples are high and the small one shifted into the Rx Shift register is high as well. If two samples are wrong,

the data in the shift register will be also wrong, but this only happens if the connection is really bad. The baud rate is divided in 8 because of used Double Speed before it is introduced into the Rx/Tx Shift registers. The clock generated by the UART baud rate generator is 8 times higher than the baud rate used for transferring data.

Sonia Maria Seoane Puga

30

Universidad de Vigo The Clock used for shifting in the data, is then divided in 8 (see diagram) and therefore, corresponds to the baud rate. As there is no need to sample data for the Tx shift register, it is directly clocked by the baud rate.

UDR register: This is buffered in received direction, so that a whole received byte can be read while the next one is being shifted in. A transmission is initiated when data is written to UDR. When reading from UDR, the byte shifted in by the receiver part of the UART is read. It is not possible to read back the last byte transmitted.

UBRR register: The UART Baud Rate Register is used to set the clock for the UART shift registers. It is a 16-bit register that allows low baud rates at high CPU speeds.

The formula which is available in the Atmega 16 datasheet:

In The following piece of program the Baud Rate is explained:

Sonia Maria Seoane Puga

31

Universidad de Vigo #define XTAL 16000000UL // crystal (16Mhz)

#define BAUD 1000000UL ..

// Baud Rate (1000000 bps)

UCSRA = (1<<U2X); // enable double speed

UBRRL = XTAL / (BAUD*8L) - 1;

// speed-baud rate

UBRRH = 0;

// load the upper bits

The UART Transmitter The UART transmitter sends data from the AVR to MC5 in the robot at the specified Baud Rate. The transmission is initiated by writing data to UDR. This data is then transferred to the TX shift register when the previously written byte has been shifted out completely. The next byte can now be written to UDR.

When a byte is transferred to the TX shift register, the UDRE flag is set. The UDRE can write the next byte to UDR without making errors in the transmission progress.

When a byte is completely shifted out and no data has been written to UDR by the UDRE, the TXC flag is set.

UCSRA register:

TXC: Transmit Complete; this flag is set when the transmission is completed. It can be used regarding, clearing it in software and polling.

Sonia Maria Seoane Puga

32

Universidad de Vigo UDRE: UART Data Register Empty; this flag is set while the UDR is empty. This condition occurs when a character is transferred from the UDR to the transmit shift register. If the next character is written to UDR now, it will not be transferred to the UDR until the character currently being transferred is completely shifted out. Consequently, the UDRE has to write UDR, UDRE is set upon reset to indicate that the transmitter is ready.

#define SET_TXD_FINISH sbi (UCSRA,TXC)

#define RESET_TXD_FINISH cbi (UCSRA,TXC)

#define CHECK_TXD_FINISH bit_is_set (UCSRA,TXC)

#define TXD_READY

bit_is_set (UCSRA,UDRE)

#define TXD_DATA

UDR

The UART Receiver The UART receiver is basically built up like the transmitter. It uses the same baud rate setting as the transmitter. The data is sampled in the middle of the bit to be received.

UCSRA register:

RXC: Receive Complete; this is the interrupt flag that is set when the UART has completely received a character. It can be clear by software writing 1 on it Also it can be either use it to let the AVR execute the interrupt service routine or to pull it in a loop with interrupts disabled.

Sonia Maria Seoane Puga

33

Universidad de Vigo #define RXD_DATA UDR

Wheels, External Interrupts. Microcontroller ATmega16 has many sources for interrupts. All these interrupts have enable bits which have to be configured to use the individual interrupts. sei ()

There is also a global interrupt enable that must be set for the microcontroller responding to any interrupt source:

sei (); //Enable global Interrupt

Besides, it is necessary to enable which port is used:

DDRD = 0x00; //enable port D DDRD |= (1<<PD1) | (1<<PD4) | (1<<PD5) | (1<<PD6) | (1<<PD7); //port D, bits 2 and 3

DDRB &= ~ (1<<PB0); // port B bit o DDRB &= ~ (1<<PB1); //port B bit 1

MCUCR ( MCU Control and Status Register):

The register MCU Control contains control bits for general MCU functions.

Sonia Maria Seoane Puga

34

Universidad de Vigo

Figure 33.24 Interrupt 1 Sense Control

Figure 3.25 Interrupt 0 Sense Control

MCUCR |= (1<<ISC10) | (1<<ISC00); //interrupts on falling and rising edges

GICR -General Interrupt Control Register

INT1 (External Interrupt Request 1 Enable) If this bit is set, an Interrupt will be released if flank is recognized by the INT1-Pin rising or falling (according to configuration in the MCUCR). The global Enable Interrupt Flag must be also set, of course.

INT0 (External Interrupt Request 0 Enable) If this bit is set, an Interrupt will be released if flank is recognized by the INT0-Pin rising or falling (according to configuration in the MCUCR). The global Enable Interrupt Flag must be also set, of course.

GICR |= (1<<INT0) | (1<<INT1);

Sonia Maria Seoane Puga

35

Universidad de Vigo

GIFR -General Interrupt Flag Register

INTF1 (External Interrupt Flag 1)

This bit will be set if an Interrupt condition, according to the configuration, is recognized by the INT1-Pin. If the global Enable Interrupt Flag is set, the Interrupt routine will become jumped. The Flag will be automatically deleted if the Interrupt routine is finished. INTF0 (External Interrupt Flag 0) This bit will be set if an Interrupt condition, according to the configuration, is recognized by the INT0-Pin. If the global Enable Interrupt Flag is set, the Interrupt routine will become jumped. The Flag will be automatically deleted if the Interrupt routine is finished.

GIFR |= (1<<INTF0) | (1<<INTF1);

3.2.2.3 Serial COM Port Number to the PC.RS-232 to RS-485 The main controller needs to convert its UART signals to the half duplex protocol to control the Dynamixel actuators, because both TxD and RxD cannot be used at the same time, in the case many devices need to be connected to a same bus. Then it is used as a "bridge" between the full duplex data coming from the RS232 used by PC to the half duplex R485 used by the Bioloid components. Such a half duplex system will be often used if many devices are connected to the same bus.

Sonia Maria Seoane Puga

36

Universidad de Vigo

Figure3.26 RS-232 to RS-485

The power is supplied to the Dynamixel actuator from the main controller through Pin 1 and Pin 2 of the connector.

The direction of data signals on the TTL level TxD and RxD depends on the PORTD and bits 5 and 6 level as the following:

When the PIN5 PORTD level is High: the signal TxD is output as Data.

When the PIN5 PORTD level is Low: the signal Data is input as RxD

In the circuit, it means it has to be used a Buffer 3 state 74126N to get send the signal from a RS232 level to a RS485. As it can see in the expanded square below:

Sonia Maria Seoane Puga

37

Universidad de Vigo

Figure3.27 Schematic Buffer 3State

UCSRB register:

RXCIE: Receive Complete Interrupt Enable; if this bit is set, the reception of a byte via the UART will cause an Interrupt if global interrupts are enabled.

TXCIE: Its the same as RXCIE, but will allow a transmission complete Interrupt.

RXEN: Receiver Enable; if this bit is set, the UART receiver will be enabled and the RXD pin will be set up as an input pin connected to the UART. All the previous port settings are now disabled, but not overwritten: Disabling the receiver again will restore the old port settings.

Sonia Maria Seoane Puga

38

Universidad de Vigo TXEN: Transmitter Enable; if this bit is set, the UART transmitter will be enabled and the TXD pin will be set up as an output pin connected to the transmitter. #define RS485_TXD sbi (PORTD, PD5), cbi (PORTD, PD6), cbi (UCSRB, RXCIE)

#define RS485_RXD sbi (PORTD, PD6), cbi (PORTD, PD5), sbi (UCSRB, RXCIE)

3.2.2.4 Flashing to the microcontroller.

Compiling. Programmers Notepad. This software is used to compiler the program (Tools/Make all) and to show if there are any errors. Consequently, it gets the hex file to use it in the Ponyprog software and finally it flashes the program on the microcontroller, as it is explained in the following point.

Sonia Maria Seoane Puga

39

Universidad de Vigo

Figure3.28 Notepad Compiler

Ponyprog 2000. Ponyprog is Serial Device Programmer software to flash the program to the microcontroller.

The first step is to plug the battery in, provided by the robot, and then to connect it to the proper COM port. Therefore, to open the folder with the hex file and select the options Setup/ Interface Setup and choose which port, COM1 or COM2, is necessary. When clicking on Probe, Test OK is got. In the case the Test is failed, it means that there is an error, and that the connection to target board is not correct.

Sonia Maria Seoane Puga

40

Universidad de Vigo

After that, you should select Setup/Calibration to make sure that there is no heavy process running in background and also that this calibration process involves measuring the CPU timing for delay adjustment during programming. Once this is setup, it does not need to be run again on the PC.

Normally, all AVR chips have internal oscillator as default. To use a crystal oscillator, you are required to set the fuse bits from Command > Security and Configuration Bits. The ATMEGA16 default fuses are, the CKSEL0-3 refers as internal oscillator with value 0001.

In this case it is used an external Clock, for Crystal Oscillator the CKSEL0-3 for external oscillator with value 1111.

The last point to keep on is to Write Device, it takes some seconds and the microcontroller will be flashed until it gets at the end Write Successful.

Figure3.29 Ponyprog Window. Fuses for External Oscillator.

Sonia Maria Seoane Puga

41

Universidad de Vigo

Atmel Evaluation Board. The Atmel Evaluations Board consists of a multiplicity of construction elements like To resistance, electrolytic capacitors, condensers, electric rectifiers, Leds, diodes, ICs, tracers, Buzzer and connection sockets, that an easy and fast assembly of the construction units. It is made possible and the best possible clarity is given of the Boards.

Figure3.30 Atmel Evaluation Board

AVR-ISP Upload. Flashing to the microcontroller. After all the last additional hardware and software, it is ready to flash the program to the microcontroller and check if everything is successful and the communication between the sensors module is what was expected.

As it is shown in the picture below it is used ISP Serial Interface which is connected to PC via Serial port for flashing the program. This is the target view of the ISP interface. Vcc and all GND lines should be connected to the header to provide a voltage reference for the programmer.

Sonia Maria Seoane Puga

42

Universidad de Vigo

This enables the programmer to support target voltages from 1.8V to 5V. The programmer runs at 5V and needs a reference voltage from the target to set programming voltage to match it.

This picture below shows the whole assembly connection for flashing:

Figure3.31 Flashing connection

3.2.2.5 Ant8 Logic Analyzer It was used Logic Analyzer Ant8: 8 Channel USB Logic Analyzer. It was quite useful to detect errors on the board and find the solution for that.

The logic acquisition takes a reading in continuous mode, displays it, and then cycles round to take another reading. All acquisition parameters are Sonia Maria Seoane Puga 43

Universidad de Vigo reloaded before each reading so for example, the clock speed can be varied while the logic is in continuous mode.

In continuous mode (Analyzer/Continuous), the software will repeat this sequence indefinitely.

A run may be stopped by clicking the Analyzer/Stop button.

Figure3.32 Ant8 Analyzer

Sonia Maria Seoane Puga

44

Universidad de Vigo

Diploma Thesis Markus Schneider.

This thesis investigates the use of reinforcement learning for legged robots.

The goal is to build a four-legged robot that learns to walk by itself. The robot must be able to learn without a teacher, just in interaction with the environment.

For this purpose some learning algorithms, that matches the requirements of this task, were tested on a one-legged crawling robot. This is more suitable because the runtime of the algorithms is short and the Value function of a 2D state-action space could be displayed human readable.

The learning algorithm for the four-legged robot is Prioritized Sweeping, because it showed excellent results on real hardware.

Prioritized Sweeping (PS) is a reinforcement algorithm that is very suitable for robotic tasks. During the interaction with the environment it builds its own model of the world. After each step, the agent saves the received reward and the successor state to its model.

It is able to combine learning and planning methods. PS is "prioritized" because it updates the most important entries first.

Sonia Maria Seoane Puga

45

Universidad de Vigo

4.1

Result of the wheels. The communication between the new distance sensor and the pc could be

seen in figure below. The transmitted and received packet of the Bioloid communication-protocol is visualized in the black terminal window. Every time the wheel is moved it measures the distance. The program running on the pc has access to this data through the read command.

Figure4.1Test of the communication between sensor board and PC

In the picture below are shown the pieces that form the whole wheel (wheel, support of the wheel and axis):

Sonia Maria Seoane Puga

46

Universidad de Vigo

Figure4.2 Wheel with the encoder

Sonia Maria Seoane Puga

47

Universidad de Vigo

CONCLUSIONS

In this Diploma Thesis, a sensor module for a four-legged robot was developed. Furthermore, the aim of this project was successfully achieved; it was to develop a sensor module, programming a microcontroller in the software area and designing a board in the hardware area. The main advantage of this board is that it is possible to use better sensors to measure the distance like an optical sensor. It is possible to use this board for any sensor because its ready to connect that sensor to each individual output of the microcontroller, interrupt control register and interrupt flag register. The disadvantage of this small board with tiny components is that the microcontroller is not removable when it is burnt; however this is not very probable. At the same time there is an advantage in comparison with the first board built because when the microcontroller is removed several times it is possible that a leg could break.

This picture shows the final work, Four Legged Robot which learns to walk by itself (robot, wheels, encoder and the board).

Sonia Maria Seoane Puga

48

Universidad de Vigo

Figure5.1 Bioloid Four legged Robot

Sonia Maria Seoane Puga

49

Universidad de Vigo

FUTURE WORK

The creation of this board can be focused on the future implementation of new sensor that can be used to get the less heavy weight as possible on the robot, and something else like wireless connection and other new ideas to improve the development of the robot, for example:

Wireless connection: usable to remove both cables, SMPS for battery and serial cable1.

Embedded system: smart computer based on Linux with a Compact Flash card2.

Interface to the Bioloid bus using USB: It is a USB transceiver chip that allows connecting directly the PC to the Bioloid bus3.

Other sensors: It would be a good option to use an infrared sensor such as an infrared pen to measure the distance.

Sensors like ultrasonic, acceleration, liquid level, and optical sensors to get much better accuracy.

Web page of one example of wireless connection:

http://www.robot-electronics.co.uk/datasheets/Easy-Radio%20ER400TRS%201-2.pdf
2

One good example of such embedded system is founded in this following link:

http://gumstix.com/waysmalls.html
3

It could be found this interface for Bioloid in the following link:

http://www.bioloid.info/tiki/tiki-index.php?page=pc+usb

Sonia Maria Seoane Puga

50

Universidad de Vigo

LIST OF FIGURES

Figure 1.1 Walking Robot................................................................................................... 2 Figure 1.2 Crawling Robot. ................................................................................................ 3 Figure 3.1 Serial Connection. ............................................................................................ 7 Figure 3.2 Bus Expansion. .................................................................................................. 7 Figure 3.3 Pins Connection............................................................................................... 8 Figure 3.4 Wire Connection to the Bus ............................................................................. 8 Figure 3.5 Location Unit.................................................................................................... 9 Figure 3.6 AX-12 Sensor .................................................................................................. 10 Figure 3.7 Behavior Control Program. ............................................................................. 11 Figure 3.8 Motion Editor .................................................................................................. 12 Figure 3.9 Robot with one leg........................................................................................... 14 Figure 3.10 Sensor ME-16................................................................................................ 14 Figure 3.11 Pinout Atmega 16 ......................................................................................... 16 Figure 3.12 Two boards: on the left is the atmega 16 PDIP board and on the right is the top and bottom of the Atmega 16 TQFP board......................................................... 17 Figure 3.13 First Sensor board for one leg robot .............................................................. 18 Figure 3.14 Schematic for one leg robot.......................................................................... 19 Figure 3.15 Board for one leg Robot ................................................................................ 20 Figure 3.16 Second Sensor Board 4 legged robot............................................................. 21 Figure 3.17 ISP Serial Interface........................................................................................ 22 Figure 3.18 Schematic file for second board 4 legged robot ............................................ 23 Figure 3.19 Board file for second board four legged robot .............................................. 24 Figure 3.20 Communication ............................................................................................. 26 Figure 3.21 Error Byte ...................................................................................................... 31 Figure 3.22 USART Block Diagram ................................................................................ 32 Figure 3.23 Clock Generation Logic, ............................................................................... 33 Figure 3.24 Interrupt 1 Sense Control............................................................................... 34 Figure 3.25 Interrupt 0 Sense Control............................................................................... 35 Figure 3.26 RS-232 to RS-485.......................................................................................... 37 Figure 3.27 Schematic Buffer 3State ................................................................................ 38 Figure 3.28 Notepad Compiler ......................................................................................... 40 Figure 3.29 Ponyprog Window. Fuses for External Oscillator........................................ 41 Figure 3.30 Atmel Evaluation Board ................................................................................ 42 Figure 3.31 Flashing connection....................................................................................... 43 Figure 3.32 Ant8 Analyzer ............................................................................................... 44 Figure 4.1Test of the communication between sensor board and PC............................... 46 Figure 4.2 Wheel with the encoder ................................................................................... 46 Figure 5.1 Bioloid Four legged Robot .............................................................................. 49

Sonia Maria Seoane Puga

51

Universidad de Vigo

REFERENCES

[1]

8-bit Microcontroller with 16K Bytes In-System Programmable Flash, 2007.

http://www.atmel.com/ http://www.ee.iitb.ac.in/uma/~kartikmohta/tech/avr/ATmega16.pdf [2]


C Programming and the ATmega16 Microcontroller:

http://www2.tech.purdue.edu/ecet/courses/referencematerial/atmel/ [3] AVR projects microcontrollers, 2004-2005 http://www.avrprojects.net


Dynamixel AX-12. Robotis, Dynamixel AX-S. Robotis, Bioloid Users Guide. Robotis, 2006.

[4]

www.robotis.com [5]
Kronos Robotics and Electronics. Components and Connectors.

www.kronosrobotics.com [6]
EAGLE version 4.16r2 (english, Windows),2006. EAGLE tutorial (english),2006.

ftp://ftp.cadsoft.de/eagle/program/4.16r2/tutorial-eng.pdf http://www.cadsoft.de

[7]

Robots/Robot Kits / Humanoid Robot Kits / Bioloid Robot Kits

http://www.trossenrobotics.com/store/p/3186-Kondo-KHR-2HV.aspx

[8]

Technologies Data Sheet ME16.

http://www.pwbruhlatec.com/Produkte/Deutsch/Inhalt/Encoder/Datasheet_ ME16_7_21.pdf

[9]

Markus Schneider. Reinforcement Learning fr Laufroboter. Diploma thesis. HS-Weingarten 2007 Michel Tokit. Entwicklung eines lernenden Laufroboters.Diploma thesis. HS-Weingarten 2006.

[10]

Sonia Maria Seoane Puga

52

Universidad de Vigo

APPENDIX

In the cover of this thesis it is attatched a CD with the following contents: Code of the Wheels Code of the Comunication RS-232 RS-485 Folder of Schematics .sch boath boards Folder of Board .bdr boath boards Electronic copy of this thesis

Sonia Maria Seoane Puga

53

You might also like