Upload
tahder77
View
228
Download
0
Embed Size (px)
Citation preview
7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
1/106
Introduction to Mechatronics
Discover robots with the Lego Mindstorms
Loc Cuvillon, Bernard Bayle
Ecole Nationale Suprieure de Physique de StrasbourgStrasbourg University
March 13, 2009
Introduction to Mechatronics 1 / 97
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
2/106
You are free to copy, to modify, to adapt and distribute this document.
Latex sources of this document should be available on the authors webpage.
LEGO and Mindstorms NXT are trademarks of the LEGO Group, which does
not sponsor, authorize or endorse this document.
Introduction to Mechatronics 2 / 97
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
3/106
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Part I
Hardware and Programming under Linux
Introduction to Mechatronics 3 / 97
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
4/106
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Outline
1 Lego Mindstorms HardwareOverviewNXT Brick Hard/Firm-ware
2 NXT Programming with NBC/NXCNBC/NXC basicsNXC structure and statementsNXC I/O API
3 Bluetooth communication
Bluetooth ProtocolBluetooth communication with PCBluetooth communication between NXT
Introduction to Mechatronics 4 / 97
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
5/106
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Outline
1 Lego Mindstorms Hardware
Overview
NXT Brick Hard/Firm-ware
2 NXT Programming with NBC/NXCNBC/NXC basics
NXC structure and statements
NXC I/O API
3 Bluetooth communication
Bluetooth Protocol
Bluetooth communication with PC
Bluetooth communication between NXT
Introduction to Mechatronics 5 / 97
L Mi d t H d NXT P i ith NBC/NXC Bl t th i ti
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
6/106
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
References
NXC Programming
[NXC07] J.C. Hansen, NXT Power Programming, Variant Press, 2007
[NXC] J.C Hansen, Not eXactly C Programmers 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 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
7/106
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
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 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
8/106
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Overview
Outline
1 Lego Mindstorms Hardware
Overview
NXT Brick Hard/Firm-ware
2 NXT Programming with NBC/NXCNBC/NXC basics
NXC structure and statements
NXC I/O API
3 Bluetooth communication
Bluetooth Protocol
Bluetooth communication with PC
Bluetooth communication between NXT
Introduction to Mechatronics 8 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
9/106
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Overview
Lego Mindstorms Overview
NXT Inputs
NXT 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 9 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
10/106
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Overview
NXT brick
battery level
NXT brick name(configurable)
USB 2.0 connectorbluetooth indicatorB : ON, invisible
B< : ON, visible
B : ON, connected
usb indicatorusb : connected, working
][ : connected, not working
loudspeaker
On/Enter button
Clear/Go back buttonNaviguation buttons
S4S1 S2 S3Sensor port
OUT_A OUT_B OUT_CServo outputs
Introduction to Mechatronics 10 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
11/106
g g g
Overview
NXT brick Menus
On/off
Connections
Visability
Search
to bluetooth device)
(search and connect
Motor rotation
Sound dBA
Ultrasonic cm
Sound files
Software File
(bytecode executable
upload 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
saved
in
Introduction to Mechatronics 11 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
12/106
g g g
Overview
NXT-G (LabView)
advance graphical interface for programming NXT
functional block and control flow
Introduction to Mechatronics 12 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://./play-movie-nxtghttp://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
13/106
Overview
Some fun NXT Projects
Rubiks Cube Solver
by Daniele Benedettelli
NXTway GSby Y. Yamamoto
Introduction to Mechatronics 13 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://./play-movie-segwayhttp://./play-movie-utopyhttp://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
14/106
NXT Brick Hard/Firm-ware
Outline
1 Lego Mindstorms Hardware
Overview
NXT Brick Hard/Firm-ware
2 NXT Programming with NBC/NXCNBC/NXC basics
NXC structure and statements
NXC I/O API
3 Bluetooth communication
Bluetooth ProtocolBluetooth communication with PC
Bluetooth communication between NXT
Introduction to Mechatronics 14 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
15/106
NXT Brick Hard/Firm-ware
Hardware specification
S1 S2 S3 S4
PWM signal generator
8bit AVR CoProcessor
A/D converter for analogic sensor
(light,sound,touch )
USB 2.0 connector
high speed communication line
on Port S4 (for future use)
RS485 UARTBluetooth Chip
class 2
10 meters range
Amtel 32 bit ARM Processor
48MHz, 64KB RAM
256KB FLASH
I2C interface with AVR proc.
and digital sensor (ultrasonic)
single and double Hbridge
(OUT_A and OUT_BC)
LB1930 & LB1836
AT91SAM7S256
Introduction to Mechatronics 15 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
16/106
NXT Brick Hard/Firm-ware
Hardware specification
I2C: Inter-Integrated
Communication need 3 lines
(data,clock,ground)
UART: Universal Asynchronous
Receiver Transmitter(serial line/port)
Note:
-each sensor port (S1-4) can be used
with digital or analog sensor.-6 wires by port: 3 for I2C + 3 for
analog signals
Introduction to Mechatronics 16 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
17/106
NXT Brick Hard/Firm-ware
NXT Firmware
Memory
Boot Recovery
(SAMBA)ROM
FLASH
RAM
64K
Firmware
(sound, .rxe...)
Files
Running
executables
256K
Processor
Boot loader/boot code
LEGO firmware
with CodeByte interpreter
Executables (.rxe)
Software
Boot code/loaderinitialization 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 in
FLASH memory
BOOT CODE stored in RAM
allow to update firmware
Introduction to Mechatronics 17 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
18/106
Outline
1 Lego Mindstorms Hardware
Overview
NXT Brick Hard/Firm-ware
2
NXT Programming with NBC/NXCNBC/NXC basics
NXC structure and statements
NXC I/O API
3 Bluetooth communication
Bluetooth ProtocolBluetooth communication with PC
Bluetooth communication between NXT
Introduction to Mechatronics 18 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
19/106
NBC/NXC basics
Outline
1 Lego Mindstorms Hardware
Overview
NXT Brick Hard/Firm-ware
2
NXT Programming with NBC/NXCNBC/NXC basics
NXC structure and statements
NXC I/O API
3 Bluetooth communication
Bluetooth ProtocolBluetooth communication with PC
Bluetooth communication between NXT
Introduction to Mechatronics 19 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
20/106
NBC/NXC basics
NBC/NXC
NBC: Next Byte Codes
name of an assembly language
name of an open source assembler available under MPL license
produce executable code for the native LEGO firmware
NXC: Not eXactly C
high level programming language: C-like syntax
compiler built upon nbc
produce ByteCode executables (.rxe)
NBC and NXC available for Linux, MAC OS, Windows
custom Firmwares to replace LEGO firmwares are available : LeJOS
(JAVA-VM) for Java programming
Introduction to Mechatronics 20 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://goforward/http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
21/106
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
Run execution
toto.rxe available in Program Files folder via menus after upload
start/stop via buttons
3Upload of .rxe file
USB cable
1Source editing
2Compilation
4Execution
Crosscompilation process
Introduction to Mechatronics 21 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
22/106
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 complex configuration of linux device manager (udev)upload command
nbc -d -S=usb toto.rxe
via LiNXT (prefered method, [LINXT])
LiNXT: Perl script with automatic search of the brickcommand to upload, download and get NXT information
to get help linxt -h
to upload a file (as root user):
linxt -u toto.rxe
Introduction to Mechatronics 22 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
23/106
NXC structure and statements
Outline
1 Lego Mindstorms Hardware
Overview
NXT Brick Hard/Firm-ware
2
NXT Programming with NBC/NXCNBC/NXC basics
NXC structure and statements
NXC I/O API
3 Bluetooth communication
Bluetooth ProtocolBluetooth communication with PC
Bluetooth communication between NXT
Introduction to Mechatronics 23 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
24/106
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 byte
struct User define
Arrays Array of any type
declaration of variable
int i;
int x=0x10; // 16 in hexadecimal
int y=10; // 10
string msg=toto;
Introduction to Mechatronics 24 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
25/106
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 entries
myarray[0]= 15;
conditions= equal
!= not equaltrue
false
Expr True if Expr!=0&& logical AND between conditions
|| logical OR between conditions
Introduction to Mechatronics 25 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
26/106
NXC structure and statements
Control structures
if, if . . . else
if (x==1)
{x=2; z=3;}
elsey=4;
for
for (i=1; i
7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
27/106
NXC structure and statements
Control structures
switch
switch (x)
{
case 1 :
z=3;
break;
case 2 :
// some code
break;
default:
// some code
break;}
repeat and until control structure available but not C standard
Introduction to Mechatronics 27 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC t t d t t t
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
28/106
NXC structure and statements
Program structure: Tasks
task music (){ PlayTone(440,3000); }
task motion ()
{
while(true)
{ OnFwd(OUT_A,50);Wait(1000); }
}
task main ()
{ // motion
start music; //and musicstart motion; //in parallel
} // execution
multithreading in NXT
=concurrent execution of tasks
number of task and function must
be < 256
at least an init task called mainneeded
API
precedes(task1,task2,..);
launch the task after end of main
start task1 or StartTask(task1) ;
StopAllTasks();
Introduction to Mechatronics 28 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC structure and statements
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
29/106
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 2
foo(2); // ERROR(one-variable)
}
Introduction to Mechatronics 29 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC structure and statements
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
30/106
NXC structure and statements
Preprocessor
Preprocessor directive
include files
#include foo.h#include //error no libray path
macro and define (recommended!)
#define TIMEOUT 200 //0.2 ms timeout
#define NORMAL_SPEED 50
Introduction to Mechatronics 30 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC I/O API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
31/106
NXC I/O API
Outline
1 Lego Mindstorms Hardware
Overview
NXT Brick Hard/Firm-ware
2 NXT Programming with NBC/NXC
NBC/NXC basics
NXC structure and statements
NXC I/O API
3 Bluetooth communication
Bluetooth ProtocolBluetooth communication with PC
Bluetooth communication between NXT
Introduction to Mechatronics 31 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC I/O API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
32/106
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
Play tone (440,500);
//440: frequency
//500: duration
Introduction to Mechatronics 32 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC I/O API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
33/106
LCD API
task main ()
{
int i=1;
TextOut(0,LCD_LINE1,"toto:");
// display toto on line 1
NumOut(20,LCD_LINE1,i);//display i on line 1 and column 20
Wait(3000);
ClearScreen();
LineOut(40,40,60,60);
//plot a line from (40,40) to (60,50) coordinates
Wait(3000);
}
Introduction to Mechatronics 33 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC I/O API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
34/106
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 power
Wait(1500); // run for 1.5 s
OnRev(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 34 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC I/O API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
35/106
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 regulationWait(5000);OnFwdReg(OUT_A,40,OUT_REGMODE_SPEED); //speed regulationWait(5000);Off(OUT_A);StopAllTasks();
}
Introduction to Mechatronics 35 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC I/O API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
36/106
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); //same as OnFwd, no regulation
Wait(2000);
OnFwdSync(OUT_AC, 40 , 50); //motor A stop
Wait(2000);
OnFwdSync(OUT_AC, 40 , 100);
//motor A speed opposite of C
Wait(2000);
Off(OUT_AC);
}
Introduction to Mechatronics 36 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC I/O API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
37/106
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 37 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC I/O API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
38/106
Advance Output API : Write File
Position-based mode
wite written in flash memory
return value of the API: LDR_FILEEXIST, LDR_FILEISFULL,. . .
read file API : OpenFileRead(), Read()
task main() {byte handle;
int result;
result=CreateFile("test_write.rxe",256,handle);
//file of 256 bytes
if (result==LDR_SUCCESS)
{ int i=3;result=Write(handle,i);
}
CloseFile(handle);
}
Introduction to Mechatronics 38 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC I/O API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
39/106
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 Description
SENSOR_TYPE_TOUCHSENSOR_TYPE_LIGHT_ACTIVE light sensor with LED on
SENSOR_TYPE_LIGHT_INACTIVE light sensor with LED offSENSOR_TYPE_SOUND_DB sound pressure in dB
SENSOR_TYPE_TOUCH I2C sensor (Ultrasonic)
MODE DescriptionSENSOR_MODE_RAW value between 0 < x < 1024
SENSOR_TYPE_BOOL 0 if x
7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
40/106
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 40 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC I/O API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
41/106
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");else TextOut(0,LCD_LINE1,"Release");if (MotorRotationCount(OUT_A) > 180)
TextOut(0,LCD_LINE2,"Half-rotation!"); } }
Introduction to Mechatronics 41 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
NXC I/O API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
42/106
One example : 3 implementation
Move forward but avoid obstacles
#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);
}
}
#define NEAR 15 //cm
task main(){SetSensorLowspeed(S4);
while(true){
OnFwd(OUT_AC,50);
if (SensorUS(S4)
7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
43/106
One example : 3 implementation
#define NEAR 15 //cm
mutex motor_mutex;
task obstacle_test(){ while(1)
{if (SensorUS(S4)
7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
44/106
Outline
1 Lego Mindstorms Hardware
Overview
NXT Brick Hard/Firm-ware
2 NXT Programming with NBC/NXC
NBC/NXC basicsNXC structure and statements
NXC I/O API
3 Bluetooth communication
Bluetooth ProtocolBluetooth communication with PC
Bluetooth communication between NXT
Introduction to Mechatronics 44 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth Protocol
O tli
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
45/106
Outline
1 Lego Mindstorms Hardware
Overview
NXT Brick Hard/Firm-ware
2 NXT Programming with NBC/NXC
NBC/NXC basicsNXC structure and statements
NXC I/O API
3 Bluetooth communication
Bluetooth ProtocolBluetooth communication with PC
Bluetooth communication between NXT
Introduction to Mechatronics 45 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth Protocol
Bluetooth
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
46/106
Bluetooth
wireless protocolfor electronics (phone headset), computer peripherals (WiiMote,
keyboard)
2.4 GHz short-range radio frequency bandwidth : unlicensed frequency
Classclass 1: 100 mW 100meters
class 2: 2.5 mW 10 meters (LEGO NXT)
Search and Pairing
search service available to find new Bluetooth device
pairing: trust communication by learning of a common passkey
-input of the passkey on both device
-key used to encrypt communication
Introduction to Mechatronics 46 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth Protocol
Bluetooth piconet
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
47/106
Bluetooth piconet
Master and slaves devices (max: 7 slaves)
on master by piconet (slaves synchronized on his clock)
slaves can not initiate a data packet transfer
slaves can send a response packet right after the master one
(synchronous communication)
slaves can not communicate between them
Introduction to Mechatronics 47 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth Protocol
Bluetooth NXT Communication Protocol
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
48/106
Bluetooth NXT Communication Protocol
NXT Direct Command (also for USB communication)
direct command interpreted by the NXT Slave firmware and translatedinto functions
any Bluetooth device (phone, PC, NXT,..) can send command via
Bluetooth packets
NXT Direct Command Telegramlength of the datagram (without the 2 Length bytes)
command type
0x00: Direct command, response required0x80: Direct command, no response0x02: Means a response datagram from slave
command code (Ex: 0x0B=GetBatteryLevel 0x03=PlayTone)
parameters of the command, or return value
byte 1
Length, LSB Length, MSBCommand
TypeCommand
byte 2 byte 3 byte 4 byte 5 byte 6 byt..
Parameters..................
Introduction to Mechatronics 48 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication with PC
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
49/106
Outline
1 Lego Mindstorms Hardware
Overview
NXT Brick Hard/Firm-ware
2 NXT Programming with NBC/NXC
NBC/NXC basicsNXC structure and statements
NXC I/O API
3 Bluetooth communication
Bluetooth ProtocolBluetooth communication with PC
Bluetooth communication between NXT
Introduction to Mechatronics 49 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication with PC
Pairing between PC and NXT -1
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
50/106
Pairing between PC and NXT -1
Get NXT Bluetooth address
each Bluetooth as an unique address on 6 bytes (MAC address)
1 command hcitool : give name and Bluetooth address of available device
>hcitool scanScanning ...
00:16:53:04:B3:46 NXT
2 LiNXT -i , while NXT connected by USB
>sudo ./linxt -i
Device information:
NXT name: NXT02
Bluetooth address: 00:16:53:02:f3:31
Introduction to Mechatronics 50 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication with PC
Pairing between PC and NXT -2
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
51/106
Pairing between PC and NXT 2
Pairing under ubuntu Linux1 set the key in the pop-up when using the following connect program
2 use NXT search and Linux Bluetooth-applet:
Linux: right click on the Bluetooth-applet > preferencesset a Bluetooth name for the PC dongleNXT: menu Bluetooth > search
select your PC name and validatevalidate the default passkeyLinux: a pop-up ask for the passkey, give the same
3 it is a one time operation, NXT now appears in Bluetooth-applet >
preferences > known devices
Introduction to Mechatronics 51 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication with PC
Programming of Direct Commands
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
52/106
Programming of Direct Commands
Socket
a socket is an abstraction for an inter-process communication (over
network)
a socket can be bind to an IP or Bluetooth address
then we can read, write on the socket data between 2 process
Compilation with gcc
gcc -o executable_name -lm -lbluetooth source_name.c
to link with Bluetooth library: -lbluetooth (math: -lm)
Example: play_tone.copening of a socket bind to NXT Bluetooth address
write of the direct command PlayTone 0x03
read of the response (status)
Introduction to Mechatronics 52 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication with PC
play tone.c
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
53/106
play_tone.c
#include
#include #include //socket lib#include #include //bluettoh lib#include #define max_message_size 59
int nxtsocket; //on declare la socket
void init_bluetooth(char *btAddress) {struct sockaddr_rc addr={0};//structure du type sockaddr_rcint status;
nxtsocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
addr.rc_family = AF_BLUETOOTH;addr.rc_channel = (uint8_t) 1;str2ba(btAddress, &addr.rc_bdaddr);// convertit un string en adresse
status = connect(nxtsocket, (struct sockaddr *)&addr, sizeof(addr) )//connection }
Introduction to Mechatronics 53 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication with PC
play tone.c
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
54/106
play_tone.c
void nxt_tone(void) {/**0x06 0x00 : length =6 bytes
0x00 : direct command with response0x03 : Playtone commande0x5B 0x1C : parameter 1 - 7259 (200-14000Hz)0x88 0x13 : parameter 2 - 0x1388=5000 (ms)**/
char cmd[8]={0x06, 0x00, 0x00, 0x03,0x5B ,0x1C ,0x88,0x13};char reply[max_message_size];
write(nxtsocket, cmd, 8); //send PlayTone command
read(nxtsocket, reply, 5); //read response
// check responseif (reply[2] != 0x02) fprintf(stderr, "not a response datagramm");if (reply[3] != 0x03) fprintf(stderr, "not the reply to play tone");if (reply[4] != 0x00) fprintf(stderr, "status not ok");
}
Introduction to Mechatronics 54 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication with PC
play tone.c
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
55/106
p y_
int main (void) {int blevel;
char btaddress[18] = "00:16:53:02:f3:31"; //NXT adressinit_bluetooth(btaddress); //open connectionnxt_tone(); //direct commandclose(nxtsocket);return 0;
}
Introduction to Mechatronics 55 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication with PC
NXTlibC
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
56/106
A simple library to perform Direct Command
wrap the previous code in nice function
compilation:
gcc -lm -lbluetooth -lnxtlibc test.c -o test
API of NXTlibC : samples
nxt_bluetooth_initialize() , nxt_bluetooth_done()
get_battery_level(),play_tone()
set_touch_sensor(), get_touch_value()
message_write(), message_read() (see next section)
Introduction to Mechatronics 56 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication with PC
play_tone.c with NXTlibC
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
57/106
p y
#include #include
#define MAC "00:16:53:02:f3:31"
int main (void){int ret;
// * * * * * Connection a la brique * * * * * //nxt_bluetooth_initialize(MAC);
play_tone(500, 2000);
// * * * * * Verification de la batterie * * * * * //ret = get_battery_level();
// *** all motor at 10% of power in regulate mode**//ret = _set_output_state(ALL_WHEEL,10,
MODE_MOTORON|MODE_BRAKE|MODE_REGULATED,REGULATION_MODE_MOTOR_SPEED|REGULATION_MODE_MOTOR_SYNC,0x00, MOTOR_RUN_STATE_RUNNING, 1000000);
nxt_bluetooth_done();
return 0; }
Introduction to Mechatronics 57 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication between NXT
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
58/106
1 Lego Mindstorms Hardware
Overview
NXT Brick Hard/Firm-ware
2 NXT Programming with NBC/NXC
NBC/NXC basicsNXC structure and statements
NXC I/O API
3 Bluetooth communication
Bluetooth ProtocolBluetooth communication with PC
Bluetooth communication between NXT
Introduction to Mechatronics 58 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication between NXT
Connection between NXT
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
59/106
Via the Bluetooth menu
search for others NXTconnect it on one of the free channel 1, 2 or 3 (up to 3 slave)
Master
Channel 0
Up to 3 slavesChannel 13
Nxt
Piconet
Introduction to Mechatronics 59 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication between NXT
NXC Bluetooth API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
60/106
Via the Bluetooth menu
10 mailbox on each NXT to exchange messages
if there is no read program while sending = message lost
direct commands available to control the slave
Example of message exchange
master : check slave connection, send message to mailbox 5 on slave,
read again message in mailbox 1 on slave,
slave : check master connection, read its mailbox 5,
put an message in its mailbox 1
Introduction to Mechatronics 60 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication between NXT
Message exchange
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
61/106
//MASTER#define INBOX 1
#define OUTBOX 5
sub BTCheck(int conn){if (!BluetoothStatus(conn)==NO_ERR){
TextOut(5,LCD_LINE2,"Error");Wait(1000);Stop(true); }
}
task main(){string in,out="hello from master!";
BTCheck(1); //check slave connectionTextOut(10,LCD_LINE1,"Master Test");
SendRemoteString(BT_CONN,OUTBOX,out);
while (1){ ReceiveRemoteString(INBOX, true, in);TextOut(10,LCD_LINE3,in); }
}
Introduction to Mechatronics 61 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication between NXT
Message exchange
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
62/106
//SLAVE#define INBOX 5
#define OUTBOX 1
sub BTCheck(int conn){if (!BluetoothStatus(conn)==NO_ERR){
TextOut(5,LCD_LINE2,"Error");Wait(1000);Stop(true);
}}
task main(){string in,out="thanks, master!";
BTCheck(0); //check slave connection
TextOut(10,LCD_LINE1,"Slave Test");
while(1){ ReceiveRemoteString(INBOX, true, in);SendResponseString(OUTBOX,out); // Not SendRemote !!TextOut(10,LCD_LINE3,in); }
}
Introduction to Mechatronics 62 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication between NXT
NXC Bluetooth API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
63/106
Example of Direct Command
master : check slave connection,
send play_tone command,
wait for response status,
send reset position on motor A
wait for response status,
send full speed command on motor A with speed regulation
Introduction to Mechatronics 63 / 97
Lego Mindstorms Hardware NXT Programming with NBC/NXC Bluetooth communication
Bluetooth communication between NXT
NXC Bluetooth API
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
64/106
//MASTER
sub BTCheck(int conn){if (!BluetoothStatus(conn)==NO_ERR){
TextOut(5,LCD_LINE2,"Error");Wait(1000);Stop(true); }
}
task main(){BTCheck(1);
RemotePlayTone(BT_CONN, 4000, 100);until(BluetoothStatus(BT_CONN)==NO_ERR);Wait(1100);
RemoteResetMotorPosition(BT_CONN,OUT_A,true);until(BluetoothStatus(BT_CONN)==NO_ERR);
RemoteSetOutputState(BT_CONN, OUT_A, 100,OUT_MODE_MOTORON+OUT_MODE_BRAKE+OUT_MODE_REGULATED,OUT_REGMODE_SPEED, 0, OUT_RUNSTATE_RUNNING, 0)
}
Introduction to Mechatronics 64 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
65/106
Part II
Introduction to Mobile Robotics
Introduction to Mechatronics 65 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
66/106
4 Mobile robotsClassification and applicationsIssues
5 Wheeled Mobile Robots TechnologyMechanical architecture
Embedded systemActuatorsSensors
6 NavigationLocalizationMappingPlanningControl
Introduction to Mechatronics 66 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
67/106
4 Mobile robotsClassification and applications
Issues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded systemActuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 67 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Classification and applications
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
68/106
4 Mobile robotsClassification and applications
Issues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded systemActuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 68 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Classification and applications
Mobile robots classification
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
69/106
Mobile robots
Robots with a moving base, by opposition with robotic manipulators.
Classificationbased on the locomotion type.
Wheeled robots
Introduction to Mechatronics 69 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Classification and applications
Mobile robots classification
http://goforward/http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
70/106
Mobile robots
Robots with a moving base, by opposition with robotic manipulators.
Classificationbased on the locomotion type.
Legged robots
Introduction to Mechatronics 69 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Classification and applications
Mobile robots classification
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
71/106
Mobile robots
Robots with a moving base, by opposition with robotic manipulators.
Classificationbased on the locomotion type.
Legged robots
Introduction to Mechatronics 69 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Classification and applications
Mobile robots classification
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
72/106
Wheeled robots, legged robots+
flying robots, undersea robots.
Introduction to Mechatronics 70 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Classification and applications
Wheeled mobile robots applications
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
73/106
A few industrial applications
Automatic Guided Vehicles (AGV)
FMC Technologies
http://www.fmcsgvs.com
Introduction to Mechatronics 71 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Classification and applications
Wheeled mobile robots applications
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
74/106
More and more general public applications
ToysTribot, WowWee
http://www.wowwee.com
Automatic vacuum cleanersDirtyDog, iRobot
http://www.irobot.com
Introduction to Mechatronics 71 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Classification and applications
Wheeled mobile robots applications
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
75/106
Education and research
Khepera II , K-team
http://www.k-team.com
1 h autonomy, 1 m/s max
7x3 cm, 80g (payload
7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
76/106
A few High-Tech applications
Spatial exploration robots
Sojourner mission to Mars
http://mars.jpl.nasa.gov/MPF/rover/sojourner.html
Introduction to Mechatronics 71 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Classification and applications
Wheeled mobile robots applications
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
77/106
A few High-Tech applications
Inspection
http://crasar.csee.usf.edu
Introduction to Mechatronics 71 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Issues
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
78/106
4
Mobile robotsClassification and applications
Issues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded systemActuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 72 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Issues
Issues
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
79/106
Technology
Issues:
mechanical architecture
embedded system
actuators
sensors
Navigation
Issues:
localization
mapping
planning
control
Introduction to Mechatronics 73 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
80/106
4
Mobile robotsClassification and applications
Issues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded systemActuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 74 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Mechanical architecture
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
81/106
4
Mobile robotsClassification and applications
Issues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded systemActuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 75 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Mechanical architecture
Mobile robots mechanical architecture
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
82/106
A large amount of systems
several types of wheels
articulated platforms
caution: all the architectures are
not kinematically consistent
Lego Tribot: a simple differential drive
mobile robot
simple to build: 2 fixed wheels,
with 2 independent actuators
differential drive locomotion
nonholonomic, nonlinear. . . not so
simple
Introduction to Mechatronics 76 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Mechanical architecture
Mobile robots mechanical architecture
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
83/106
A large amount of systems
several types of wheels
articulated platforms
caution: all the architectures are
not kinematically consistent
Lego Tribot: a simple differential drive
mobile robot
simple to build: 2 fixed wheels,
with 2 independent actuators
differential drive locomotion
nonholonomic, nonlinear. . . not so
simple
Introduction to Mechatronics 76 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Mechanical architecture
Lego TriBot modelling
Wheels velocities (!angles
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
84/106
O
y
xx
y
CIR
O
L
v
vd
vg
r
l
Wheels velocities (!angles
convention) :
vr = rr = ( + L)
vl = rl = ( L)
and then:
v =
vr + vl
2
=r( r + l)
2L
Differential kinematics:
x = vcos y = vsin
=
Introduction to Mechatronics 77 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Embedded system
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
85/106
4 Mobile robots
Classification and applications
Issues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded systemActuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 78 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Embedded system
Lego TriBot embedded system
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
86/106
NXT Block
The core of the robot, which enables to get measurements and to control theactuators.
Refer to the first part of the talk for more details. . .
NXT Inputs
NXT 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 79 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Actuators
Outline
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
87/106
4 Mobile robots
Classification and applications
Issues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded systemActuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 80 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Actuators
LEGO Mindstorms Servo-motor
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
88/106
Encoder wheel andwith optical sensor
Gear train (1:48)
Running_modes
ON: power control
open 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 81 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Actuators
LEGO Mindstorms Servo-motor driving
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
89/106
O V
9 V
90% duty cycle
O V
9 V
10% 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 Action
H L Forward
L H Reverse
L L Brake
Introduction to Mechatronics 82 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Actuators
Electronic braking
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
90/106
e
i
U
R
L
= Ki
= Ke
e : back e.m.f
: motor torque
: motor angular speed
Braking
1 motor motion: e= 0
2 short circuit current i eR
in opposition
Introduction to Mechatronics 83 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Sensors
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
91/106
4 Mobile robots
Classification and applications
Issues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded systemActuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 84 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Sensors
Ultrasonic Telemeters
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
92/106
http://www.pages.drexel.edu/ kws23/tutorials/ultrasonic/ultrasonic.html
Properties:alternate emission/reception
sounds not heard by human
ear (ultrasound=20kHz to
200kHz)
minimal measurementdistance and variable
maximal frequency=f(maximal
distance)
different drawbacks
(directivity, reflectivity,
ambient conditions sensitivity)
Introduction to Mechatronics 85 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Sensors
Lego TriBot Ultrasonic Telemeter
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
93/106
Introduction to Mechatronics 86 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
94/106
4 Mobile robots
Classification and applications
Issues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded systemActuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 87 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Localization
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
95/106
4 Mobile robots
Classification and applications
Issues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded systemActuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 88 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Localization
Dead reckoning
Odometry
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
96/106
Odometry
Computation of the configuration by velocities integration:
x(t) =
Zt0
x()d, y(t) =
Zt0
y()d, (t) =
Zt0
()d.
The TriBot example, with a Te sampling period:
x(k + 1) = x(k) + v(k)Te cos (k)
y(k + 1) = y(k) + v(k)Te sin (k)
(k + 1) = (k) + (k)Te
Remark
Odometry: current configuration relative to the initial configuration.
Introduction to Mechatronics 89 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Mapping
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
97/106
4 Mobile robots
Classification and applicationsIssues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded systemActuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 90 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Mapping
Environment mapping
Occupancy grid: discrete map of the environment
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
98/106
Occupancy grid: discrete map of the environment
Cell decomposition, with probability of collision from sensors measurements.
The simplest case: binary grid, without filtering, trusting the odometry
localization.
Introduction to Mechatronics 91 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Planning
Outline
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
99/106
4 Mobile robots
Classification and applicationsIssues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded system
Actuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 92 / 97 Mobile robots Wheeled Mobile Robots Technology Navigation
Planning
Configuration space
Definition
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
100/106
Configuration space = set of all the accessible configurations of the robot:robot represented as a point: obstacles augmentation
robot with complex shapes and kinematics: more difficult problem. Over
pessimistic obstacle augmentation can close doors !
Introduction to Mechatronics 93 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Planning
Roadmaps
Visibility roadmap
http://find/http://goback/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
101/106
y p
Graph capturing the environment topology from the polygonal obstaclesvertices.
link initial point and goal to visible vertices
Introduction to Mechatronics 94 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Planning
Roadmaps
Visibility roadmap
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
102/106
y p
Graph capturing the environment topology from the polygonal obstaclesvertices.
apply the same to the new vertices
Introduction to Mechatronics 94 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Planning
Roadmaps
Visibility roadmap
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
103/106
y p
Graph capturing the environment topology from the polygonal obstaclesvertices.
search for a path in the graph
Introduction to Mechatronics 94 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Control
Outline
4 Mobile robots
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
104/106
4 Mobile robots
Classification and applicationsIssues
5 Wheeled Mobile Robots Technology
Mechanical architecture
Embedded system
Actuators
Sensors
6 Navigation
Localization
MappingPlanning
Control
Introduction to Mechatronics 95 / 97
Mobile robots Wheeled Mobile Robots Technology Navigation
Control
Path following problem
Problem
http://find/7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
105/106
Find such that d(P, C) decreases to zero, with v imposed.
x
y
Ox
O
C
r
Or
xr
yr
y
P
d
a
e
It can be showna that:
s =vcos e a sin e
1 dc(s)
,
d = vsin e + a cos e,
e = sc(s).
a|d c(s)|
7/30/2019 Intro to Mechatronics from Strasbourg University.pdf
106/106
d vsin e + a cos e
It comes that:
= vsin e
acos e
v
cos ek(d, e)d,
with k(d, e) 0 such that k(d,
2) = 0 gives:
d = vak(d, e)d.
Consequence
If a, v et k(d, e) > 0: |d| decreases along any path.
Restrictions
No control of the orientation.
Can be solve at the planning step.
Introduction to Mechatronics 97 / 97
http://find/