introduction to mechatronics - unistra.fr... · lego mindstorms hardware nxt programming with...

63
Introduction to Mechatronics Discover robots with the Lego Mindstorms Loïc Cuvillon, Bernard Bayle Ecole Nationale Supérieure de Physique de Strasbourg Strasbourg University March 30, 2012 Introduction to Mechatronics 1 / 56

Upload: others

Post on 19-Aug-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Introduction to MechatronicsDiscover robots with the Lego Mindstorms

Loïc Cuvillon, Bernard Bayle

Ecole Nationale Supérieure de Physique de StrasbourgStrasbourg University

March 30, 2012

Introduction to Mechatronics 1 / 56

Page 2: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

You are free to copy, to modify, to adapt and distribute this document.Latex sources of this document should be available on the author’s webpage.

LEGO and Mindstorms NXT are trademarks of the LEGO Group, which doesnot sponsor, authorize or endorse this document.

Introduction to Mechatronics 2 / 56

Page 3: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Part I

Hardware and Programming under Linux

Introduction to Mechatronics 3 / 56

Page 4: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 4 / 56

Page 5: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 5 / 56

Page 6: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

References

NXC Programming

[NXC07] J.C. Hansen, NXT Power Programming, Variant Press, 2007

[NXC] J.C Hansen, Not eXactly C Programmer’s Guide,http://bricxcc.sourceforge.net/nbc/

[NXCT] D. Benedettelli. , Programming LEGO NXT Robots using NXC,http://bricxcc.sourceforge.net/nbc/nxcdoc/NXC_tutorial.pdf

NXT Bluetooth and USB communication

[LINXT] Lego Mindstorms NXT brick in Linux via USB,http://sourceforge.net/projects/linxt/

[BLUE] J. Schultz, Lego, Bluetooth and Linux, http://www.cs.uleth.ca/benkoczi/3720/data/NXT_Bluetooth_handout-jeremy.pdf

[NXTLIBC] Lego Mindstorms NXT Bluetooth library in C,http://www.quietearth.us/nxtlibc.htm

Introduction to Mechatronics 6 / 56

Page 7: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

References

LEGO resources and documentation

[LEGO] Bluetooth Developer Kit and Hardware Developer Kit,http://mindstorms.lego.com/eng/Overview/NXTreme.aspx

Introduction to Mechatronics 7 / 56

Page 8: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Overview

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 8 / 56

Page 9: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Overview

Why the Lego Mindstorms?

fun (look back on childhood)

cheap (for the content)and not the least: highly valuable for education

computer sciencescontrol systems theoryrobotics

Introduction to Mechatronics 9 / 56

Page 10: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Overview

Lego Mindstorms Overview

NXT InputsNXT Outputs

Sound Sensor

Touch Sensor

Light Sensor

Servo Motors

Ultrasonic Sensor

with position encoders

(contact switch)

(pressure in dB)(distance in cm)

(light intensity in %)

LCD screen

Buttons

NXT processorwith Bluetooth

Introduction to Mechatronics 10 / 56

Page 11: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Overview

NXT brick

Battery level

NXT brick name(configurable)

USB 2.0 connector

B : ON, invisible

B< : ON, visible

B<> : ON, connected

usb : connected, working

]−[ : connected, not working

On/Enter button

Clear/Go back buttonNavigation buttons

S4S1 S2 S3Sensor port

OUT_A OUT_B OUT_CServo outputs

Loudspeaker

USB indicator

Bluetooth indicator

Introduction to Mechatronics 11 / 56

Page 12: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Overview

NXT brick Menus

On/off

Connections

Visability

Searchto bluetooth device)(search and connect

Motor rotation

Sound dBA

Ultrasonic cm

Sound files

Software File(bytecode executableupload from computer)

(LCD display distance from sensor)

Delete Files

Volume

NXT version(firmware version)

NXT ProgramSettingsBluetoothMy files View (testing)

NXT Program Example :

= "Forward until an object detection, then turn left. Repeat"

NXT files

savedin

Introduction to Mechatronics 12 / 56

Page 13: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Overview

NXT-G (LabView)

advance graphical interface for programming NXT

functional block and control flow

Introduction to Mechatronics 13 / 56

Page 14: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Overview

Some fun NXT Projects

Rubik’s Cube Solverby Daniele Benedettelli

NXTway-GS ENSPS (model by Y.Yamamoto)

Introduction to Mechatronics 14 / 56

Page 15: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXT Brick Hard/Firm-ware

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 15 / 56

Page 16: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXT Brick Hard/Firm-ware

Hardware specification

Introduction to Mechatronics 16 / 56

Page 17: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXT Brick Hard/Firm-ware

LEGO Mindstorms Servo-motor

Encoder wheel andwith optical sensor

Gear train (1:48)

Running_modes

ON: power controlopen loop controlreference: % of the max power

ON & REGULATED:speed regulationuse of position sensor signalsclosed loop with PID controller

ON & BRAKE: electronic braking

OFF: coasting (free motion)

Introduction to Mechatronics 17 / 56

Page 18: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXT Brick Hard/Firm-ware

LEGO Mindstorms Servo-motor driving

O V

9 V

90% duty cycle

O V

9 V10% duty cycle

Power control

PWM (Pulse Width Modulation) ofa 8 kHz signal

90% duty cycle ≈ 8.1 V20% duty cycle ≈ 1.8 V

+Vcc

0V

In2

In2In1

M

In1

+−

In1=High, In2=Low In1=Low, In2=High

+Vcc

0V

In1 In2

In2In1

M+

Direction and braking

H-bridge with DC motorsIN1 IN2 ActionH L ForwardL H ReverseL L Brake

Introduction to Mechatronics 18 / 56

Page 19: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXT Brick Hard/Firm-ware

Electronic braking

e

i

U

R

Lτ = Ki

ω = Ke

e : back e.m.f

τ : motor torque

ω : motor angular speed

Braking

1 motor motion: e 6= 02 short circuit current i ≃ − e

R

→ τ in opposition

Introduction to Mechatronics 19 / 56

Page 20: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXT Brick Hard/Firm-ware

Hardware specification

I2C: Inter-IntegratedCommunicationuse 3 lines (data,clock,ground)

UART: Universal AsynchronousReceiver Transmitter(serial line/port)

Note:

each sensor port (S1-4) can beused with digital or analog sensor.

6 wires by port: 3 for I2C + 3 foranalog signals

Introduction to Mechatronics 20 / 56

Page 21: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXT Brick Hard/Firm-ware

NXT Firmware

Processor

Boot loader/boot code

LEGO firmwarewith CodeByte interpreter

Executables (.rxe)

HARD

SOFT

Boot code/loader

initialization of the hardware

load the firmware

Firmware : a basic operating system

multi-thread (thread: light task)

provides an API for I/O

(displays the menus)

interprets ByteCode executables(.rxe)

firmware and files stored inFLASH memory

Introduction to Mechatronics 21 / 56

Page 22: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 22 / 56

Page 23: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NBC/NXC basics

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 23 / 56

Page 24: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NBC/NXC basics

NBC/NXC

NBC: Next Byte Codes

name of an assembly language

name of an open source assembler available under MPL license

produces executable bytecode for the native LEGO firmware

NXC: Not eXactly C

high level programming language: C-like syntax

compiler built upon nbc

produces ByteCode executables (.rxe)

NBC and NXC available for Linux, MAC OS, Windows

but custom Firmwares to replace LEGO firmwares are available : LeJOS(JAVA-VM) for Java programming

Introduction to Mechatronics 24 / 56

Page 25: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NBC/NXC basics

Compilation and Execution

Compilation under linux

nbc compiler available from [NXC]

options of nbc available with ”nbc -help”

compilation of a source file *.nxc

nbc toto.nxc -O=toto.rxe

Execution

toto.rxe available in NXT’s Program Files folder after upload

brick buttons used to start/stop the progam

3−Upload of .rxe file

USB cable

1−Source editing

2−Compilation

4−Execution

Cross−compilation process

Introduction to Mechatronics 25 / 56

Page 26: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NBC/NXC basics

USB Upload

Detection of the NXT brick

”lsusb”: listing of connected USB device

Bus 002 Device 004: ID 0694:0002 Lego Group

via NXC

need configuration of the linux device manager (udev)http://www.krizka.net/2009/12/27/

starting-mindstorm-nxt-2-0-development-on-linux/

compilation and upload in one command:

nbc -d toto.nxc

Introduction to Mechatronics 26 / 56

Page 27: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NBC/NXC basics

USB Upload

via NeXTTool

executable with a lot of options

... like upload, get NXT information, read sensors, play tone

to get help ”NeXTTool -h”

to upload a file :

NeXTTool /COM=usb -download=toto.rxe

Introduction to Mechatronics 27 / 56

Page 28: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC structure and statements

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 28 / 56

Page 29: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC structure and statements

Statements 1

comments:

//This is a comment/*This is a comment*/

variablesbool, byte, unsigned char, char 8 bit

unsigned int, short, int 16 bitunsigned long, long 32bit

string Array of bytestruct User defineArrays Array of any type

declaration of variable

int i;int x=0x10; // 16 in hexadecimalint y=10; // 10string msg=’’toto’’;

Introduction to Mechatronics 29 / 56

Page 30: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC structure and statements

Statements 2

assignment

x=y+2;x+=y; // equivalent to x=x+y;

arrays (no pointers)

byte myvector[2]; // 2 byte arrayint myarray[]; // int array (no dimension)ArrayInit(myarray,0,10); // alocation of 10 null entriesmyarray[0]= 15;

conditions= equal!= not equal

truefalse

Expr True if Expr!=0&& logical AND between conditions|| logical OR between conditions

Introduction to Mechatronics 30 / 56

Page 31: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC structure and statements

Control structures

if, if . . . else

if (x==1){x=2; z=3;}elsey=4;

for

for (i=1; i<10; i++){

;}

while

while (x<10){x++ ; // something needed !!}

do.. while

do{ x++ ;}

while (x<10)

Introduction to Mechatronics 31 / 56

Page 32: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC structure and statements

Control structures

switch

switch (x){case 1 :z=3;break;

case 2 :// some codebreak;

default:// some codebreak;

}

repeat and until control structure available but not C standard

Introduction to Mechatronics 32 / 56

Page 33: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC structure and statements

Program structure: Tasks

task music (){ PlayTone(440,3000); }

task motion (){while(true)

{ OnFwd(OUT_A,50);Wait(1000); }

}

task main (){ // motionstart music; //and musicstart motion; //in parallel

} // execution

multithreading in NXT=concurrent execution of tasks

number of task and function mustbe < 256

at least an init task called ”main”needed

API

precedes(task1,task2,..);launch the task after end of main

start task1 or StartTask(task1) ;

StopAllTasks();

Introduction to Mechatronics 33 / 56

Page 34: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC structure and statements

Program structure: Functions

parameter passed by value

return for non-void function

void foo (int x){x++;}

task main{int y=1;foo(y);

//y still equal to 1}

parameter passed by reference

void foo (int &x) // !!{x++;}

task main{

int y=1;foo(y); //y now equal to 2foo(2); // ERROR (not a variable)

}

Introduction to Mechatronics 34 / 56

Page 35: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC structure and statements

Preprocessor

Preprocessor directive

include files

#include ’’foo.h’’#include <foo.h> //error no libray path

macro and define (recommended!)

#define TIMEOUT 200 //0.2 ms timeout#define NORMAL_SPEED 50

Introduction to Mechatronics 35 / 56

Page 36: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 36 / 56

Page 37: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

some functions of the API

Timings

wait(2000);// sleep for 2s

x=CurrentTick();// sys time in ms

Math Functions

-Cos, Sin, Abs, Acos in degree-returns 100 times the value

x=cos(60); //returns 50

Strings

msg=numToStr(i)// convert number in string

msg=StrCat(str1,str2)// concatenation

Sound

PlayTone (440,500);//440: frequency//500: duration

Introduction to Mechatronics 37 / 56

Page 38: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

LCD API

task main (){int i=1;TextOut(0,LCD_LINE1,"toto:");

// display toto on line 1NumOut(20,LCD_LINE1,i);

//display i on line 1 and column 20Wait(3000);ClearScreen();LineOut(40,40,60,60);

//plot a line from (40,40) to (60,50) coordinatesWait(3000);

}

Introduction to Mechatronics 38 / 56

Page 39: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

Output Control API : Servo-motor

Unregulated mode

no regulation (speed can vary according to the load)

reference = power in % , output selection= OUT_A, OUT_BC, OUT_ABC. . .

task main(){OnFwd(OUT_AC,85); //motor AC fwd at 85% of powerWait(1500); // run for 1.5 sOnRev(OUT_A,90); //motor A reverse at 90%,

//C still going fwd at 85%Float(OUT_C); //motot C power off, free decelerationWait(1500);Off(OUT_ABC); //motor ABC power off with braking}

Introduction to Mechatronics 39 / 56

Page 40: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

Output Control API : Servo-motor

Regulated mode

PID regulation of the motor speed (power will increase if load increases)

reference = speed in % of maximal speed

task motor_status(){while(1)NUMOUT(0,LCD_LINE1,MotorActualSpeed(OUT_A));

//diplay not speed but power!!}

task main() {start motor_status;

OnFwdReg(OUT_A, 40, OUT_REGMODE_IDLE);//same as OnFwd, no regulation

Wait(5000);OnFwdReg(OUT_A,40,OUT_REGMODE_SPEED); //speed regulationWait(5000);Off(OUT_A);StopAllTasks();}

Introduction to Mechatronics 40 / 56

Page 41: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

Output Control API : Servo-motor

Synchronized mode

only for a pair of motors (OUT_xy)

synchronized the rotation (useful to go in straight line for mobile robot)

if one motor slow down, the other adapts

last parameter: steering or turn percentage

task main() {OnFwdSync(OUT_AC, 50, 0); //Motors A and C same speedWait(2000);OnFwdSync(OUT_AC, 40 , 50); //motor A stopWait(2000);OnFwdSync(OUT_AC, 40 , 100);

//motor A speed opposite of CWait(2000);Off(OUT_AC);}

Introduction to Mechatronics 41 / 56

Page 42: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

Output Control API : Servo-motor

Position-based mode

regulation of rotation position in degree

#define degree 180

task main() {RotateMotor(OUT_AC,56, degree);

//rotation of 180 degree at 56% of power}

Introduction to Mechatronics 42 / 56

Page 43: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

Input API : Sensors

Configuration of the input ports

1 a TYPE (TOUCH,SOUND. . . ) with SetSensorType(port,TYPE)2 a MODE (RAW, BOOL. . . ) with SetSensorMode(port,MODE)

TYPE DescriptionSENSOR_TYPE_TOUCH touch sensor

SENSOR_TYPE_LIGHT_ACTIVE light sensor with LED onSENSOR_TYPE_LIGHT_INACTIVE light sensor with LED off

SENSOR_TYPE_SOUND_DB sound pressure in dBSENSOR_TYPE_LOWSPEED I2C sensor (Ultrasonic)

MODE DescriptionSENSOR_MODE_RAW value between 0 < x < 1024SENSOR_TYPE_BOOL 0 if x<512, else 1

SENSOR_TYPE_PERCENT value between 0 < x < 100SENSOR_TYPE_EDGE count number of transition

SENSOR_TYPE_TOUCH count number of level change

Introduction to Mechatronics 43 / 56

Page 44: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

Input API : Sensors

Default configuration of the input ports

high-level functions with the default mode : SetSensorXXXX(port)

task main() {SetSensorType(S1,SENSOR_TYPE_TOUCH);SetSensorMode(S1,SENSOR_MODE_BOOL)SetSensorTouch(S1); //idem than the 2 previous line

SetSensorSound(S3);//Sound sensor on port 3, default pourcent?

SetSensorLight(S4); // port 4, default mode : percentSetSensorLowSpeed(S2);

// I2C sensor (Ultrasonic,..) on port 2}

Introduction to Mechatronics 44 / 56

Page 45: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

Input API : Sensors and rotation

Reading

analog sensor: SensorValue(SX) or the equivalent macro SENSOR_X

for I2C ultrasonic sensor: SensorUS(port)

rotation count on servo_motor: MotorRotationCount(OUT_X)

task main() {bool cont; int dist;

SetSensorTouch(S1);SetSensorLowspeed(S2);ResetRotationCount(OUT_A);

while(1){ cont=SENSOR_1; // or cont=SensorValue(S1);dist=SensorUS(S2);if (cont==1)

{TextOut(0,LCD_LINE1,"Pressed"); PlayTone(440,500);}else TextOut(0,LCD_LINE1,"Released");if (MotorRotationCount(OUT_A) > 180)

TextOut(0,LCD_LINE2,"Half-rotation!"); } }

Introduction to Mechatronics 45 / 56

Page 46: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

One example : "Move forward but avoid obstacles"

Implementation 1

#define NEAR 15 //cm

task main(){SetSensorLowspeed(S4);

while(true){OnFwd(OUT_AC,50);

while(SensorUS(S4)>NEAR);//do nothing: waitOff(OUT_AC);OnRev(OUT_C,40); //turn

//angle linked to wait timeWait(800);}

}

Implementation 2

#define NEAR 15 //cm

task main(){SetSensorLowspeed(S4);

while(true){

OnFwd(OUT_AC,50);

if (SensorUS(S4)<NEAR){ Off(OUT_AC);OnRev(OUT_C,40);Wait(800); }

}}

Introduction to Mechatronics 46 / 56

Page 47: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

NXC I/O API

One example : 3 implementation

#define NEAR 15 //cm

mutex motor_mutex;

task obstacle_test(){ while(1)

{if (SensorUS(S4)<NEAR){Acquire(motor_mutex);Off(OUT_AC);OnRev(OUT_C,40);Wait(800);Release(motor_mutex);}

}}

task move(){

while(true){ Acquire(motor_mutex);OnFwd(OUT_AC,50);Release(motor_mutex); }}

task main(){SetSensorLowspeed(S4);start obstacle_test; start move; }

Implementation 3: Multiple tasks

running in concurrency

mutex: mutual exclusion =prevent the 2 tasks to controlmotors simultaneously

a task block on Acquire(), ifanother has already Acquire themutex → must wait for theRelease

Introduction to Mechatronics 47 / 56

Page 48: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 48 / 56

Page 49: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Classification and applications

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 49 / 56

Page 50: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Classification and applications

Mobile robots classification

Mobile robots

Robots with a moving base, by opposition with robotic manipulators.

Classification based on the locomotion type.

Wheeled robots

Introduction to Mechatronics 50 / 56

Page 51: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Classification and applications

Mobile robots classification

Mobile robots

Robots with a moving base, by opposition with robotic manipulators.

Classification based on the locomotion type.

Legged robots

Introduction to Mechatronics 50 / 56

Page 52: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Classification and applications

Mobile robots classification

Mobile robots

Robots with a moving base, by opposition with robotic manipulators.

Classification based on the locomotion type.

Legged robots

Introduction to Mechatronics 50 / 56

Page 53: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Classification and applications

Mobile robots classification

Wheeled robots, legged robots+

flying robots, undersea robots.

Introduction to Mechatronics 51 / 56

Page 54: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Classification and applications

Wheeled mobile robots applications

A few industrial applications

Automatic Guided Vehicles (AGV)FMC Technologieshttp://www.fmcsgvs.com

Introduction to Mechatronics 52 / 56

Page 55: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Classification and applications

Wheeled mobile robots applications

More and more general public applications

ToysTribot, WowWee

http://www.wowwee.com

Automatic vacuum cleanersDirtyDog, iRobot

http://www.irobot.com

Introduction to Mechatronics 52 / 56

Page 56: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Classification and applications

Wheeled mobile robots applications

Education and research

Khepera II , K-teamhttp://www.k-team.com

1 h autonomy, 1 m/s max7x3 cm, 80g (payload<250g)

Multi-robot navigationSRI

http://www.ai.sri.com/centibots/index.html

Introduction to Mechatronics 52 / 56

Page 57: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Classification and applications

Wheeled mobile robots applications

A few High-Tech applications

Spatial exploration robotsSojourner mission to Mars

http://mars.jpl.nasa.gov/MPF/rover/sojourner.html

Introduction to Mechatronics 52 / 56

Page 58: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Classification and applications

Wheeled mobile robots applications

A few High-Tech applications

Inspectionhttp://crasar.csee.usf.edu

Introduction to Mechatronics 52 / 56

Page 59: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 53 / 56

Page 60: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Mechanical architecture

Outline

1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware

2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API

3 Mobile robotsClassification and applications

4 Wheeled Mobile Robots TechnologyMechanical architecture

Introduction to Mechatronics 54 / 56

Page 61: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Mechanical architecture

Mobile robots mechanical architecture

A large amount of systems

several types of wheels

articulated platforms

caution: all the architectures arenot kinematically consistent

Lego Tribot: a simple differential drivemobile robot

simple to build: 2 fixed wheels,with 2 independent actuators

differential drive locomotion

nonholonomic, nonlinear. . . not sosimple

Introduction to Mechatronics 55 / 56

Page 62: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Mechanical architecture

Mobile robots mechanical architecture

A large amount of systems

several types of wheels

articulated platforms

caution: all the architectures arenot kinematically consistent

Lego Tribot: a simple differential drivemobile robot

simple to build: 2 fixed wheels,with 2 independent actuators

differential drive locomotion

nonholonomic, nonlinear. . . not sosimple

Introduction to Mechatronics 55 / 56

Page 63: Introduction to Mechatronics - unistra.fr... · Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology NXC structure and statements Statements

Lego Mindstorms Hardware NXT Programming with NBC/NXC Mobile robots Wheeled Mobile Robots Technology

Mechanical architecture

Lego TriBot modelling

O

~y

~x

x

y

CIR

O′

L

ρ

ω

θ

v

ϕr

ϕl

vr

vl

Wheels velocities (!anglesconvention) :

vr = −r ϕr = (ρ+ L)ω

vl = r ϕl = (ρ− L)ω

and then:

v =vr + vl

2

ω =−r(ϕr + ϕl)

2L

Differential kinematics:

x = v cos θ

y = v sin θ

θ = ω

Introduction to Mechatronics 56 / 56