More On Embedded Systems Mobile Robots and  - Mobile ... - EPFL
More On Embedded Systems Mobile Robots and  - Mobile ... - EPFL
Action
Computation
(controller)
A
Environment
Human-Guided
Task Complexity Robotics
Research
Autonomous
Robotics Industry
Autonomy
y
The e-puck miniature
robot
S l t d andd re-elaborated
Selected l b t d slides
lid from:
f
Microinformatique
q
I t d ti tto th
Introduction the e-puck
k robot
b t
Francesco Mondada
Robotics Systems Laboratory
IMT - STI - EPFL
The ee-puck
puck Mobile Robot
Main features
• Cylindrical, Ø 70mm
• dsPIC processor
• Two
T o stepper motors
• Ring of LEDs
• Many sensors:
9 Camera
9 Sound
9 IR proximity
9 3D accelerometer
• Li-ion accumulator
• Bluetooth wireless communication
• Open hardware (and software)
The e-puck
e puck Open Hardware License
The specifications of the e-puck mobile robot are "open source hardware".
You can redistribute them and/or modify them under the terms of the e-puck
Robot Open Source Hardware License as published by EPFL. You should
have received a copy of the EPFL e-puck Robot Open Source Hardware
Li
License along
l with
ith these
th specifications;
ifi ti if not,
t write
it to
t the
th Ecole
E l
Polytechnique Fédérale de Lausanne (EPFL), Industrial Relations Office,
Station 10, 1015 Lausanne, Switzerland.
These specifications are distributed in the hope that they will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
more details, see the EPFL e-puck Robot Open Source Hardware License.
Mechatronic Hardware
Overview
e-puck Block Schema
Computation
and memory
Communication
Actuators
Sensors
e-puck Overview
Speaker
IR receiver
((remote control))
Reset
Accelerometer
Mode selector
RS232
Programming and Ring of LEDs
debug connector
IR proximity
i i
ON-OFF sensors
microphones
p
CMOS camera
Wheels with
stepper motor Li-Ion accumulator
ee-puck
puck Mechanical Structure
e-puck Electronics
(typical routing report produced by the EPFL PCB workshop)
e-puckk Electronics:
El t i SampleS l Schematics
S h ti
e-puck Electronics: Layout (4 Layers PCB)
inside
PIC/dsPIC Family
from www.microchip.com
Microcontroller
on the
h e-puckk
DSP and Specialized Variants
• dsPIC is a family of chips combining microcontroller and Digital
Signal Processor (DSP) structure and features
ee-puck
puck
microcontroller
Programming
g g Real-Time
Embedded Systems
Embedded systems
Programming embedded systems is all about resource
management, i.e. dealing with delays and time constraints
imposed by the environment and limitations of the hardware
(memory, computation, energy, communication bandwidth).
When pprogramming
g g ((or simply
p y using)
g) an embedded system,
y , yyou
must bear in mind its limitations and find appropriate
techniques for dealing with them.
E
Energy, memory and d computation
t ti are often
ft very limited
li it d andd
precious in real-time embedded system applications.
Often
Often, you need to find the optimal trade
trade-off
off between
computation, memory and communication.
Fortunately, computer and electronic engineers have developed
a lot of useful techniques to perform these trade-offs.
Programming Embedded Systems
Modern embedded systems have increasing
software complexity.
Some applications may be critical and
improper software design can cause real
catastrophes!
Ariane 5 explosion: a 64 bit floating point
number tracking the horizontal velocity of the
rocket was converted to a 16 bit signed integer.
The number was larger than 32,767, the largest
integer storable in a 16 bit signed integer, and
thus the conversion failed:
double h_v = horizontal_velocity();
y()
short int h_v2 = (short int) h_v;
sensors actuators
processing time
analog-digital
Perceptiion
Action
n
conversion time actuator delay
Computation
Sideairbag g in a car: p
perception-
p
to-action delay < 10 mSec
void InitTMR1(void) {
T1CON = 0;
T1CONbits.TCKPS = 0; // prescaler = 256
TMR1 = 0; // clear timer 1 Interrupt set-up and
PR1 = (MILLISEC/18.00); // 18KHz interrupt (T = 55 us)
initialization
IFS0bits.T1IF = 0; // clear interrupt flag
IEC0bits.T1IE = 1; // set interrupt enable bit
T1CONbits TON = 1;
T1CONbits.TON // start Timer1
}
void main() {
// initialize Timer 1
InitTMR1();
21µs 34µs 21µs 34µs 21µs 34µs 21µs 34µs 21µs 34µs
The main loop gets executed, but the only thing it does is to put the
microcontroller in sleep mode.
In sleep mode, timers and hardware interrupts are still active.
Each 55µs, Timer 1 triggers an interrupt, thus wakening the microcontroller.
The task X() gets executed during approximately 21µs.
21µs Then
Then, the
microcontroller can get back to sleep for 34µs.
Wh t if the
What th task
t k X() llasts
t longer
l than
th expected?
t d?
Typical execution scheme
main() sleep sleep sleep sleep sleep sleep
ISR X() X() X() X() X()
21µs 34µs 21µs 34µs 21µs 34µs 31µs 24µs 21µs 34µs
Bonus: the microcontroller sleeps about 60% of the time (in other
words, you can save a lot of energy, depending on the system).
Interrupts: some definitions
Interrupt Service Routine (ISR): simply another program function that gets
executed upon trigger of its associated interrupt.
Interrupt vector: a fixed address that contains the memory address of the ISR
ISR.
Interrupt flag: one bit in a register that indicates whether the interrupt has
been triggered or not.
Interrupt mask: one bit in a register that controls whether the interrupt can be
triggered or not
Non Maskable Interrupt
p ((NMI):
) an interrupt
p that is always
y active.
Asynchronous event: an event that could happen at any time (not necessarily
synchronized with the clock).
Time-triggered
Ti t i d interrupt:
i t t an interrupt
i t t that
th t is
i triggered
ti d by
b a timer
ti in
i a
periodic fashion.
Event-triggered interrupt: an interrupt that is triggered by an (external) event
(
(e.g., user input,
i A/D conversion,
i sensor measurement). )
Microphone on the real e-puck
First, you need a buffer to read the data from the microphone:
#define SAMPLELEN 1840 // for buffer allocation
static int values[SAMPLELEN]; // buffer and index for storing
static int valuesw; // index
void InitTMR1(void) {
T1CON = 0;
T1CONbits.TCKPS = 0; // prescaler = 256
TMR1 = 0; // clear timer 1
PR1 = (MILLISEC/18.00); // 18KHz interrupt (T = 55 us)
IFS0bits.T1IF = 0; // clear interrupt flag
IEC0bits.T1IE = 1; // set interrupt enable bit
T1CONbits.TON = 1; // start Timer1
}
Microphone on the real e-puck
Now, we need to define an Interrupt Service Routine (ISR) that will be
executed each 55µs.
This function is very
y simple;
p ; it performs
p onlyy four operations:
p
First, it clears the interrupt flag so that the interrupt can be triggered again.
Second, it checks whether the buffer is full. If it is the case, it just returns
without doing anything.
anything
Third, it calls the function e_read_ad(int channel) for initiating a new
analog/digital conversion.
Finally, the new value is added to the buffer and the index is incremented.
Note that we use an active waiting loop, which is not really optimal from the
energy/scheduling point of view (see slides before).
A better practice would consist in putting the microcontroller in sleep mode
and using another software interrupt when the buffer is full to waken it and
print the values in the ISR.
Multiple I/O = Multiple tasks
Multiple I/O = Multiple tasks
Read
Sensing accelerometer
Read IR sensors Read camera
Crash Braitenberg
Process image
detection algorithm
Processing
5ms 10ms 300ms
Object recognition and detection
Task A
Task B
Turn LEDs Update wheel
Task C
Act ation
Actuation on motors
Dependency Maximal delay
Scheduling is the key!
Object recognition and detection
Braitenberg
algorithm Read camera
Update wheel
Process image
motors
t
Braitenberg
algorithm
There is
Th i even some
spare time left!
Read Crash Turn LEDs
accelerometer detection on