Giving Robots Life with the .NET Micro Framework

Post on 24-Mar-2016

75 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

004. Rob Miles. University of Hull rob@robmiles.com twitter.com/RobMiles robmiles.com. Giving Robots Life with the .NET Micro Framework. Agenda. What is the .NET Micro Framework? What can I do with it ? How do I connect Sensors and Interfaces? - PowerPoint PPT Presentation

Transcript

Giving Robots Life with the .NET Micro Framework

004

Rob MilesUniversity of Hullrob@robmiles.comtwitter.com/RobMilesrobmiles.com

• What is the .NET Micro Framework?• What can I do with it?• How do I connect Sensors and

Interfaces?• How can I control a robot with

the .NET Micro Framework?• Grand Finale

Agenda

• You might think of C#, Visual Studio and .NET as tools that you use to create PC applications• Compile and run your programs and run them on

your desktop or laptop• However, there is more to .NET than this• You are probably aware that you can write .NET

applications for your Windows Mobile device• But now you can also target all kinds of

devices

.NET for Multiple Device types

• A version of .NET for tiny devices• Runs a .NET program held in the device

itself• Designed for embedded applications• Lets you create embedded code in C#

• The cheapest platforms are now very affordable

The .NET Micro Framework

Windows

Tablet PC

Notebook PC

The Windows PC

Windows

Tablet PC

Notebook PC

Point of Sale

Medical Devices

ATMS & Kiosks

Machine Control

Industrial Automatio

n

Thin Clients

Embedded Windows

Windows

Tablet PC

Notebook PC

Point of Sale

Medical Devices

ATMS & Kiosks

Machine Control

Industrial Automatio

n

Thin ClientsWindows Mobile

Smartphone Windows MobilePocket PC Phone

Windows Automotive

Zune

VoIP Phones

MobileHandhelds

Set-top Boxes

Windows Embedded CE

Windows

Tablet PC

Notebook PC

WearableDevices

AuxiliaryDisplays

Remote Controls

Sensor Networks

Point of Sale

Medical Devices

ATMS & Kiosks

Machine Control

Industrial Automatio

n

Thin ClientsWindows Mobile

Smartphone Windows MobilePocket PC Phone

Windows Automotive

Zune

VoIP Phones

MobileHandhelds

Set-top Boxes

.NET Micro Framework

Platforms and HardwareWindows Vista Windows XP

EmbeddedWindows CE .NET Micro

FrameworkDevice Features

Connected,PC Class Performance, Accelerated Graphics

Connected,PC Class Performance

Connected, Graphical UI, Server, Browser, RAS DirectX

Connected, Small, Wearable, Graphical UI

Development Visual Studio + C#.NET Framework

Visual Studio + C#.NET Framework

Visual Studio + C#.NET Compact Framework

Visual Studio + C#.NET Micro Framework

Footprint X86 Dual Core, 64 Bit, Multi Processor

X86 X86, MIPS, SH4, ARM, with MMU, 12 MB,Managed Code

ARM 7, ARM 9, No MMU, 250-500KB, Managed Code

Power Mains Mains Low Power Very Low Power

Platforms and HardwareWindows Vista Windows XP

EmbeddedWindows CE .NET Micro

FrameworkDevice Features

Connected,PC Class Performance, Accelerated Graphics

Connected,PC Class Performance

Connected, Graphical UI, Server, Browser, RAS DirectX

Connected, Small, Wearable, Graphical UI

Development Visual Studio + C#.NET Framework

Visual Studio + C#.NET Framework

Visual Studio + C#.NET Compact Framework

Visual Studio + C#.NET Micro Framework

Footprint X86 Dual Core, 64 Bit, Multi Processor

X86 X86, MIPS, SH4, ARM, with MMU, 12 MB,Managed Code

ARM 7, ARM 9, No MMU, 250-500KB, Managed Code

Power Mains Mains Low Power Very Low Power

Platforms and HardwareWindows Vista Windows XP

EmbeddedWindows CE .NET Micro

FrameworkDevice Features

Connected,PC Class Performance, Accelerated Graphics

Connected,PC Class Performance

Connected, Graphical UI, Server, Browser, RAS DirectX

Connected, Small, Wearable, Graphical UI

Development Visual Studio + C#.NET Framework

Visual Studio + C#.NET Framework

Visual Studio + C#.NET Compact Framework

Visual Studio + C#.NET Micro Framework

Footprint X86 Dual Core, 64 Bit, Multi Processor

X86 X86, MIPS, SH4, ARM, with MMU, 12 MB,Managed Code

ARM 7, ARM 9, No MMU, 250-500KB, Managed Code

Power Mains Mains Low Power Very Low Power

.NET Framework on Windows

Services•Description•Discovery•Protocols

UI Controls•HTML•Web

Runtime•Interop•Remoting•Serialization

Design

ConfigurationCache

Session stateSecurity

ImagingDrawing 2D

TextPrinting

DesignADO.NET

SQL ServerCESQL Client

Xslt/XPathXML Document

Reader/writersSerialization

Service processConfiguration

ThreadingDiagnostics

NetIO

ResourcesReflection

SecurityCollections

GlobalizationText

Component model

System.Drawing

System.Windows.FormsSystem.Web

System.Data System.XML

System

.NET Compact Framework

Services•Description•Discovery•Protocols

UI Controls• HTML• Web

Runtime• Interop• Remoting• Serialization

Design

ConfigurationCache

Session stateSecurity

ImagingDrawing 2D

TextPrinting

DesignADO.NET

SQL ServerCESQL Client

Xslt/XPathXML Document

Reader/writersSerialization

Service processConfiguration

ThreadingDiagnostics

NetIO

ResourcesReflection

SecurityCollections

GlobalizationText

Component model

System.Drawing

System.Windows.FormsSystem.Web

System.Data System.XML

System

.NET Micro Framework Services• Description• Discovery• Protocols

UI Controls• HTML• Web

Design

ConfigurationCache

Session stateSecurity

ImagingDrawing 2D

TextPrinting

DesignADO.NET

SQL ServerCESQL Client

Xslt/XPathXML Document

Reader/writersSerialization

Service processConfiguration

ThreadingDiagnostics

NetIO

ResourcesReflection

SecurityCollections

GlobalizationText

Component model

System.Drawing

System.Windows.FormsSystem.Web

System.Data System.XML

System

InteropRuntime

SerializationRemoting

• A device powered by the .NET Micro Framework does not have/need an operating system

• Programs execute directly on the hardware using a "Bootable Run Time System"• Simplifies deployment• Reduces the demands on the target platform

• Programs still have access to many parts of the .NET API• Provided by the run-time system rather than an

operating system

The Missing Operating System

• C# source is compiled to Intermediate Language (MSIL)

• The MSIL is downloaded in a compressed form and interpreted in the Micro Framework device

• As far as the code is concerned it is running inside a standard .NET Assembly

• The program runs as soon as the device is powered up

How it works

• Not all .NET devices support all the components of the full .NET Framework• This is quite sensible given the limitations of the

platforms and the needs of the solutions• However, all the fundamentals of .NET are

present on all of the platforms• And they are used in exactly the same way

in your applications• And there are special purpose libraries

The .NET Framework Scope

• There are many different hardware platforms available

• Some are designed as processor boards that can be incorporated into your own hardware

• Some also have custom libraries for additional hardware abilities

Hardware Platforms

• TinyClr Fez Mini• It is pin compatible

with the Basic Stamp board

• It costs less than $50www.tinyclr.com

Tiny Micro Framework Platform

• Device Solutions Tahoe II • Touch screen• SD card slot• Network connection

www.devicesolutions.net/

Larger Micro Framework Platform

• ChipworkX Development System

• Touch screen• SD card slot• Network connection • USB hosting• MP3 playback www.ghilectronics.com

Fully Loaded Micro Framework Platform

• You also get a highly flexible emulator

• You can configure this to match any hardware platform

• You can also create emulations of hardware devices connected to the platform

Pretend Micro Framework Platform

• The development boards look rather expensive

• You would not base a product on these

• Instead you use them to create a prototype and then just use the processor component in a custom board

Making a Product

• Object based implementation of hardware• Single pins, I2C, Spi, serial, USB (host and client)

• Powerful graphics library with touch and gestures

• Fully networkable, provides DPWS, web server and web client support

• Can be used as the processing component in a custom made hardware solution

Platform Abilities

• Anything from simple embedded controllers to connected data terminals

• If you have an idea for a clever embedded device you now have the perfect platform

• You don’t have to learn another programming language or toolchain

What can the Micro Framework Do?

• Write programs in C# using Visual Studio 2008

• Full debugging support, even inside the device

• Run your program on the real device or the emulator

How do I write programs?

DemoSensor Interfacting

• The lab board lets you connect sensors to the processor

• Each port can be configured in software and its behaviours are exposed via C# objects

The FEZ Micro Lab Board

• The Fez Mini Robot kit puts the Micro Framework device in control of a robot

• The controller board has hard wired connections to the motor

• You can connect other devices as required

A Micro Framework Robot

Fez MiniRobot

DemoMaking a Cowardly Robot

• The sensors are implemented as objects which expose properties and methods

• When an sensor instance is created it is bound to a particular input pin

Robot SensorsFEZ_Pin.AnalogIn DistancePin = FEZ_Pin.AnalogIn.An1;FEZ_Components.DistanceDetector distanceDetector;

distanceDetector = new FEZ_Components.DistanceDetector(DistancePin, FEZ_Components.DistanceDetector.SharpSensorType.GP2D120);

• The program repeatedly looks for objects• When it finds one it moves backwards

Cowardly Codewhile (true){ float distance = distanceDetector.GetDistance_cm(); Debug.Print(distance.ToString()); if (distance < 4) { FEZMini_Robot.MoveRamp(-100, -100, 1); System.Threading.Thread.Sleep(300); FEZMini_Robot.Move(0, 0); } System.Threading.Thread.Sleep(200);}

• Devices are all implemented via objects, just like “ordinary” C# programs

Driving Devicesif (distance > 10) greenLed.TurnOn();else greenLed.ShutOff();

if (distance < 10) redLed.TurnOn();else redLed.ShutOff();

DemoMaking a Cowardly Robot With Lights

• Components can also generate events which are handled using delegates

Hardware EventskillSwitch.ButtonPressEvent += new FEZ_Components.Button.ButtonPressEventHandler(killSwitch_ButtonPressEvent);

...

static void killSwitch_ButtonPressEvent( FEZ_Pin.Interrupt pin, FEZ_Components.Button.ButtonState state){ if (state == FEZ_Components.Button.ButtonState.Pressed) { shutDown(); }}

• It would be useful for the robot to be able to send diagnostic information back to the host

• We can use a thread to do this, as the Micro Framework has full thread support

• This includes support for synchronisation

Threading

DemoControlling a Robot with Windows Phone

• This the architecture for our Windows Phone controlled Micro Framework robot

System Architecture

WindowsPhone

Robot ControlWeb Server

Fez MiniRobot

http Xbee

• The phone talks http to the robot web server

.NET Micro Framework Hosting

WindowsPhone

Robot ControlWeb Server

Fez MiniRobot

http Xbee

• Micro Framework devices can host websites and also implement Web Services

• This includes support for secure sockets

• You already know how to do this, since it is based on the .NET Libraries

Micro Framework Web Support

• The graphics display is based on WPF

• You use the StackPanel class to automatically layout content

Micro Framework Display Library

• The Robot Controller uses a serial port to talk to a wireless modem and send commands to the robot

.NET Micro Framework Interface

WindowsPhone

Robot ControlWeb Server

Fez MiniRobot

http Xbee

• You can create and manage serial data connections exactly as for the desktop versions of .NET

• You can bind events to data arrival

• You can also create emulated serial devices for your test harnesses

Serial Data Support

• The robot receives commands and acts on them• It could also return sensor data to the server

.NET Micro Framework Control

WindowsPhone

Robot ControlWeb Server

Fez MiniRobot

http Xbee

• This shows how we can use Micro Framework devices at a variety of levels in an installation:• Small, headless embedded devices• Rich user interface for controllers• Connected using standard protocols

A Distributed Sensor Network

• .NET Developers can now target embedded systems

• Where it was previously too expensive to think about an embedded solution, you can now begin to build one

• The tools are inexpensive• You don’t need special skills

Changing the Business Rules

• The .NET Framework is now shared source

• You can get obtain a porting kit and put the framework onto any hardware platform you like – for free

• This has huge potential for new platforms

.NET Micro Framework 4.0 Devices

• You can get started for free• Download Visual Studio 2008

Express• You can use other versions of Visual

Studio if you wish• Download the Micro Framework • Then you can create projects and

the emulator

Getting Started

• .NET Micro Framework site: http://www.microsoft.com/netmf• .NET Micro Framework Team Blog: http://blogs.msdn.com/netmfteam/ • Blog with all kinds of stuff: http://www.robmiles.com• Books: Embedded Programming with the Microsoft® .NET Micro Framework

Donald Thompson & Rob Miles, Microsoft Press 2007Expert .NET Micro Framework,

Jens Kühner, Apress 2009

Resources

Q & A

top related