A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

29
A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University

Transcript of A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Page 1: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

A DC-Motor Micromouse

Dr. Tony Wilcox Technology Innovation Centre

Birmingham City University

Page 2: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Micromouse at TIC

Micromouse at TIC evolved as a mechanism to enthuse and engage students more fully in the practical aspects of designing real-time embedded systems.

Traditionally, Embedded Systems has been taught using static target boards – flashing LEDs, reading sensors, “traffic-light” controllers etc., and little else.

Mobile robots bring in motor drives, positional encoders, real-time systems, closed-loop control theory, and most importantly of all, real-world problems.

Mobile Robots becomes “Electronics on Wheels”

Page 3: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Key mouse components

• Mechanics: chassis, drive system, motors, wheels

• Power supply: batteries, regulators, charger

• Power electronics: H-bridge for DC or Stepper motor drive

• Sensors and signal conditioning electronics for sensing walls

• Encoders for position, speed, acceleration measurement and control

• Comms interface for programming and/or debugging

• A controller: microprocessor, microcontroller, or custom logic

There are many elements that must come together in a mouse build.

Page 4: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Software

• Speed and Position measurement: multi-source interrupts

• Motor Speed and Positional control : P, PD or PID

• Mouse Position/Velocity/Acceleration profiling

• Rotational/Traction Control :additional sensors - accelerometers, gyros

• Orthogonal tracking: in-place turns (rotation), smooth turns – 90,180 degrees

• Diagonal tracking: 45, 90,135,180 degree in-place and smooth turns

• Maze Mapping: multi-sensor data acquisition and analysis

• Maze Solving: Flooding algorithms

For real-time software applications look no further ....

Page 5: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

HEREtic: A low cost DC mouse

The key objectives were that it would:

• have sufficient capability to be a micromouse wall-follower and maze-solver

• be able to function in other non-micromouse environments (long-range sensors, rf links)

• provide a reference design for a new influx of mouse-builders.

The aim of HEREtic was to develop a low-cost, DC motor driven, autonomous mobile robot that would be a versatile educational tool, as well as a competitive maze solver.

Page 6: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Mechanics

• Compact chassis 75mm wide by 130mm long (diagonals?)

• PCB used as structural element i.e. the chassis (cost)

• ‘Wheelchair’ drive – 2 motors, 2 wheels independently driven

• Spur and Pinion gearing for higher torque, lower speed, ‘controllability’

• Low cost DC motors (VCR)

• Sensors at 30, 60, 120, 150, 210, 240, 300, 330 degrees

• 43mm wheels with ‘O’ ring tyres

• Laser-printed encoder disk direct mounted on motor shaft

• Front and rear skids to minimise rocking

The mechanical design and build is usually the stumbling block ...

Page 7: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Design and Build• Designed using a 3D CAD package

– forces an assessment of all mechanical aspects

– reduces conflicts/errors in component placement

– can produce a 2D drawing for import as a mechanical layer on PCB, reducing electronic/mechanical component conflicts.

– simplifies positioning of fixing holes, cutouts, pillars etc.

• Machining kept to a minimum

– used COTS aluminium angle for motor mounts

– used COTS gears, nylon washers

– Laser-printed acetate encoder disks

– Stub axle machined from mild steel rod, but can be made from COTS tube plus bolts.

Page 8: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Base Assembly

Page 9: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

HEREtic model

Page 10: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Electronics

• 8 IR phototransistors , 8 matching IR emitters

• 2 additional IR emitters at 0,180 degrees for ranging with forward/reverse facing sensors

• 2 - I2C sensor ports at 0,180 degrees for long-distance ranging using ultrasonic sensors or triangulation IR sensors.

• All IR phototransistors multiplexed through one signal conditioning circuit – giving good channel matching, ambient cancellation and sample-and-hold.

• Low cost L293 dual H-Bridge motor driver.

• PLD used to enable either locked-antiphase or sign-magnitude pwm.

• RF and wired RS232 comms.

• ICD connection for debugging.

Plenty of room to show your elegance here – or not ......

Page 11: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Base-board schematic

Page 12: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Top-board schematic

Page 13: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Base PCB with overlay

Page 14: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Top PCB with overlay

Page 15: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

HEREtic prototype

Page 16: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Development Tools

• Protel and Orcad for PCB design and circuit simulation

• Solidworks for 3D/2D CAD

• Coreldraw for the encoder disks

• Quartus II and WARP to simulate and synthesise VHDL for the PLD

• MPLAB IDE with MCC18 compiler

• MPSIM source-level code simulation

• ICD2 and wired-RS232 for debug on the bench

• RF link for ‘run-time’ RS232 debug

A selection of development tools used for HEREtic.

Page 17: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

OK, so we’ve got hardware...

• Real-time measurements: wheel speed and position, wall sensors, battery voltage etc.

• Real-time motor control using appropriate sensor feedback

• Navigation algorithms

• Mapping algorithms

• Solving algorithms

• User interface (RS232 radio link, on-board LCD, LEDs)

Embedded microprocessor systems need software to function - some key software elements are:

Page 18: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

DC motor control

MOTOR

MOTOR

CONTROLLER

DRIVER

DRIVER

SENSOR

SENSOR

The wheels are independently driven, though most often the motors share the same controller.

Skids or castors on the front and rear limit rocking.

DC motors need a gear-train to reduce speed and improve torque

A typical micromouse motor-wheel arrangement is the ‘wheelchair’ drive.

Page 19: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

The control loop

The error between desired and actual is calculated, and the value of the error determines the drive applied to the motor.

GAIN MOTOR

SENSOR

SET

MEASURED

e = error R=drive OUTPUT+-

GAIN MOTOR

SENSOR

SET

MEASURED

e = error R=drive

OUTPUT+-

A block diagram can be used to represent the control loop implemented by the controller.

Duplicate the control loop for the other motor.

Page 20: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Straight line?

One would think that the system discussed would follow a perfectstraight line.

MOTOR

MOTOR

CONTROLLER

DRIVER

DRIVER

This is due to slight difference between the drive-trains, and to an imperfect control system limited by what is termed the ‘steady state error’.

It doesn’t !

Page 21: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Proportional Control

If the GAIN is a constant, K, then we have:

R = drive

e = error

R(t) = K * e(t)

The drive is linearly proportional to the error, and so this is termed proportional control.

R(t) = Kp * e(t) where Kp is the proportional gain of the controller

Page 22: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Steady State Error

k=0.2

k=0.4

k=0.6

SET

Time

We will always have a steady state error with a proportional controller

R(t) = Kp * e(t) or the discrete form Rn = Rn-1 + Kp * (en - en-1)

If the error reduces to zero, there is no drive to the motor, thereforethe error can never be zero.

Steady state errork=0.8

Page 23: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

‘Three-Term’ PID control

P

MOTOR

SENSOR

SET

MEASURED

e R=drive OUTPUTI

D

-+ +

+

+

With these three terms we can ‘tune’ the response of the system,reducing rise time, overshoot, and steady-state error

We can overcome these by the use of three gain terms:

proportional, integral, derivative PID

Simple proportional control has significant limitations –

Page 24: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

The Derivative Term

SET

Time

KpKd

The derivative is the rate of change – adding this term increases the speed of the response, but with the same steady state error.

R(t) = Kp * ( e(t) + Td * de(t)/dt )

Rn = Rn-1 + Kp * (en - en-1) + Kd * (en – 2en-1 + en-2)

Page 25: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

The Integral Term

SET

Time

Kp

Kd

KiZero steady state error

R(t) = Kp * ( e(t) + 1/Ti * ∫e(t)dt + Td * de(t)/dt )

Rn = Rn-1 + Kp * (en - en-1) + Ki * (en + en-1)/2 + Kd * (en – 2en-1 + en-2)

The addition of the integral term sums the error over time, reducing the steady state error to zero

Page 26: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Code example

Control theory is just one of the many areas that must be learned, applied,understood in order to persuade a micromouse to give its all -

void PID (void) { current_error = desired_speed – measured_speed; pwm_duty = pwm_duty

+ KP * (current_error - last_error) + KI * (current_error + last_error)/2 + KD * (current_error - 2*last_error + last_but_one_error); last_but_one_error = last_error; last_error = current_error; }

You might think that the code for a PID loop would be complex and unreadable:

Is it? ............

Most of us get by with hand-waving and reading code examples ....!

Page 27: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Summary : Skills

The design, build, and programming of a micromouse requires multi-disciplinary skills.

It provides the opportunity for :- • an individual student to develop broad technical skills in new areas or• the development of team-working skills amongst a group of

mechanical, electronic, and embedded software students.

( Of course, the same skills will be gained by employees who are encouraged to get involved with micromouse ..... )

Page 28: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

Summary : Skills

• Mechanical design: statics and dynamics

• CAD for chassis, drive train, integration with electronic sub-systems

• Analogue and digital electronic design

• Embedded microprocessor design

• Printed Circuit Board design/ prototyping skills

• Real-time embedded software development for uP, uC, SOC or DSP

• Control system design

A complete Micromouse design demands expertise in :

many components and some mice are available commercially ....!HINT:

Page 29: A DC-Motor Micromouse Dr. Tony Wilcox Technology Innovation Centre Birmingham City University.

What everyone wants ….