Professional Documents
Culture Documents
The last version of this book and other documents are available at the URL
http://book.duckietown.org/
Google search the documentation (with some delay, for Google to index the pages)
2
TABLE OF C
CONTENTS
ONTENTS
Part C - Oper
Operation
ation manual - Duckiebot .......................................................................................................... 59
Unit C-1 - Duckiebot confconfigur
igurations
ations...........................................................................................................
........................................................................................................... 60
Section 1.1 - Configuration list.....................................................................................................................
..................................................................................................................... 60
Section 1.2 - Configuration functionality....................................................................................................
.................................................................................................... 60
Unit C-2 - Acquiring the parts for the Duckiebot C0 ................................................................................ 62
Section 2.1 - Bill of materials........................................................................................................................
........................................................................................................................ 62
Section 2.2 - Chassis......................................................................................................................................
...................................................................................................................................... 63
Section 2.3 - Raspberry Pi 3 - Model B ........................................................................................................ 63
Section 2.4 - Camera ..................................................................................................................................... 65
Section 2.5 - DC Stepper Motor HAT .......................................................................................................... 66
Section 2.6 - Battery ...................................................................................................................................... 67
Section 2.7 - Standoffs, Nuts and Screws .................................................................................................... 67
Section 2.8 - Zip Tie.......................................................................................................................................
....................................................................................................................................... 68
Section 2.9 - Configuration C0-w ................................................................................................................. 68
Section 2.10 - Configuration C0-j ............................................................................................................... 69
Section 2.11 - Configuration C0-d ............................................................................................................... 69
Unit C-3 - Soldering boar
boards ds for C0 .............................................................................................................. 70
Unit C-4 - Pr
Preparing
eparing the pow power er cable for C0 .............................................................................................. 71
Section 4.1 - Step 1: Find a cable..................................................................................................................
.................................................................................................................. 71
Section 4.2 - Step 2: Cut the cable................................................................................................................
................................................................................................................ 72
Section 4.3 - Step 3: Strip the cable..............................................................................................................
.............................................................................................................. 72
Section 4.4 - Step 3: Strip the wires..............................................................................................................
.............................................................................................................. 73
Section 4.5 - Step 4: Find the power wires .................................................................................................. 74
Section 4.6 - Step 5: Test correct operation ................................................................................................. 74
Unit C-5 - Assembling the Duckiebot C0 ................................................................................................... 76
Section 5.1 - Part A - Assembling the car - bottom part ............................................................................ 76
Section 5.2 - Part B - Assembling the RPI-3, camera, and HATs .............................................................. 79
Unit C-6 - Repr
eproducing
oducing the imag imagee............................................................................................................... 80
Section 6.1 - Download and uncompress the Ubuntu Mate image..........................................................
.......................................................... 80
Section 6.2 - Burn the image to an SD card ................................................................................................ 80
Section 6.3 - Raspberry Pi Config ................................................................................................................ 81
Section 6.4 - Install packages ....................................................................................................................... 81
Section 6.5 - Install Edimax driver .............................................................................................................. 82
Section 6.6 - Install ROS ............................................................................................................................... 83
Section 6.7 - Wireless configuration (old version) ..................................................................................... 83
Section 6.8 - Wireless configuration ............................................................................................................ 84
Section 6.9 - SSH server config.....................................................................................................................
..................................................................................................................... 86
Section 6.10 - Create swap Space ................................................................................................................. 86
Section 6.11 - Passwordless sudo ................................................................................................................. 87
4 TABLE OF CONTENTS
Part D - Oper
Operation
ation manual - DuckietDuckietowns owns ................................................................................................... 120
Unit D -1 - Duckiet
Duckietownown parts
parts......................................................................................................................
...................................................................................................................... 121
Section 1.1 - Bill of materials......................................................................................................................
...................................................................................................................... 121
Section 1.2 - Duckies...................................................................................................................................
................................................................................................................................... 121
Section 1.3 - Floor Mats .............................................................................................................................. 122
Section 1.4 - Duck Tape .............................................................................................................................. 122
Section 1.5 - Traffic Signs............................................................................................................................
............................................................................................................................ 123
Unit D -2 - Traff
affic
ic lights P Parts
arts.....................................................................................................................
..................................................................................................................... 124
Section 2.1 - Bill of materials......................................................................................................................
...................................................................................................................... 124
Section 2.2 - Raspberry Pi...........................................................................................................................
........................................................................................................................... 124
Unit D -3 - Duckiet
Duckietownown Assembly ............................................................................................................. 125
Unit D -4 - Traff
affic
ic lights Assembly
Assembly.............................................................................................................
............................................................................................................. 126
Unit D -5 - The Duckiet
Duckietown own specif
specification
ication.................................................................................................
................................................................................................. 127
Section 5.1 - Topology ................................................................................................................................. 127
Section 5.2 - Signs placement.....................................................................................................................
..................................................................................................................... 127
Part E - Oper
Operation
ation manual - Duckiebot with LEDs ..................................................................................... 128
Unit E-1 - Acquiring the parts for the Duckiebot C1 .............................................................................. 129
Section 1.1 - Bill of materials......................................................................................................................
...................................................................................................................... 129
Section 1.2 - LEDs ....................................................................................................................................... 130
Section 1.3 - Bumpers ................................................................................................................................. 131
Section 1.4 - Headers, resistors and jumper ............................................................................................. 132
Unit E-2 - Soldering boar
boards ds for C1 ............................................................................................................ 133
Unit E-3 - Assembling the Duckiebot C1 ................................................................................................. 134
Unit E-4 - C1 (LEDs) setup ........................................................................................................................ 135
Part G - Ex
Exer
ercises
cises.............................................................................................................................................
............................................................................................................................................. 200
Unit G-1 - Ex
Exer
ercise:
cise: Git and con convventions
entions..................................................................................................
.................................................................................................. 201
Unit G-2 - Ex
Exer
ercise:
cise: R Robot
obot setup st steps
eps ...................................................................................................... 202
Section 2.1 - Milestone: (setup step)..........................................................................................................
.......................................................................................................... 202
Section 2.2 - Milestone: (setup step)..........................................................................................................
.......................................................................................................... 202
Section 2.3 - Milestone: (setup step)..........................................................................................................
.......................................................................................................... 202
Section 2.4 - Milestone: (setup step)..........................................................................................................
.......................................................................................................... 202
Section 2.5 - Milestone: Take a log with robot..........................................................................................
.......................................................................................... 202
Section 2.6 - Milestone: Calibrated robot wheels ..................................................................................... 202
Section 2.7 - Milestone: Camera calibrated .............................................................................................. 202
Unit G-3 - Ex
Exer
ercise:
cise: R ROSOS node tut tutorial
orial ..................................................................................................... 203
Section 3.1 - Skills learned..........................................................................................................................
.......................................................................................................................... 203
Section 3.2 - Instructions ............................................................................................................................ 203
Unit G-4 - Ex
Exer
ercise:
cise: Basic imag imagee oper operations
ations.............................................................................................
............................................................................................. 204
Section 4.1 - Skills learned..........................................................................................................................
.......................................................................................................................... 204
Section 4.2 - Instructions ............................................................................................................................ 204
Section 4.3 - Useful APIs ............................................................................................................................ 204
Unit G-5 - Ex
Exer
ercise:
cise: Specif
Specifications
ications and ttesting esting ........................................................................................ 205
TABLE OF CONTENTS 7
Section 5.1 - Skills learned..........................................................................................................................
.......................................................................................................................... 205
Section 5.2 - Instructions ............................................................................................................................ 205
Section 5.3 - image-ops specification.........................................................................................................
......................................................................................................... 205
Section 5.4 - Useful APIs ............................................................................................................................ 205
Section 5.5 - Testing it works with image-ops-tester .............................................................................. 205
Section 5.6 - Bottom line.............................................................................................................................
............................................................................................................................. 206
Unit G-6 - Ex
Exerercise:
cise: Who w watatches
ches the w watatchmen?
chmen? (optional)
(optional)................................................................
................................................................ 207
Section 6.1 - Skills learned..........................................................................................................................
.......................................................................................................................... 207
Section 6.2 - Instructions ............................................................................................................................ 207
Section 6.3 - image-ops-tester-tester specification ................................................................................ 207
Section 6.4 - Testing it works with image-ops-tester-tester-tester ...................................................... 207
Section 6.5 - Bottom line.............................................................................................................................
............................................................................................................................. 207
Unit G-7 - Ex
Exerercise:
cise: Simple data analysis fr from
om a bag .............................................................................. 208
Section 7.1 - Skills learned..........................................................................................................................
.......................................................................................................................... 208
Section 7.2 - Instructions ............................................................................................................................ 208
Section 7.3 - Bag analysis: bag-analyze-topic .......................................................................................... 208
Section 7.4 - Bag analysis complete: bag-analyze-all ............................................................................. 208
Section 7.5 - Useful APIs ............................................................................................................................ 209
Section 7.6 - Bag analysis............................................................................................................................
............................................................................................................................ 209
Section 7.7 - Useful APIs ............................................................................................................................ 209
Section 7.8 - Check that it works ............................................................................................................... 209
Unit G-8 - Ex
Exerercise:
cise: Bag in, bag out out...........................................................................................................
........................................................................................................... 210
Section 8.1 - Skills learned..........................................................................................................................
.......................................................................................................................... 210
Section 8.2 - Instructions ............................................................................................................................ 210
Section 8.3 - Specification for bag-copy .................................................................................................... 210
Section 8.4 - Useful new API learned........................................................................................................
........................................................................................................ 210
Section 8.5 - Bag decimate..........................................................................................................................
.......................................................................................................................... 210
Section 8.6 - Useful new APIs .................................................................................................................... 210
Section 8.7 - Check that it works ............................................................................................................... 210
Unit G-9 - Ex
Exerercise:
cise: Bag imag
images es.................................................................................................................
................................................................................................................. 211
Section 9.1 - Skills learned..........................................................................................................................
.......................................................................................................................... 211
Section 9.2 - Instructions ............................................................................................................................ 211
Unit G-10 - Ex
Exer
ercise:
cise: Use our API for argumentsarguments....................................................................................
.................................................................................... 212
Section 10.1 - Skills learned........................................................................................................................
........................................................................................................................ 212
Section 10.2 - Instructions .......................................................................................................................... 212
Section 10.3 - Useful new API learned......................................................................................................
...................................................................................................... 212
Unit G-11 - Ex
Exer
ercise:
cise: Instagr
Instagram am ffilt
ilters
ers......................................................................................................
...................................................................................................... 213
Section 11.1 - Skills learned........................................................................................................................
........................................................................................................................ 213
Section 11.2 - Instructions .......................................................................................................................... 213
Unit G-12 - Ex
Exer
ercise:
cise: Bouncing ball .......................................................................................................... 214
Section 12.1 - Skills learned........................................................................................................................
........................................................................................................................ 214
Section 12.2 - Instructions .......................................................................................................................... 214
Section 12.3 - Useful new API learned......................................................................................................
...................................................................................................... 214
Unit G-13 - Ex
Exer
ercise:
cise: Visualizing data on imag imagee...................................................................................... 215
Section 13.1 - Skills learned........................................................................................................................
........................................................................................................................ 215
Section 13.2 - Instruction............................................................................................................................
............................................................................................................................ 215
Section 13.3 - Specification for bag-mark-spots ........................................................................................ 215
Unit G-14 - Ex
Exer
ercise:
cise: Mak
Makee that int intoo a node ............................................................................................ 216
Section 14.1 - Learned skills.......................................................................................................................
....................................................................................................................... 216
Section 14.2 - Instructions .......................................................................................................................... 216
Unit G-15 - Ex
Exer
ercise:
cise: Instagr
Instagram am with EasyAlgEasyAlgoo int interface
erface.......................................................................
....................................................................... 217
Section 15.1 - Learned skills.......................................................................................................................
....................................................................................................................... 217
Section 15.2 - Instructions .......................................................................................................................... 217
Section 15.3 - See documentation..............................................................................................................
.............................................................................................................. 217
Section 15.4 - Use in your code .................................................................................................................. 217
Section 15.5 - Milestone: Illumination invariance (anti-instagram) ...................................................... 217
Unit G-16 - Ex
Exer
ercise:
cise: Launch ffilesiles basics
basics..................................................................................................
.................................................................................................. 218
Section 16.1 - Learned skills.......................................................................................................................
....................................................................................................................... 218
Unit G-17 - Ex
Exer
ercise:
cise: Unit ttests
ests..................................................................................................................
.................................................................................................................. 219
Section 17.1 - Learned skills.......................................................................................................................
....................................................................................................................... 219
8 TABLE OF CONTENTS
Part H - Softw
Softwar
aree rrefer
eference
ence ............................................................................................................................ 234
Unit H-1 - Ubuntu packaging with APT APT...................................................................................................
................................................................................................... 235
Section 1.1 - apt install ............................................................................................................................ 235
Section 1.2 - apt update .............................................................................................................................. 235
Section 1.3 - apt-key ................................................................................................................................... 235
Section 1.4 - apt-mark ................................................................................................................................. 235
Section 1.5 - add-apt-repository ................................................................................................................ 235
Section 1.6 - wajig ....................................................................................................................................... 235
Section 1.7 - dpigs ....................................................................................................................................... 235
Unit H-2 - GNU/Linux ggener eneral al notions
notions....................................................................................................
.................................................................................................... 236
Section 2.1 - Background reading .............................................................................................................. 236
Unit H-3 - Every da dayy Linux ........................................................................................................................ 237
Section 3.1 - cd ............................................................................................................................................ 237
Section 3.2 - sudo ........................................................................................................................................ 237
Section 3.3 - ls ............................................................................................................................................ 237
Section 3.4 - cp ............................................................................................................................................ 237
Section 3.5 - mkdir ....................................................................................................................................... 237
Section 3.6 - touch ....................................................................................................................................... 237
Section 3.7 - reboot ..................................................................................................................................... 237
Section 3.8 - shutdown ................................................................................................................................. 237
Section 3.9 - rm ............................................................................................................................................ 237
TABLE OF CONTENTS 9
Unit H-4 - Users .......................................................................................................................................... 238
Section 4.1 - passwd ..................................................................................................................................... 238
Unit H-5 - UNIX ttools
ools.................................................................................................................................
................................................................................................................................. 239
Section 5.1 - cat .......................................................................................................................................... 239
Section 5.2 - tee .......................................................................................................................................... 239
Section 5.3 - truncate ................................................................................................................................. 239
Unit H-6 - Linux disks and ffiles iles.................................................................................................................
................................................................................................................. 240
Section 6.1 - fdisk ....................................................................................................................................... 240
Section 6.2 - mount ....................................................................................................................................... 240
Section 6.3 - umount ..................................................................................................................................... 240
Section 6.4 - losetup ................................................................................................................................... 240
Section 6.5 - gparted ................................................................................................................................... 240
Section 6.6 - dd ............................................................................................................................................ 240
Section 6.7 - sync ........................................................................................................................................ 240
Section 6.8 - df ............................................................................................................................................ 240
Unit H-7 - Other administr
administration ation commands
commands............................................................................................
............................................................................................ 241
Section 7.1 - visudo ..................................................................................................................................... 241
Section 7.2 - update-alternatives .............................................................................................................. 241
Section 7.3 - udevadm ................................................................................................................................... 241
Section 7.4 - systemctl ................................................................................................................................ 241
Unit H-8 - Mak
Makee........................................................................................................................................... 242
Section 8.1 - make ........................................................................................................................................ 242
Unit H-9 - Python-r
Python-relat elateded ttools
ools..................................................................................................................
.................................................................................................................. 243
Section 9.1 - virtualenv .............................................................................................................................. 243
Section 9.2 - pip .......................................................................................................................................... 243
Unit H-10 - Raspberry
Raspberry-PI -PI commands
commands........................................................................................................
........................................................................................................ 244
Section 10.1 - raspi-config ........................................................................................................................ 244
Section 10.2 - vcgencmd ............................................................................................................................... 244
Section 10.3 - raspistill ............................................................................................................................ 244
Section 10.4 - jstest ................................................................................................................................... 244
Section 10.5 - swapon ................................................................................................................................... 244
Section 10.6 - mkswap ................................................................................................................................... 244
Unit H-11 - Users and permissions ........................................................................................................... 245
Section 11.1 - chmod ..................................................................................................................................... 245
Section 11.2 - groups ................................................................................................................................... 245
Section 11.3 - adduser ................................................................................................................................. 245
Section 11.4 - useradd ................................................................................................................................. 245
Unit H-12 - Downloading
Downloading...........................................................................................................................
........................................................................................................................... 246
Section 12.1 - curl ...................................................................................................................................... 246
Section 12.2 - wget ...................................................................................................................................... 246
Section 12.3 - sha256sum .............................................................................................................................. 246
Section 12.4 - xz .......................................................................................................................................... 246
Unit H-13 - Shells and en envir
vironments
onments........................................................................................................
........................................................................................................ 247
Section 13.1 - source ................................................................................................................................... 247
Section 13.2 - which ..................................................................................................................................... 247
Section 13.3 - export ................................................................................................................................... 247
Unit H-14 - Other misc commands ........................................................................................................... 248
Section 14.1 - pgrep ..................................................................................................................................... 248
Section 14.2 - npm ........................................................................................................................................ 248
Section 14.3 - nodejs ................................................................................................................................... 248
Section 14.4 - ntpdate ................................................................................................................................. 248
Section 14.5 - chsh ...................................................................................................................................... 248
Section 14.6 - echo ...................................................................................................................................... 248
Section 14.7 - sh .......................................................................................................................................... 248
Section 14.8 - fc-cache ............................................................................................................................... 248
Unit H-15 - Linux rresour
esources ces usag
usagee ............................................................................................................ 249
Section 15.1 - Measuring CPU usage using htop ..................................................................................... 249
Section 15.2 - Measuring I/O usage using iotop ..................................................................................... 249
Section 15.3 - How fast is the SD card? ..................................................................................................... 249
Unit H-16 - SD Car
Cards ds ttools
ools ......................................................................................................................... 250
10 TABLE OF CONTENTS
Part I - Softw
Softwar
aree dev
development
elopment guide ............................................................................................................. 277
Unit I-1 - Python
Python..........................................................................................................................................
.......................................................................................................................................... 278
Section 1.1 - Background reading .............................................................................................................. 278
Section 1.2 - Python virtual environments ............................................................................................... 278
Section 1.3 - Useful libraries.......................................................................................................................
....................................................................................................................... 278
Section 1.4 - Context managers..................................................................................................................
.................................................................................................................. 278
Section 1.5 - Exception hierarchies............................................................................................................
............................................................................................................ 278
Section 1.6 - Object orientation - Abstract classes, class hierarchies ..................................................... 278
Unit I-2 - Working with Y YAML
AML ffiles iles .......................................................................................................... 279
Section 2.1 - Pointers to documentation ................................................................................................... 279
Section 2.2 - Editing YAML files ................................................................................................................ 279
Section 2.3 - Reading and writing YAML files in Python........................................................................
........................................................................ 279
Section 2.4 - Duckietown wrapping API...................................................................................................
................................................................................................... 279
Unit I-3 - Duckiet
Duckietown own code con convventions .................................................................................................. 280
Section 3.1 - Python .................................................................................................................................... 280
Section 3.2 - Logging ................................................................................................................................... 281
Section 3.3 - Exceptions .............................................................................................................................. 281
Section 3.4 - Scripts ..................................................................................................................................... 281
Unit I-4 - Conf
Configur
iguration
ation..............................................................................................................................
.............................................................................................................................. 282
Section 4.1 - Environment variables..........................................................................................................
.......................................................................................................... 282
Section 4.2 - The scuderia file .................................................................................................................... 282
Section 4.3 - The machines file ................................................................................................................... 283
Section 4.4 - People database......................................................................................................................
...................................................................................................................... 283
Section 4.5 - Modes of operation................................................................................................................
................................................................................................................ 283
Unit I-5 - Node conf
configur
iguration
ation mechanisms
mechanisms..............................................................................................
.............................................................................................. 284
Unit I-6 - Minimal R ROSOS node - pkg_name .................................................................................................. 285
Section 6.1 - The files in the package ........................................................................................................ 285
Section 6.2 - Writing a node: talker.py .................................................................................................... 286
Section 6.3 - The Talker class .................................................................................................................... 288
Section 6.4 - Launch File ............................................................................................................................ 289
Section 6.5 - Testing the node .................................................................................................................... 290
Section 6.6 - Documentation......................................................................................................................
...................................................................................................................... 292
Section 6.7 - Guidelines .............................................................................................................................. 292
Unit I-7 - Mak
Makef efile
ile syst
systemem .......................................................................................................................... 293
Section 7.1 - User guide .............................................................................................................................. 293
Section 7.2 - Makefile organization ........................................................................................................... 293
Section 7.3 - Makefile help ......................................................................................................................... 294
Unit I-8 - ROS packag
packagee vverif erification
ication...........................................................................................................
........................................................................................................... 296
Section 8.1 - Naming ................................................................................................................................... 296
Section 8.2 - package.xml ............................................................................................................................ 296
Section 8.3 - Messages.................................................................................................................................
................................................................................................................................. 296
Section 8.4 - Readme file ............................................................................................................................ 296
Section 8.5 - Launch files............................................................................................................................
............................................................................................................................ 296
Section 8.6 - Test files..................................................................................................................................
.................................................................................................................................. 296
Unit I-9 - Duckiet
Duckietown own utility libr library
ary ......................................................................................................... 297
Unit I-10 - Cr
Creating
eating unit ttests ests with R ROS
OS ................................................................................................... 298
Unit I-11 - Continuous int integr
egration
ation............................................................................................................
............................................................................................................ 299
Section 11.1 - Never break the build..........................................................................................................
.......................................................................................................... 299
Section 11.2 - How to stay in the green ..................................................................................................... 299
Section 11.3 - How to make changes to master : pull requests................................................................
................................................................ 300
12 TABLE OF CONTENTS
Part J - Duckiet
Duckietown
own syst
systemem............................................................................................................................
............................................................................................................................ 304
Unit J-1 - Teleoper
eleoperation
ation .............................................................................................................................. 305
Section 1.1 - Implementation.....................................................................................................................
..................................................................................................................... 305
Section 1.2 - Camera ................................................................................................................................... 305
Section 1.3 - Actuators ................................................................................................................................ 305
Section 1.4 - IMU.........................................................................................................................................
......................................................................................................................................... 305
Unit J-2 - Par
arallel
allel aut
autonom
onomyy ...................................................................................................................... 306
Unit J-3 - Lane contr
controlol................................................................................................................................
................................................................................................................................ 307
Section 3.1 - Implementation.....................................................................................................................
..................................................................................................................... 307
Unit J-4 - Indef
Indefinit
initee na
navig
vigation
ation..................................................................................................................
.................................................................................................................. 308
Section 4.1 - Implementation.....................................................................................................................
..................................................................................................................... 308
Unit J-5 - Planning ...................................................................................................................................... 309
Section 5.1 - Implementation.....................................................................................................................
..................................................................................................................... 309
Unit J-6 - Coor
Coordination
dination...............................................................................................................................
............................................................................................................................... 310
Section 6.1 - Implementation.....................................................................................................................
..................................................................................................................... 310
Unit J-7 - Duckiet
Duckietownown R ROS
OS Guidelines .................................................................................................... 311
Section 7.1 - Node and Topics .................................................................................................................... 311
Section 7.2 - Parameters..............................................................................................................................
.............................................................................................................................. 311
Section 7.3 - Launch file ............................................................................................................................. 311
Part L - Packag
ackages
es - Infr
Infrastructur
astructuree .................................................................................................................. 326
ackagee duckietown ................................................................................................................... 327
Unit L-1 - Packag
Section 1.1 - Package information ............................................................................................................. 327
ackagee duckietown_msgs .......................................................................................................... 328
Unit L-2 - Packag
Section 2.1 - Package information ............................................................................................................. 328
ackagee easy_algo ..................................................................................................................... 329
Unit L-3 - Packag
Section 3.1 - Package information ............................................................................................................. 329
Section 3.2 - Design goals ........................................................................................................................... 329
Section 3.3 - Configuration.........................................................................................................................
......................................................................................................................... 329
ackagee easy_logs ..................................................................................................................... 330
Unit L-4 - Packag
Section 4.1 - Package information ............................................................................................................. 330
Section 4.2 - Command-line utilities.........................................................................................................
......................................................................................................... 330
Section 4.3 - Selector language...................................................................................................................
................................................................................................................... 331
Section 4.4 - Automatic log download using require ............................................................................. 332
Section 4.5 - Browsing the cloud................................................................................................................
................................................................................................................ 333
Section 4.6 - Log sets ................................................................................................................................... 333
TABLE OF CONTENTS 13
Section 4.7 - Log generation ....................................................................................................................... 334
ackagee easy_node ..................................................................................................................... 335
Unit L-5 - Packag
Section 5.1 - Package information ............................................................................................................. 335
Section 5.2 - YAML file format...................................................................................................................
................................................................................................................... 335
Section 5.3 - Using the easy_node API ...................................................................................................... 337
Section 5.4 - Configuration using easy_node : the users point of view .................................................. 341
Section 5.5 - Visualizing the configuration database...............................................................................
............................................................................... 343
Section 5.6 - Benchmarking ....................................................................................................................... 345
Section 5.7 - Automatic documentation generation ................................................................................ 346
Section 5.8 - Parameters and services defined for all packages .............................................................. 347
Section 5.9 - Other ideas ............................................................................................................................. 347
ackagee easy_regression .......................................................................................................... 348
Unit L-6 - Packag
Section 6.1 - Package information ............................................................................................................. 348
Section 6.2 - Design goals ........................................................................................................................... 348
Section 6.3 - Formalization.........................................................................................................................
......................................................................................................................... 348
Section 6.4 - Language ................................................................................................................................ 349
ackagee what_the_duck .............................................................................................................. 351
Unit L-7 - Packag
Section 7.1 - Package information ............................................................................................................. 351
Section 7.2 - Adding more tests to what-the-duck .................................................................................... 351
Section 7.3 - Tests already added ............................................................................................................... 351
Section 7.4 - List of tests to add .................................................................................................................. 352
Part M - Packag
ackageses - Lane contr
control ol ................................................................................................................... 354
ackagee adafruit_drivers ....................................................................................................... 355
Unit M-1 - Packag
Section 1.1 - Package information ............................................................................................................. 355
ackagee anti_instagram ........................................................................................................... 356
Unit M-2 - Packag
Section 2.1 - Package information ............................................................................................................. 356
Section 2.2 - Unit tests integrated with rostest ....................................................................................... 356
Section 2.3 - Unit tests needed external files ............................................................................................ 356
Section 2.4 - Node anti_instagram_node .................................................................................................... 356
ackagee dagu_car ..................................................................................................................... 358
Unit M-3 - Packag
Section 3.1 - Package information ............................................................................................................. 358
Section 3.2 - Node forward_kinematics_node ............................................................................................. 358
Section 3.3 - Node inverse_kinematics_node ............................................................................................. 358
Section 3.4 - Node velocity_to_pose_node ................................................................................................ 359
Section 3.5 - Node car_cmd_switch_node .................................................................................................... 359
Section 3.6 - Node wheels_driver_node ...................................................................................................... 359
Section 3.7 - Node wheels_trimmer_node .................................................................................................... 360
ackagee ground_projection ..................................................................................................... 361
Unit M-4 - Packag
Section 4.1 - Package information ............................................................................................................. 361
Section 4.2 - Node ground_projection_node ............................................................................................... 361
ackagee joy_mapper .................................................................................................................. 362
Unit M-5 - Packag
Section 5.1 - Package information ............................................................................................................. 362
Section 5.2 - Testing .................................................................................................................................... 362
Section 5.3 - Dependencies.........................................................................................................................
......................................................................................................................... 362
Section 5.4 - Node joy_mapper_node2 ......................................................................................................... 362
ackagee lane_control .............................................................................................................. 364
Unit M-6 - Packag
Section 6.1 - Package information ............................................................................................................. 364
Section 6.2 - lane_controller_node ............................................................................................................ 364
ackagee lane_filter ................................................................................................................ 366
Unit M-7 - Packag
Section 7.1 - Package information ............................................................................................................. 366
Section 7.2 - lane_filter_node ................................................................................................................... 366
ackagee line_detector2 ........................................................................................................... 369
Unit M-8 - Packag
Section 8.1 - Package information ............................................................................................................. 369
Section 8.2 - Testing the line detector using visual inspection ............................................................... 369
Section 8.3 - Quantitative tests...................................................................................................................
................................................................................................................... 370
Section 8.4 - line_detector_node2 .............................................................................................................. 371
ackagee line_detector ............................................................................................................ 373
Unit M-9 - Packag
Section 9.1 - Package information ............................................................................................................. 373
ackagee pi_camera ................................................................................................................. 374
Unit M-10 - Packag
14 TABLE OF CONTENTS
Part N - Packag
ackages
es - Indef
Indefinit
initee na
navig
vigation
ation......................................................................................................
...................................................................................................... 377
Unit N-1 - AprilT
AprilTags
ags libr
library
ary ....................................................................................................................... 378
Section 1.1 - Package information ............................................................................................................. 378
ackagee apriltags_ros ............................................................................................................. 380
Unit N-2 - Packag
Section 2.1 - Package information ............................................................................................................. 380
ackagee fsm ............................................................................................................................... 381
Unit N-3 - Packag
Section 3.1 - Package information ............................................................................................................. 381
Section 3.2 - Node fsm_node ....................................................................................................................... 381
ackagee indefinite_navigation ............................................................................................... 383
Unit N-4 - Packag
Section 4.1 - Package information ............................................................................................................. 383
ackagee intersection_control ................................................................................................. 384
Unit N-5 - Packag
Section 5.1 - Package information ............................................................................................................. 384
ackagee navigation .................................................................................................................. 385
Unit N-6 - Packag
Section 6.1 - Package information ............................................................................................................. 385
ackagee stop_line_filter ........................................................................................................ 386
Unit N-7 - Packag
Section 7.1 - Package information ............................................................................................................. 386
Part O - Packag
ackages
es - Localization and planning
planning.............................................................................................
............................................................................................. 387
ackagee duckietown_description ............................................................................................. 388
Unit O -1 - Packag
Section 1.1 - Package information ............................................................................................................. 388
ackagee localization ............................................................................................................... 389
Unit O -2 - Packag
Section 2.1 - Package information ............................................................................................................. 389
Part P - Packag
ackages
es - Coor
Coordination
dination ................................................................................................................... 390
ackagee led_detection .............................................................................................................. 391
Unit P-1 - Packag
Section 1.1 - Package information ............................................................................................................. 391
Section 1.2 - LED detector .......................................................................................................................... 391
Section 1.3 - Unit tests ................................................................................................................................ 391
ackagee led_emitter ................................................................................................................. 393
Unit P-2 - Packag
Section 2.1 - Package information ............................................................................................................. 393
Section 2.2 - In depth .................................................................................................................................. 393
ackagee led_interpreter .......................................................................................................... 395
Unit P-3 - Packag
Section 3.1 - Package information ............................................................................................................. 395
ackagee led_joy_mapper ............................................................................................................ 396
Unit P-4 - Packag
Section 4.1 - Package information ............................................................................................................. 396
ackagee rgb_led ........................................................................................................................ 397
Unit P-5 - Packag
Section 5.1 - Package information ............................................................................................................. 397
Section 5.2 - Demos.....................................................................................................................................
..................................................................................................................................... 397
ackagee traffic_light .............................................................................................................. 398
Unit P-6 - Packag
Section 6.1 - Package information ............................................................................................................. 398
Part Q - Packag
ackages
es - A
Additional
dditional functionality ................................................................................................ 399
ackagee mdoap ........................................................................................................................... 400
Unit Q -1 - Packag
Section 1.1 - Package information ............................................................................................................. 400
ackagee parallel_autonomy ...................................................................................................... 401
Unit Q -2 - Packag
Section 2.1 - Package information ............................................................................................................. 401
ackagee vehicle_detection ...................................................................................................... 402
Unit Q -3 - Packag
Section 3.1 - Package information ............................................................................................................. 402
Part R - Packag
ackages
es - T
Templat
emplates
es ........................................................................................................................ 403
ackagee pkg_name ...................................................................................................................... 404
Unit R-1 - Packag
TABLE OF CONTENTS 15
Section 1.1 - Package information ............................................................................................................. 404
ackagee rostest_example .......................................................................................................... 405
Unit R-2 - Packag
Section 2.1 - Package information ............................................................................................................. 405
Part S - Packag
ackages
es - Con
Convvenience .................................................................................................................... 406
ackagee duckie_rr_bridge ......................................................................................................... 407
Unit S-1 - Packag
Section 1.1 - Package information ............................................................................................................. 407
ackagee duckiebot_visualizer .................................................................................................. 408
Unit S-2 - Packag
Section 2.1 - Package information ............................................................................................................. 408
Section 2.2 - Node duckiebot_visualizer .................................................................................................. 408
ackagee duckietown_demos ......................................................................................................... 409
Unit S-3 - Packag
Section 3.1 - Package information ............................................................................................................. 409
ackagee duckietown_logs .......................................................................................................... 410
Unit S-4 - Packag
Section 4.1 - Package information ............................................................................................................. 410
Section 4.2 - Misc.........................................................................................................................................
......................................................................................................................................... 410
ackagee duckietown_unit_test .................................................................................................. 411
Unit S-5 - Packag
Section 5.1 - Package information ............................................................................................................. 411
ackagee veh_coordinator .......................................................................................................... 412
Unit S-6 - Packag
Section 6.1 - Package information ............................................................................................................. 412
Part T - Packag
ackages
es - T
Too sort .............................................................................................................................. 413
16
PARTA
ART
The Duckiet
Duckietown
own pr
project
oject
UNIT A-1
What is Duckiet
Duckietown?
own?
This video is a Duckumentary about the first version of the class, during Spring 2016.
The Duckumentary was shot by Chris Welch.
TODO: Add Duckumentary
Figure 1.1. The Duckumentary
See also this documentary by Red Hat:
The best way to get a sense of how the platform looks is to watch these videos. They
show off the capabilities of the platform.
If you would like to know more, the paper [2] describes the Duckiebot and its software.
(With 29 authors, we made the record for a robotics conference!)
TODO: add the video here that we showed at ICRA.
Can you do it by night?
Figure 2.1. Part of the first MIT class, during the final demo.
2.2. Univ
University
ersity-lev
-level
el classes in 2016
Later that year, the Duckietown platform was also used in these classes:
National Chiao Tung University 2016, Taiwan - Prof. Nick Wang;
Tsinghua University, Peoples Republic of China - Prof. (Samuel) Qing-Shan Jias
Computer Networks with Applications course;
Rennselaer Polytechnic Institute 2016 - Prof. John Wen;
2.3. Univ
University
ersity-lev
-level
el classes in 2017
In 2017, these four courses will be taught together, with the students interacting among
institutions:
ETH Zrich 2017 - Prof. Emilio Frazzoli, Dr. Andrea Censi;
University of Montreal, 2017 - Prof. Liam Paull;
TTI/Chicago 2017 - Prof. Matthew Walter; and
National Chiao Tung University, Taiwan - Prof. Nick Wang.
Furthermore, the Duckietown platform is used also in the following universities:
Rennselaer Polytechnic Institute (Jeff Trinkle)
National Chiao Tung University, Taiwan - Prof. Yon-Ping Chens Dynamic system
simulation and implementation course.
Chosun University, Korea - Prof. Woosuk Sungs course;
DUCKIETOWN HISTORY AND FUTURE 21
Petra Christian University, Indonesia - Prof. Resmana Lims Mobile Robot Design
Course
National Tainan Normal University, Taiwan - Prof. Jen-Jee Chens Vehicle to Every-
thing (V2X) course; and
Yuan Zhu University, Taiwan - Prof. Kan-Lin Hsiungs Control course.
2.4. Chile
TODO: to write
2.5. Duckiet
Duckietown
own High School
TODO: to write
22
UNIT A-3
Duckiet
Duckietown
own classes
3.1. 2016
1) Massachuset
Massachusetts
ts Institut
Institutee of T
Technology
echnology
2) National Chiao T
Tung
ung Univ
University
ersity
Location:
Course title:
Instructors: Prof. Nick Wang
DUCKIETOWN CLASSES 23
Educational Level:
Time period:
Link:
Summary:
Highlights:
3) Tsinghua Univ
University
ersity
Location:
Course title:
Instructors:
Educational Level:
Time period:
Link:
Summary:
Highlights:
4) Rennselaer P
Polyt
olytechnic
echnic Institut
Institutee
Location:
Course title:
Instructors:
Educational Level:
Time period:
Link:
Summary:
Highlights:
3.2. 2017
1) ETH Zrich
Assigned tto:
o: Censi/Tani
2) Univ
Universit
ersit de Montr
Montral
al
Location: Montreal
Course title: IFT 6080 Sujets en exploitation des ordinateurs
Instructors: Liam Paull
Educational Level: Graduate
Time period: Sept. - Dec. 2017
Link: Official Course Website
Summary: 12 students admitted spanning across Universit de Montral, cole Poly-
technic, McGill University and Concordia University
24 DUCKIETOWN CLASSES
Highlights:
3) Toy
oyota
ota T
Technological
echnological Institut
Institutee at Chicag
Chicagoo / Univ
University
ersity of Chicag
Chicagoo
Location: Chicago
Course title: TTIC 31240 Self-driving Vehicles: Models and Algorithms for Autonomy
Instructors: Matthew R. Walter
Educational Level: Undergraduate/Graduate
Time period: Sept. - Dec. 2017
Link: Official Course Website
Summary: 12 students admitted from TTI-Chicago and the University of Chicago
Highlights:
UNIT A-4
First st
steps
eps
4.2. Duckiet
Duckietown
own for instruct
instructors
ors
TODO: to write
4.3. Duckiet
Duckietown
own for self-guided learners
TODO: to write
4.4. Intr
Introduction
oduction for companies
TODO: to write
1) Gener
General
al questions
26 FIRST STEPS
Q: What is Duckietown?
Duckietown is a low-cost educational and research platform.
Q: Is Duckietown free to use?
Yes. All materials are released according to an open source license.
Q: Is everything ready?
Not quite! Please sign up to our mailing list to get notified when things are a bit more
ready.
Q: How can I start?
See the section First Steps.
Q: How can I help?
If you would like to help actively, please email duckietown@mit.edu.
3) FAQ by instruct
instructors
ors
Duckumentation documentation
28
UNIT B-1
Contributing ttoo the documentation
1.1. Wher
Wheree the documentation is
The simplest way to contribute to the documentation is to click any of the icons
next to the headers.
They link to the edit page in Github. There, one can make and commit the edits in
only a few seconds.
1.3. Comments
In the multiple-page version, each page also includes a comment box powered by a ser-
vice called Disqus. This provides a way for people to write comments with a very low
barrier. (We would periodically remove the comments.)
In the following, we are going to assume that the documentation system is installed in
~/duckuments . However, it can be installed anywhere.
We are also going to assume that you have setup a Github account with working public
keys.
We are also going to assume that you have installed the duckietown/software in ~/duckietown .
Here, note we are using git lfs clone its much faster, because it downloads the Git
LFS files in parallel.
If it fails, it means that you do not have Git LFS installed. See Unit H-26.
The command --depth 100 tells it we dont care about the whole history.
Next, we will create a virtual environment using inside the ~/duckuments directory.
Change into that directory:
$ cd ~/duckuments
Other distributions: In other distributions you might need to use venv instead of vir-
tualenv .
Activate the virtual environment:
$ source ~/duckuments/deploy/bin/activate
$ cd ~/duckuments
$ cd ~/duckuments/mcdp
$ python setup.py develop
Not
ote:
e: If you get a permission error here, it means you have not properly activated the
virtual environment.
Other distributions: If you are not on Ubuntu 16, depending on your system, you might
need to install these other dependencies:
Check befor
beforee yyou
ou continue
Make sure you have deployed and activated the virtual environment. You can
check this by checking which python is active:
$ which python
/home/user/duckuments/deploy/bin/python
Then:
$ cd ~/duckuments
$ make duckuments-dist
This creates the directory duckuments-dist , which contains another checked out copy of
the repository, but with the branch gh-pages , which is the branch that is published by
Github using the Github Pages mechanism.
Check befor
beforee yyou
ou continue
At this point, please make sure that you have these two .git folders:
~/duckuments/.git
~/duckuments/duckuments-dist/.git
./duckuments-dist/master/duckiebook/index.html
1) Incr
Incremental
emental compilation
If you want to do incremental compilation, you can omit the clean and just use:
$ make compile
This will be faster. However, sometimes it might get confused. At that point, do make
CONTRIBUTING TO THE DOCUMENTATION 31
clean .
Sympt
ymptom:
om: Invalid XML
Resolution: Markdown doesnt mean that you can put anything in a file. Except for
the code blocks, it must be valid XML. For example, if you use > and < without
quoting, it will likely cause a compile error.
Sympt
ymptom:
om: Tabs are evil
Resolution: Do not use tab characters. The error message in this case is quite helpful in
telling you exactly where the tabs are.
Sympt
ymptom:
om: The error message contains ValueError: Suspicious math fragment 'KEYMATHS000END-
KEY'
Resolution: You probably have forgotten to indent a command line by at least 4 spaces.
The dollar in the command line is now being confused for a math formula.
1.7. The w
workflow
orkflow ttoo edit documentation.
Not
ote:
e: This part is now done by a bot, so it has been removed by the documentation.
The book is published to a different repository called duckuments-dist and from there pub-
lished as book.duckietown.org .
Not
ote:
e: The dependencies below are harder to install. If you dont manage to do it, then
you only lose the ability to compile the PDF. You can do make compile to compile the
HTML version, but you cannot do make compile-pdf .
1) Installing nodejs
$ nodejs --version
6.xx
$ cd $DUCKUMENTS
$ npm install MathJax-node jsdom@9.3 less
The only pain point in the installation procedure has been the installation of nodejs
packages using npm . For some reason, they cannot be installed globally ( npm install -g ).
Do not use sudo for installation. It will cause problems.
If you use sudo , you probably have to delete a bunch of directories, such as: ~/duckuments/
node_modules , ~/.npm , and ~/.node_modules , if they exist.
3) Installing Prince
4) Installing fonts
$ fc-cache -fv
$ make compile-pdf
./duckuments-dist/master/duckiebook.pdf
UNIT B-2
Featur
eatures
es of the documentation writing syst
system
em
2.1. Mark
Markdown
down
You can use math, environment, and references. For example, take a look at
or refer to Proposition 1.
Pr
Proposition
oposition 1. (Proposition example) This is an example proposition: .
The above was written as in Listing 2.1.
You can use $\LaTeX$ math, environment, and references.
For example, take a look at
\[
x^2 = \int_0^t f(\tau)\ \text{d}\tau
\]
or refer to [](#prop:example).
\begin{proposition}[Proposition example]\label{prop:example}
This is an example proposition: $2x = x + x$.
\end{proposition}
example
\begin{definition} \label{def:lorem}
Lorem
\end{definition}
Def
Definition
inition 1. Lorem
\begin{proposition} \label{prop:lorem}
Lorem
\end{proposition}
Pr
Proposition
oposition 2. Lorem
\begin{remark} \label{rem:lorem}
Lorem
\end{remark}
Remark 1. Lorem
\begin{problem} \label{prob:lorem}
Lorem
\end{problem}
Pr
Problem
oblem 1. Lorem
\begin{example} \label{exa:lorem}
Lorem
\end{example}
Example 1. Lorem
\begin{theorem} \label{thm:lorem}
Lorem
\end{theorem}
Theor
Theorem
em 1. Lorem
FEATURES OF THE DOCUMENTATION WRITING SYSTEM 35
\begin{lemma} \label{lem:lorem}
Lorem
\end{lemma}
Lemma 1. Lorem
2.3. LaT
LaTeX
eX equations
\begin{equation}
2a = a + a \label{eq:one}
\end{equation}
\begin{align}
a &= b \label{eq:two} \\
&= c \label{eq:three}
\end{align}
Note that referring to the equations is done using the syntax \eqref{eq:name} , rather than
[](#eq:name) .
2.4. LaT
LaTeX
eX symbols
Use the syntax ![name] for describing the variables in the code.
Make sure to quote (with 4 spaces) all command lines. Otherwise, the dollar symbol
confuses the LaTeX interpreter.
2.6. Char
Charact
acter
er escapes
Use the string $ to write the dollar symbol $, otherwise it gets confused with La-
TeX math materials. Also notice that you should probably use USD to refer to U.S.
dollars.
Other symbols to escape are shown in Table 2.2.
2.7. Keyboar
eyboarddk
keys
eys
2.8. Figur
Figures
es
For any element, adding an attribute called figure-id with value fig:figure ID or tab:table
ID will create a figure that wraps the element.
For example:
Alternatively, you can put anywhere an element figcaption with ID figure id:caption :
2.9. Subf
Subfigur
igures
es
<div figure-id="fig:big">
<figcaption>Caption of big figure</figcaption>
To embed latex in your figures, you can add it directly to a file and save it as filename.svg
file and save anywhere in the /docs directory. You can run:
$ make process-svg-figs
And your svg The file will be compiled into a PDF figure with the LaTeX commands
properly interpreted. You can then include the pdf file as normal way (See Section 2.8)
using the filename.pdf as the filename in the img tag.
ure.
2.11. Short
Shortcut
cut for tables
The shortcuts col2 , col3 , col4 , col5 are expanded in tables with 2, 3, 4 or 5 columns.
The following code:
Use the classes labels-row1 and labels-row1 to make pretty tables like the following.
labels-row1 : the first row is the headers.
labels-col1 : the first column is the headers.
2) Linking fr
from
om the documentation ttoo the documentation
[](#topic ID)
See 2.12.1.
You are encouraged to put links to the documentation from the code or scripts.
To do so, use links of the form:
http://purl.org/dth/topic ID
Here dth stands for Duckietown Help. This link will get redirected to the corre-
sponding document on the website.
For example, you might have a script whose output is:
When the user clicks on the link, they will be redirected to Section 4.2.
FEATURES OF THE DOCUMENTATION WRITING SYSTEM 41
<div figure-id="fig:example-embed">
<figcaption>Cool Duckietown by night</figcaption>
<dtvideo src="vimeo:152825632"/>
</div>
2.14. Bibliogr
Bibliograph
aphyy
[](#bib:bibtex ID)
For example:
42 FEATURES OF THE DOCUMENTATION WRITING SYSTEM
If a file contains the tag move-here , the fragment pointed by the src attribute is moved at
the place of the tag.
This is used for autogenerated documentation.
Syntax:
# Node `node`
<move-here src='#package-node-autogenerated'>
2.16. Comments
You can insert comments using the HTML syntax for comments: any text between
<! and > is ignored.
# My section
TODO: todo
TODO: todo
TOWRITE: towrite
To writ
write:
e: towrite
FEATURES OF THE DOCUMENTATION WRITING SYSTEM 43
Task: task
Task: task
Assigned: assigned
Assigned tto:
o: assigned
2) Not
otes
es and rremarks
emarks
Remark: remark
Remark: remark
Note: note
Not
ote:
e: note
Symptom: symptom
Sympt
ymptom:
om: symptom
Warning: warning
Warning: warning
3) Troubleshooting
Symptom: symptom
Sympt
ymptom:
om: symptom
Resolution: resolution
Resolution: resolution
4) Guidelines
Bad: bad
bad
44 FEATURES OF THE DOCUMENTATION WRITING SYSTEM
Better: better
better
Q: question
Q: question
A: answer
Answ
Answer:
er: answer
6) Authors, maintainers, P
Point
oint of Contact
Maintainer: maintainer
Maintainer: maintainer
Author: author
Author: author
7) Refer
eferences
ences
See: see
see
Reference: reference
FEATURES OF THE DOCUMENTATION WRITING SYSTEM 45
reference
Requires: requires
Requir
equires:
es: requires
Recommended: recommended
Recommended: recommended
see also
2.18. Div en
envir
vironments
onments
1) Example usag
usagee
</div>
2) Check
</div>
Check befor
beforee yyou
ou continue
46 FEATURES OF THE DOCUMENTATION WRITING SYSTEM
3) Requir
equirements
ements
</div>
2.19. Not
otes
es and questions
There are three environments: comment, question, doubt, that result in boxes that
can be expanded by the user.
These are the one-paragraph forms:
+ comment
this is a comment on one paragraph.
+ question
this is a question on one paragraph.
+ doubt
I have my doubts on one paragraph.
A second paragraph...
</div>
+ comment
A comment
A second paragraph
FEATURES OF THE DOCUMENTATION WRITING SYSTEM 47
A second paragraph...
</div>
+ question
A question
A second paragraph
$ alternative command
A second paragraph...
</div>
+ doubt
A question
Should it not be:
$ alternative command
A second paragraph
For example, you can refer to the line containing Initialize of pkg_name/src/sub-
scriber_node.py by using the following syntax:
[link2]: github:org=duckietown,repo=Software,path=pkg_name/src/
subscriber_node.py,from_text=Initialize
For example, [this link refers to a range of lines][interval]: click it to see how Github
highlights the lines from "Initialize" to "spin".
[interval]: github:org=duckietown,repo=Software,path=pkg_name/src/
subscriber_node.py,from_text=Initialize,to_text=spin
2.21. Put
Putting
ting code fr
from
om the rreposit
epository
ory in line
In addition to referencing the files, you can also copy the contents of a file inside the
documentation.
This is done by using the tag display-file .
For example, you can put a copy of pkg_name/src/subscriber_node.py using:
<display-file src="
github:org=duckietown,
repo=Software,
path=pkg_name/src/subscriber_node.py
"/>
#!/usr/bin/env python
import rospy
# Create subscriber
subscriber = rospy.Subscriber("topic", String, callback)
<display-file src="
github:org=duckietown,
repo=Software,
path=pkg_name/src/subscriber_node.py,
from_text=Initialize,
to_text=spin
"/>
# Create subscriber
subscriber = rospy.Subscriber("topic", String, callback)
UNIT B-3
Documentation style guide
This chapter describes the conventions for writing the technical documentation.
3.1. Gener
General
al guidelines for ttechnical
echnical writing
Use either laptop or duckiebot (not capitalized, as a hostname) as the prefix for the
command line.
For example, for a command that is supposed to run on the laptop, use:
laptop $ cd ~/duckietown
It will become:
$ cd ~/duckietown
duckiebot $ cd ~/duckietown
It will become:
$ cd ~/duckietown
$ cd ~/duckietown
When the user must edit a file, just say: edit /this/file .
Writing down the command line for editing, like the following:
$ vi /this/file
1) Troubleshooting
Sympt
ymptom:
om: This strange thing happens.
Resolution: Maybe the camera is not inserted correctly. Remove and reconnect.
Sympt
ymptom:
om: This other strange thing happens.
Resolution: Maybe the plumbus is not working correctly. Try reformatting the
plumbus.
UNIT B-4
Knowledg
Knowledgee gr
graph
aph
Not
ote:
e: This chapter describes something that is not implemented yet.
4.1. Formalization
1) Atoms
Def inition 2. (Atom) An atom is a concrete resource (text, video) that is the smallest
Definition
unit that is individually addressable. It is indivisible.
Each atom as a type, as follows:
text
text/theory
text/setup
text/demo
text/exercise
text/reference
text/instructor-guide
text/quiz
video
video/lecture
video/instructable
video/screencast
video/demo
2) Semantic gr
graph
aph of at
atoms
oms
3) Modules
Because modules can contain other modules, they allow to describe hierarchical con-
tents. For example, a class module is a module that contains other modules; a degree
is a module that contains class modules, etc.
Modules can overlap. For example, a Basic Object Detection and an Advanced Ob-
ject Detection module might have a few atoms in common.
4.2. Atoms pr
properties
operties
4.3. Mark
Markdown
down format for tteext
xt-lik
-likee at
atoms
oms
This first paragraph will be used as the "summary" for this text.
In the text, you describe the semantic graph using tags and IDs.
In Markdown, you can give IDs to sections using the syntax:
Then, when you write the second step, you can add a a semantic edge using the follow-
ing.
The following table describes the syntax for the different types of semantic links:
See also See also: If you are interested in feature detection, you might want to learn about [SIFT](#SIFT
Not
ote:
e: This part is not implemented yet.
representations.md
representations.zh-CN.md
representations.it.md
representations.es.md
The reason is that in this way you can check automatically from Git whether representa-
tions.zh-CN.md is up to date or representations.md has been modified since.
Here are some considerations for the writers of the original version, to make the trans-
lators job easier.
It is better to keep files smallish so that (1) the translation tasks can feel approachable
by translators; (2) it is easier for the system to reason about the files.
Name all the headers with short, easy identifiers, and never change them.
Oper
Operation
ation manual - Duckiebot
60
UNIT C-1
Duckiebot conf
configur
igurations
ations
Here we define the different Duckiebot hardware configurations, and describe their
functionalities. This is a good starting point if you are wondering what parts you should
purchase to get started. Once you have decided which configuration best suits your
needs, you can proceed to purchasing the components for a C0+wjd or C1 Duckiebot.
1.1. Conf
Configur
iguration
ation list
1.2. Conf
Configur
iguration
ation functionality
1) C0
This is the minimal configuration for a Duckiebot. It will be able to navigate a Duck-
ietown, but not communicate with other Duckiebots. It is the configuration of choice
for tight budgets or when operation of a single Duckiebot is more of interest than fleet
behaviours.
TODO: Insert pic of assembled Duckiebot in C0 configuration.
2) C0+w
3) C0+j
In this configuration, the minimal C0 version is augmented with a 2.4 GHz wireless
joypad, used for manual remote control of the Duckiebot. It is particularly useful for
getting the Duckiebot our of tight spots or letting younger ones have a drive.
TODO: Insert pic of assembled Duckiebot in C0+j configuration.
4) C0+d
In this configuration, the minimal C0 version is augmented with a USB flash hard drive.
This drive is convenient for storing videos (logs) as it provides both extra capacity and
faster data transfer rates than the microSD card in the Raspberry Pi. Moreover, it is easy
DUCKIEBOT CONFIGURATIONS 61
to unplug it from the Duckiebot at the end of teh day and bring it over to a computer
for downloading and analyzing stored data.
TODO: Insert pic of assembled Duckiebot in C0+d configuration.
5) C0+wjd
The upgrades of the minimal C0 version are not mutually exclusive. We will refer to
C0+wjd when any or all of the add-ons to the minimal version are considered.
6) C1
This is the ultimate Duckiebot configuration and it includes the necessary hardware for
controlling and placing 5 RGB LEDs on the Duckiebot. It is the necessary configuration
to enable communication between Duckiebots, hence fleet behaviours (e.g., negotiat-
ing crossing an intersection).
TODO: Insert pic of assembled Duckiebot in C1 configuration.
62
UNIT C-2
Acquiring the parts for the Duckiebot C0
The trip begins with acquiring the parts. Here, we provide a link to all bits and pieces
that are needed to build a Duckiebot, along with their price tag. If you are wondering
what is the difference between different Duckiebot configurations, read this.
In general, keep in mind that:
The links might expire, or the prices might vary.
Shipping times and fees vary, and are not included in the prices shown below.
Substitutions are OK for the mechanical components, and not OK for all the elec-
tronics, unless you are OK in writing some software.
Buying the parts for more than one Duckiebot makes each one cheaper than buying
only one.
Requir
equires:
es: Cost: USD 159 + Shipping Fees (minimal configuration C0 )
Requir
equires:
es: Time: 15 days (average shipping for cheapest choice of components)
Results: A kit of parts ready to be assembled in a C0 or C0+wjd configuration.
Next Steps:
After receiving these components, you are ready to do some soldering before
assembling your C0 or C0+wjd Duckiebot.
TODO: Add a different Tools section in the table (e.g., solderer), or add in the re-
soruces beginning snippet; Differentiate pricing for bulk vs detail purchase (?)
2.2. Chassis
We selected the Magician Chassis as the basic chassis for the robot (Figure 2.1).
We chose it because it has a double-decker configuration, and so we can put the battery
in the lower part.
The chassis pack includes the motors and wheels as well as the structural part.
The Raspberry Pi is the central computer of the Duckiebot. Duckiebots use Model B
(Figure 2.2) (A1.2GHz 64-bit quad-core ARMv8 CPU, 1GB RAM), a small but powerful
computer.
64 ACQUIRING THE PARTS FOR THE DUCKIEBOT C0
1) Pow
ower
er Supply
We want a hard-wired power source (5VDC, 2.4A, Micro USB) to supply the Raspberry
Pi (Figure 2.3).
2) Heat Sinks
3) Class 10 Micr
MicroSD
oSD Car
Cardd
The MicroSD card (Figure 2.5) is the hard disk of the Raspberry Pi. 16 Gigabytes of ca-
pacity are sufficient for the system image.
ACQUIRING THE PARTS FOR THE DUCKIEBOT C0 65
4) Mir
Mirco
co SD car
cardd rreader
eader
A microSD card reader (Figure 2.6) is useful to copy the system image to a Duckiebot
from a computer to the Raspberry Pi microSD card, when the computer does not have
a native SD card slot.
2.4. Camer
Cameraa
The Camera is the main sensor of the Duckiebot. All versions equip a 5 Mega Pixels
1080p camera with wide field of view ( ) fisheye lens (Figure 2.7).
1) Camer
Cameraa Mount
The camera mount (Figure 2.8) serves to keep the camera looking forward at the right
angle to the road (looking slightly down). The front cover is not essential.
66 ACQUIRING THE PARTS FOR THE DUCKIEBOT C0
2) 300mm Camer
Cameraa Cable
A longer (300 mm) camera cable Figure 2.9 make assembling the Duckiebot easier, al-
lowing for more freedom in the relative positioning of camera and computational stack.
2.5. DC St
Stepper
epper Mot
Motor
or HA
HAT
T
We use the DC Stepper motor HAT (Figure 2.16) to control the DC motors that drive
the wheels. This item will require soldering to be functional.
1) Stacking Headers
We use a long 20x2 stacking header (Figure 2.11) to connect the Raspberry Pi with the
DC Stepper Motor HAT. This item will require soldering to be functional.
2.6. Bat
Batttery
We use non electrically conductive standoffs (M2.5 12mm F 6mm M), nuts (M2.5), and
screws (M2.5x10mm) to hold the Raspberry Pi to the chassis and the HATs stacked on
top of the Raspberry Pi.
The Duckiebot requires 8 standoffs, 4 nuts and 4 screws.
68 ACQUIRING THE PARTS FOR THE DUCKIEBOT C0
Two 300x5mm zip ties are needed to keep the battery at the lower deck from moving
around.
2.9. Conf
Configur ation C0-w
iguration
1) Wir
Wireless
eless A
Adapt
dapter
er (5 GHz)
The Edimax AC1200 EW-7822ULC 5 GHz wireless adpater (Figure 2.15) boosts the
connectivity of the Duckiebot, especially useful in busy Duckietowns (e.g., classroom).
2.10. Conf
Configur ation C0-j
iguration
1) Joypad
The joypad is used to manually remote control the Duckiebot. Any 2.4 GHz wireless
controller (with a tiny USB dongle) will do.
The model linked in the table (Figure 2.16) does not include batteries.
Requir
equires:
es: 2 AA 1.5V batteries.
2.11. Conf
Configur ation C0-d
iguration
1) Tin
Tinyy 32GB USB Flash Driv
Drivee
Iin configuration C0+d , the Duckiebot is equppied with a external hard drive (Figure
2.17). This add-on is very convenient to store logs during experiments and later port
them to a workstation for analysis. It provides storage capacity and faster data transfer
than the MicroSD card.
UNIT C-3
Soldering boar ds for C0
boards
Assigned tto:
o: Shiying
Resources necessary:
Requir
equires:
es: Duckiebot C0+wjd parts. The acquisition process is explained in Unit C-2.
The configurations are described in Unit C-1.
Requir
equires:
es: Time: ??? minutes
Results:
TODO: finish above
UNIT C-4
Pr
Preparing
eparing the pow er cable for C0
power
In configuration C0 we will need a cable to power the DC motor HAT from the battery.
The keen observer might have noticed that such a cable was not included in the C0
Duckiebot parts chapter. Here, we create this cable by splitting open any USB-A cable,
identifying and stripping the power wires, and using them to power the DC motor HAT.
If you are unsure about the definitions of the different Duckiebot configurations, read
Unit C-1.
It is important to note that these instructions are relevant only for assembling a C0+wjd
configuration Duckiebot. If you intend to build a C1 configuration Duckiebot, you can
skip these instructions.
Resources necessary:
Requir
equires:
es: One male USB-A to anything cable.
Requir
equires:
es: A pair of scissors.
Requir
equires:
es: A multimeter (only if you are not purchasing the suggested components)
Requir
equires:
es: Time: 5 minutes
Results: One male USB-A to wires power cable
4.1. St
Step
ep 1: Find a cable
Figure 4.1. The two USB cables in the suggested battery pack.
Put the shorter cable back in the box, and open the longer cable (Figure 4.2)
72 PREPARING THE POWER CABLE FOR C0
Figure 4.2. Take the longer cable, and put the shorter on back in the box.
4.2. St
Step
ep 2: Cut the cable
Check befor
beforee yyou
ou continue
Make sure the USB cable is unplugged from any power source before proceeding.
Take the scissors and cut it (Figure 4.3) at the desired length from the USB-A port.
4.3. St
Step
ep 3: Strip the cable
Paying attention not to get hurt, strip the external white plastic. A way to do so without
damaging the wires is shown in Figure 4.5.
PREPARING THE POWER CABLE FOR C0 73
4.4. St
Step
ep 3: Strip the wir
wires
es
Check befor
beforee yyou
ou continue
Make sure the USB cable is unplugged from any power source before proceeding.
Once you have isolated the wires, strip them, and use the scissors to cut off the data
wires (green and white, central positions) (Figure 4.8).
74 PREPARING THE POWER CABLE FOR C0
Figure 4.8. Strip the power wires and cut the data wires.
If you are not using the suggested cable, or want to verify which are the data and power
wires, continue reading.
4.5. St
Step
ep 4: Find the pow
power
er wir
wires
es
If you are using the USB-A cable from the suggested battery pack, black and red are the
power wires and green and white are instead for data.
If you are using a different USB cable, or are curious to verify that black and red actu-
ally are the power cables, take a multimeter and continue reading.
Plug the USB port inside a power source, e.g., the Duckiebots battery. You can use some
scotch tape to keep the cable from moving while probing the different pairs of wires
with a multimeter. The voltage across the pair of power cables will be roughly twice
the voltage between a power and data cable. The pair of data cables will have no volt-
age differential across them. If you are using the suggested Duckiebot battery as power
source, you will measure around 5V across the power cables (Figure 4.9).
4.6. St
Step
ep 5: T
Test
est corr
correct
ect oper
operation
ation
You are now ready to secure the power wires to the DC motor HAT power pins. To do
so though, you need to have soldered the boards first. If you have not done so yet, read
Unit C-3.
If you have soldered the boards already, you may test correct functionality of the newly
crafted cable. Connect the battery with the DC motor HAT by making sure you plug the
black wire in the pin labeled with a minus: - and the red wire to the plus: + (Figure
4.10).
PREPARING THE POWER CABLE FOR C0 75
UNIT C-5
Assembling the Duckiebot C0
Open the Duckiebox package (magician chassis DG007), and you wont need them
all. Take out the following materials: Chassis-bottom, Chassis-up (1+1 pieces) Motor (2
pieces), motor holders (4 pieces) Wheels (2 pieces), Omni wheel (1 pieces) all Spacers
and screw inside of the packages. Screwdriver (1x)
1) Mot
Motor
or + chassis bot
botttom
Insert motor holders on the chassis-bottom and put the motors as below (with the
longest screws M3*30 and M3 nuts). Ignore the speed board holder in the image.
ASSEMBLING THE DUCKIEBOT C0 77
Figure 5.3.
Figure 5.4.
Not
otee 1: Orient the motors so that its wires are inward (toward the center of the chassis-
bottom) and the black wires are closer to the chassis-bottom. This makes wiring easier
later.
Not
otee 2: if your Magician Chassis package has unsoldered motor wires, you will have
to solder them first. Check these instructions [make instructions for soldering motor
wires]. In this case, your wires will not have the male pin headers on one end. Do not
worry, you can still plug them in the stepper motor hat power terminals.
Figure 5.5.
Figure 5.6.
Figure 5.7.
Figure 5.8.
Put the car upright (omni wheel pointing towards the table) and arrange wires so that
ASSEMBLING THE DUCKIEBOT C0 79
they go through the center rectangle. Put 4 spacers with 4 of M3*6 scr
screws
ews on each cor-
ner as below.
Figure 5.9.
Figure 5.10.
Mat erials: Chassis-up, Camera and camera mount, M310 flathead screws and M3 nuts
Materials:
from the Duckiebot package. 4 M-F Nylon M3x5+6mm standoff spacers, 3x0.5mm
screws, Nylon nuts Raspberry Pi 3 Model B Soldered PWM/Servo HAT and Soldered
Stepper Motor HAT, 1 Male-male wire, * Standoffs
80
UNIT C-6
Repr
eproducing
oducing the imag
imagee
Assigned tto:
o: Andrea
These are the instructions to reproduce the Ubuntu image that we use.
Please note that the image is already available, so you dont need to do this manually.
However, this documentation might be useful if you would like to port the software to
a different distribution.
Resources necessaries:
Requir
equires:
es: Internet connection to download the packages.
Requir
equires:
es: A PC running any Linux with an SD card reader.
Requir
equires:
es: Time: about 20 minutes.
Results:
A baseline Ubuntu Mate 16.04.2 image with updated software.
filename: ubuntu-mate-16.04.2-desktop-armhf-raspberry-pi.img.xz
size: 1.2 GB
SHA256: dc3afcad68a5de3ba683dc30d2093a3b5b3cd6b2c16c0b5de8d50fede78f75c2
After download, run the command sha256sum to make sure you have the right version:
$ sha256sum ubuntu-mate-16.04.2-desktop-armhf-raspberry-pi.img.xz
dc3afcad68a5de3ba683dc30d2093a3b5b3cd6b2c16c0b5de8d50fede78f75c2
If the string does not correspond exactly, your download was corrupted. Delete the file
and try again.
Then decompress using the command xz :
$ xz -d ubuntu-mate-16.04.2-desktop-armhf-raspberry-pi.img.xz
2) Installation
language: English
username: ubuntu
password: ubuntu
hostname: duckiebot
3) Updat
Updatee installed softw
softwar
aree
The WiFi was connected to airport network duckietown with password quackquack .
Afterwards I upgraded all the software preinstalled with these commands:
$ sudo raspi-config
Editors / shells:
Git:
Other:
Development:
Python:
I2C:
Then, download and install the Edimax driver from this repository.
REPRODUCING THE IMAGE 83
6.6. Install R
ROS
OS
Install ROS.
The procedure is given in Section 28.1.
6.7. Wir
Wireless
eless conf
configur
iguration
ation (old vversion)
ersion)
auto wlan0
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="duckietown"
psk="quackquack"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}
network={
key_mgmt=NONE
}
6.8. Wir
Wireless
eless conf
configur
iguration
ation
The files that describe the network configuration are in the directory
/etc/NetworkManager/system-connections/
This is the contents of the connection file duckietown , which describes how to connect to
the duckietown wireless network:
REPRODUCING THE IMAGE 85
[connection]
id=duckietown
uuid=e9cef1bd-f6fb-4c5b-93cf-cca837ec35f2
type=wifi
permissions=
secondaries=
timestamp=1502254646
[wifi]
mac-address-blacklist=
mac-address-randomization=0
mode=infrastructure
ssid=duckietown
[wifi-security]
group=
key-mgmt=wpa-psk
pairwise=
proto=
psk=quackquack
[ipv4]
dns-search=
method=auto
[ipv6]
addr-gen-mode=stable-privacy
dns-search=
ip6-privacy=0
method=auto
/etc/NetworkManager/system-connections/create-5ghz-network
Contents:
86 REPRODUCING THE IMAGE
[connection]
id=create-5ghz-network
uuid=7331d1e7-2cdf-4047-b426-c170ecc16f51
type=wifi
# Put the Edimax interface name here:
interface-name=wlx74da38c9caa0 - to change
permissions=
secondaries=
timestamp=1502023843
[wifi]
band=a
# Put the Edimax MAC address here
mac-address=74:DA:38:C9:CA:A0 - to change
mac-address-blacklist=
mac-address-randomization=0
mode=ap
seen-bssids=
ssid=duckiebot-not-configured
[ipv4]
dns-search=
method=shared
[ipv6]
addr-gen-mode=stable-privacy
dns-search=
ip6-privacy=0
method=ignore
Note that there is an interface name and MAC address that need to be changed on each
PI.
6.10. Cr
Creat
eatee sw
swap
ap Space
Do the following:
Create an empty file using the dd (device-to-device copy) command:
$ sudo vi /etc/fstab
$ sudo swapon -a
6.11. Passw
asswor
ordless
dless sudo
$ sudo visudo
6.12. Clean up
You can use the command dpigs to find out which packages take lots of space.
Either:
88 REPRODUCING THE IMAGE
$ wajig large
$ dpigs -H -n 20
Stuff to remove:
1) Gr
Groups
oups
You should make the ubuntu user belong to the i2c and input groups:
You may need to do the following (but might be done already through raspi-config ):
Not
ote:
e: this is not in the aug10 image.
REPRODUCING THE IMAGE 89
3) Passw
asswor
ordless
dless SSH conf
config
ig
https://www.dropbox.com/s/pxyou3qy1p8m4d0/duckietown_key1.pub?dl=1
Download to .ssh/authorized_keys :
4) Shell pr
prompt
ompt
echo ""
echo "Welcome to a duckiebot!"
echo ""
echo "Reminders:"
echo ""
echo "1) Do not use the user 'ubuntu' for development - create your own user."
echo "2) Change the name of the robot from 'duckiebot' to something else."
echo ""
export EDITOR=vim
At this point, before you copy/distribute the image, create a user, install the software,
and make sure that what-the-duck does not complain about any missing package.
(Ignore what-the-duck s errors about things that are not set up yet, like users.)
6.15. Cr
Creating
eating the imag
imagee
You may now want to create an image that you can share with your friends. They will
think you are cool because they wont have to duplicate all of the work that you just
did. Luckily this is easy. Just power down the duckiebot with:
You may want to subsequently shrink the image, for example if your friends have small-
er SD cards than you.
90 REPRODUCING THE IMAGE
Note here the additions since the last image was created.
Create a file
/etc/duckietown-image.yaml
Not
ote:
e: We should install Git LFS on the Raspberry Pi, but so far AC did not have any
luck. See Section 26.1.
UNIT C-7
Installing Ubuntu on lapt
laptops
ops
Assigned tto:
o: Andrea
Before you prepare the Duckiebot, you need to have a laptop with Ubuntu installed.
Requir
equires:
es: A laptop with free disk space.
Requir
equires:
es: Internet connection to download the Ubuntu image.
Requir
equires:
es: About ??? minutes.
Results: A laptop ready to be used for Duckietown.
On the choice of username: During the installation, create a user for yourself with a
username different from ubuntu , which is the default. Otherwise, you may get confused
later.
Use byobu :
Use vim :
Other utilities:
7.3. Install R
ROS
OS
1) Redshift
This is Flux for Linux. It is an accessibility/lab safety issue: bright screens damage eyes
and perturb sleep [4].
Install redshift and run it.
Optional but very encouraged: install the duckuments system. This will allow you to
have a local copy of the documentation and easily submit questions and changes.
The procedure is documented in Section 1.4.
7.6. Passw
asswor dless sudo
ordless
2) Cr
Creat
eatee key pair for username
key
INSTALLING UBUNTU ON LAPTOPS 93
Next, create a private/public key pair for the user; call it username@robot name .
$ ssh -T git@github.com
UNIT C-8
Duckiebot Initialization
Assigned tto:
o: Andrea
Requir
equires:
es: An SD card of dimensions at least ??? GB.
Requir
equires:
es: A computer with an internet connection, an SD card reader, and 35 GB of
free space.
Requir
equires:
es: An assembled Duckiebot in configuration D17-C0 . This is the result of Unit
C-5.
Results: A Duckiebot that is ready to use.
What does it mean ready to use?.
8.1. Acquir
cquiree and burn the imag
imagee
$ xz -d -k duckiebot-RPI3-AC-aug10.img.xz
$ sha256sum duckiebot-RPI3-AC-aug10.img
2ea79b0fc6353361063c89977417fc5e8fde70611e8afa5cbf2d3a166d57e8cf duckiebot-ac-aug10.img
Compare the hash that you obtain with the hash above. If they are different, there was
some problem in downloading the image.
Next, burn the image on disk.
The procedure of how to burn an image is explained in Section 16.2.
Connect the Duckiebot and your laptop to the same network switch.
Allow 30 s - 1 minute for the DHCP to work.
2) Option 2: Duckiet
Duckietown
own netw
network
ork
The Duckiebot connects automatically to a 2.4 GHz network called duckietown and
password quackquack .
Connect your laptop to the same wireless network.
$ ping duckiebot-not-configured.local
$ ssh ubuntu@duckiebot-not-configured.local
8.6. (F
(For
or D17-
D17-C1)
C1) Conf
Configur
iguree the rrobot
obot-g
-gener
enerat
ated
ed netw
network
ork
$ iwconfig
wlxAABBCCDDEEFFGG unassociated Nickname:"rtl8822bu"
...
lo no wireless extensions.
...
$ ifconfig wlxAABBCCDDEEFFGG
wlx74da38c9caa0 Link encap:Ethernet HWaddr AA:BB:CC:DD:EE:FF:GG
/etc/NetworkManager/system-connections/create-5ghz-network
8.7. Set
Setting
ting up wir
wireless
eless netw
network
ork conf
configur
iguration
ation
/etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="duckietown"
scan_ssid=1
psk="quackquack"
priority=10
}
8.8. Updat
Updatee the syst
system
em
8.9. Giv
Givee a name ttoo the Duckiebot
8.10. Chang
Changee the hostname
/etc/hostname
/etc/hosts
127.0.0.1 localhost
127.0.1.1 robot name
Not
ote:
e: there is a command hostname that promises to change the hostname. However,
the change given by that command does not persist across reboots. You need to edit
the files above for the changes to persist.
Not
ote:
e: Never add other hostnames in /etc/hosts . It is a tempting fix when DNS does not
work, but it will cause other problems subsequently.
Then reboot the Raspberry Pi using the command
$ sudo reboot
After reboot, log in again, and run the command hostname to check that the change has
persisted:
$ hostname
robot name
If your SD card is larger than the image, youll want to expand the filesystem on your
robot so that you can use all of the space available. Achieve this with:
once rebooted you can test whether this was successful by doing
$ df -lh
DUCKIEBOT INITIALIZATION 99
You should see that the Size of your /dev/sda1 partition is close to the side of your SD
card.
8.12. Cr
Creat
eatee yyour
our user
You must not use the ubuntu user for development. Instead, you need to create a new
user.
Choose a user name, which we will refer to as username .
To create a new user:
At this point, you should be able to login to the new user from the laptop using the
password:
100 DUCKIEBOT INITIALIZATION
2) Cr
Creat
eatee key pair for username
key
Next, create a private/public key pair for the user; call it username@robot name .
$ ssh -T git@github.com
Make sure that you can login passwordlessly to your user from the laptop.
The procedure is explained in Section 18.6. In this case, we have: local
= laptop, local-user = your local user on the laptop, remote = robot name , re-
mote-user = username .
If the step is done correctly, you should be able to login from the laptop to the robot,
without typing a password:
it means you should learn more about Linux and networks, and you are setting yourself
up for failure.
Yes, you can do without, but with an additional 30 seconds of your time. The 30 sec-
onds you are not saving every time are the difference between being productive roboti-
cists and going crazy.
Really, it is impossible to do robotics when you have to think about IPs and passwords
If you know what you are doing, you are welcome to install and use additional shells,
but please keep Bash as be the default shell. This is important for ROS installation.
For the record, our favorite shell is ZSH with oh-my-zsh .
8.14. Har
Hardw
dwar
aree check: camer
cameraa
$ vcgencmd get_camera
supported=1 detected=1
If you see detected=0 , it means that the hardware connection is not working.
You can test the camera right away using a command-line utility called raspistill .
Use the raspistill command to capture the file out.jpg :
$ raspistill -t 1 -o out.jpg
1) Troubleshooting
Sympt
ymptom:
om: detected=0
Resolution: If you see detected=0 , it is likely that the camera is not connected correctly.
If you see an error that starts like this:
mmal: Cannot read camera info, keeping the defaults for OV5647
...
mmal: Camera is not detected. Please check carefully the camera module is installed correctly.
then, just like it says: Please check carefully the camera module is installed correctly..
102
UNIT C-9
Softw
Softwar
aree setup and R
RC
C rremot
emotee contr
control
ol
Assigned tto:
o: Andrea
Requir
equires:
es: Laptop configured, according to Unit C-7.
Requir
equires:
es: You have configured the Duckiebot. The procedure is documented in Unit
C-8.
Requir
equires:
es: You have created a Github account and configured public keys, both for
the laptop and for the Duckiebot. The procedure is documented in Unit H-27.
Results: You can run the joystick demo.
For the above to succeed you should have a Github account already set up.
It should not ask for a password.
1) Troubleshooting
Sympt
ymptom:
om: It asks for a password.
Resolution: You missed some of the steps described in Unit H-27.
Sympt
ymptom:
om: Other weird errors.
Resolution: Probably the time is not set up correctly. Use ntpdate as above:
$ sudo ntpdate -u us.pool.ntp.org
9.2. Set up R
ROS
OS en
envir
vironment
onment on the Duckiebot
$ cd ~/duckietown
Now we are ready to make the workspace. First you need to source the baseline ROS
environment:
$ source /opt/ros/kinetic/setup.bash
$ catkin_make -C catkin_ws/
Not
ote:
e: there is a known bug, for which it fails the first time on the Raspberry Pi. Try
again; it will work.
Plug the joystick receiver in one of the USB port on the Raspberry Pi.
To make sure that the joystick is detected, run:
$ ls /dev/input/
Check befor
beforee yyou
ou continue
Make sure that your user is in the group input and i2c :
$ groups
username sudo input i2c
If input and i2c are not in the list, you missed a step. Ohi ohi! You are not follow-
ing the instructions carefully!
Consult again Section 8.12.
$ jstest /dev/input/js0
Move the joysticks and push the buttons. You should see the data displayed change ac-
cording to your actions.
SSH into the Raspberry Pi and run the following from the duckietown directory:
104 SOFTWARE SETUP AND RC REMOTE CONTROL
$ cd ~/duckietown
$ source environment.sh
The environment.sh setups the ROS environment at the terminal (so you can use com-
mands like rosrun and roslaunch ).
Now make sure the motor shield is connected.
Run the command:
If there is no red output in the command line then pushing the left joystick knob con-
trols throttle - right controls steering.
This is the expected result of the commands:
left joystick up forward
left joystick down backward
right joystick left turn left (positive yaw)
right joystick right turn right (negative yaw)
It is possible you will have to unplug and replug the joystick or just push lots of buttons
on your joystick until it wakes up. Also make sure that the mode switch on the top of
your joystick is set to X, not D.
Is all of the above valid with the new joystick?
Close the program using Ctrl - C .
1) Troubleshooting
Sympt
ymptom:om: The robot moves weirdly (e.g. forward instead of backward).
Resolution: The cables are not correctly inserted. Please refer to the assembly guide for
pictures of the correct connections. Try swapping cables until you obtain the expected
behavior.
Resolution: Check that the joystick has the switch set to the position x.And the mode
light should be off.
Sympt
ymptom:om: The left joystick does not work.
Resolution: If the green light on the right to the mode button is on, click the mode
button to turn the light off. The mode button toggles between left joystick or the cross
on the left.
Sympt
ymptom:om: The robot does not move at all.
Resolution: The cables are disconnected.
Resolution: The program assumes that the joystick is at /dev/input/js0 . In doubt, see Sec-
tion 9.4.
9.6. The pr
proper
oper shut
shutdown
down pr
procedur
oceduree for the Raspberry Pi
Generally speaking, you can terminate any roslaunch command with Ctrl -C.
To completely shutdown the robot, issue the following command:
SOFTWARE SETUP AND RC REMOTE CONTROL 105
UNIT C-10
Reading fr
from
om the camer
cameraa
Requir
equires:
es: You have configured the Duckiebot. The procedure is documented in Unit
C-8.
Requir
equires:
es: You know the basics of ROS (launch files, roslaunch , topics, rostopic ).
TODO: put reference
Results: You know that the camera works under ROS.
10.2. Cr
Creat
eatee tw
twoo windows
In the first window, we will launch the nodes that control the camera.
Activate ROS:
$ source environment.sh
At this point, you should see the red LED on the camera light up continuously.
In the terminal you should not see any red message, but only happy messages like the
following:
READING FROM THE CAMERA 107
...
[INFO] [1502539383.948237]: [/robot name/camera_node] Initialized.
[INFO] [1502539383.951123]: [/robot name/camera_node] Start capturing.
[INFO] [1502539384.040615]: [/robot name/camera_node] Published the first image.
For more information about roslaunch and launch files, see Section 28.3.
$ source environment.sh
1) List ttopics
opics
$ rostopic list
/robot name/camera_node/camera_info
/robot name/camera_node/image/compressed
/robot name/camera_node/image/raw
/rosout
/rosout_agg
2) Show ttopics
opics fr
frequency
equency
You can use rostopic hz to see the statistics about the publishing frequency:
3) Show ttopics
opics data
You can view the messages in real time with the command rostopic echo :
You should see a large sequence of numbers being printed to your terminal.
Thats the image as seen by a machine.
If you are Neo, then this already makes sense. If you are not Neo, in Unit C-12, you will
learn how to visualize the image stream on the laptop using rviz .
use Ctrl - C to stop rostopic .
UNIT C-11
RC contr
control
ol launched rremot
emotely
ely
Assigned tto:
o: Andrea
Requir
equires:
es: You can run the joystick demo from the Raspberry Pi. The procedure is
documented in Unit C-9.
Results: You can run the joystick demo from your laptop.
11.1. Two w
waays ttoo launch a pr
progr
ogram
am
As you did on the Duckiebot, you should clone the Software repository in the ~/duckietown
directory.
The procedure is documented in Section 9.1.
You have to edit the machines files on your laptop, as you did on the Duckiebot.
The procedure is documented in Section 9.3.
Check befor
beforee yyou
ou continue
Make sure that you can login with SSH without a passw
passwor
ord
d. From the laptop,
run:
$ source environment.sh
$ roslaunch duckietown joystick.launch veh:=robot name
You should be able to drive the vehicle with joystick just like the last example. Note that
remotely launching nodes from your laptop doesnt mean that the nodes are running
on your laptop. They are still running on the Raspberry Pi in this case.
11.5. Wat
atch
ch the pr
progr am output using rqt_console
ogram
Also, you might have notice that the terminal where you launch the launch file is not
printing all the printouts like the previous example. This is one of the limitation of re-
mote launch.
Dont worry though, we can still see the printouts using rqt_console .
On the laptop, open a new terminal window, and run:
AC: I could not see any messages in rqt_console - not sure what is wrong.
You should see a nice interface listing all the printouts in real time, completed with fil-
ters that can help you find that message you are looking for in a sea of messages.
You can use Ctrl - C at the terminal where roslaunch was executed to stop all the nodes
launched by the launch file.
11.6. Troubleshooting
Sympt
ymptom:
om: roslaunch fails with an error similar to the following:
remote[robot name.local-0]: failed to launch on robot name:
Resolution: You have not followed the instructions that told you to add the HostKeyAlgo-
rithms option. Delete ~/.ssh/known_hosts and fix your configuration.
UNIT C-12
RC+camer
C+cameraa rremot
emotely
ely
Assigned tto:
o: Andrea
Requir
equires:
es: You can run the joystick demo remotely. The procedure is documented in
Unit C-11.
Requir
equires:
es: You can read the camera data from ROS. The procedure is documented in
Unit C-10.
Requir
equires:
es: You know how to get around in Byobu. You can find the Byobu tutorial in
Unit H-24.
Results: You can run the joystick demo from your laptop and see the camera image
on the laptop.
12.1. Assumptions
In the first window, launch the joystick remotely using the same procedure in Section
11.4.
$ source environment.sh
$ roslaunch duckietown joystick.launch veh:=robot name
You should be able to drive the robot with the joystick at this point.
RC+CAMERA REMOTELY 113
In the second window, we will launch the nodes that control the camera.
The launch file is called camera.launch :
$ source environment.sh
$ roslaunch duckietown camera.launch veh:=robot name
You should see the red led on the camera light up.
12.5. Thir
Thirdd window: view data flow
$ source environment.sh
$ export ROS_MASTER_URI=http://robot name.local:11311/
$ rostopic list
/diagnostics
/robot name/camera_node/camera_info
/robot name/camera_node/image/compressed
/robot name/camera_node/image/raw
/robot name/joy
/robot name/wheels_driver_node/wheels_cmd
/rosout
/rosout_agg
$ source environment.sh
$ source set_ros_master.sh robot name
$ rviz
In the rviz interface, click Add on the lower left, then the By topic tag, then select
the Image topic by the name
/robot name/camera_node/image/compressed
Then click ok. You should be able to see a live stream of the image from the camera.
114 RC+CAMERA REMOTELY
12.7. Pr
Proper
oper shut
shutdown
down pr
procedur
oceduree
To stop the nodes: You can stop the node by pressing Ctrl - C on the terminal where
roslaunch was executed. In this case, you can use Ctrl - C in the terminal where you
launched the camera.launch .
You should see the red light on the camera turn off in a few seconds.
Note that the joystick.launch is still up and running, so you can still drive the vehicle
with the joystick.
UNIT C-13
Int
Interlude:
erlude: Erg
Ergonomics
onomics
Assigned tto:
o: Andrea
So far, we have been spelling out all commands for you, to make sure that you under-
stand what is going on.
Now, we will tell you about some shortcuts that you can use to save some time.
Not
ote:
e: in the future you will have to debug problems, and these problems might be
harder to understand if you rely blindly on the shortcuts.
Requir
equires:
es: Time: ??? minutes.
Results: You will know about some useful shortcuts.
13.1. set_ros_master.sh
Instead of using:
Note that you need to use source ; without that, it will not work.
Instead of using
$ ssh my-robot
Host my-robot
User username
Hostname robot name.local
$ ping my-robot
Assigned tto:
o: Andrea
118
UNIT C-15
Camer
Cameraa calibr
calibration
ation
UNIT C-16
Taking a log
Assigned tto:
o: Andrea
120
PARTD
ART
Oper
Operation
ation manual - Duckiet
Duckietowns
owns
UNIT D -1
Duckiet
Duckietown
own parts
Duckietowns are the cities where Duckiebots drive. Here, we provide a link to all bits
and pieces that are needed to build a Duckietown, along with their price tag. Note that
while the topography of the map is highly customable, we recommend using the com-
ponents listed below. Before purchasing components for a Duckietown, read Unit D-5
to understand how Duckietowns are built.
In general, keep in mind that:
The links might expire, or the prices might vary.
Shipping times and fees vary, and are not included in the prices shown below.
Substitutions are probably not OK, unless you are OK in writing some software.
Requir
equires:
es: Cost (per ): USD ??? + Shipping Fees
Requir
equires:
es: Time: ??? days (average shipping time)
Results: A kit of parts ready to be assembled in a Duckietown.
Next Steps: Assemblying a Duckietown.
TODO: Figure out costs
1.2. Duckies
The floor mats (Figure 1.2) are the ground on which the Duckiebots drive.
We choose these mats because they have desirable surface properties, are modular, and
have the right size to be street segments. Each square is (~61x61cm) and can connect
on every side of other squares. There are 6 mats in each package.
1.4. Duck T
Tape
ape
We use duck (duct) tape of different colors (Figure 1.3) for defining the roads and their
signals. White indicates the road boundaries, yellow determines lane boundaries and
red are stop signs.
The white and red tape we use are 2 inches wide, while the yellow one is 1 inch wide.
1.5. Traff
affic
ic Signs
Traffic signs (Figure 1.4) inform Duckiebots on the map of Duckietown, allowing them
to make driving decisions.
UNIT D -2
Traff
affic
ic lights P
Parts
arts
Traffic lights regulate intersections in Duckietown. Here, we provide a link to all bits
and pieces that are needed to build a traffic light, along with their price tag. You will
need one traffic per either three, or four way intersections. The components listed be-
low meet the appearence specifications described in Unit D-5.
In general, keep in mind that:
The links might expire, or the prices might vary.
Shipping times and fees vary, and are not included in the prices shown below.
Substitutions are probably OK, if you are willing to write some software.
Requir
equires:
es: Cost: USD ?? + Shipping Fees
Requir
equires:
es: Time: ?? days (average shipping time)
Results: A kit of parts ready to be assembled in a traffic light.
Next Steps: - Assemblying a traffic light.
TODO: Estimate time and costs
2.2. Raspberry Pi
Assigned tto:
o: Shiying
126
UNIT D -4
Traff
affic
ic lights Assembly
Assigned tto:
o: Shiying
UNIT D -5
The Duckiet
Duckietown
own specif
specification
ication
Assigned tto:
o: Liam?
5.1. Topology
1) Topology constr
constraints
aints
PARTE
ART
Oper
Operation
ation manual - Duckiebot with LEDs
UNIT E-1
Acquiring the parts for the Duckiebot C1
Upgrading your C0+wjd configuration to C1 starts here, with purchasing the necessary
components. We provide a link to all bits and pieces that are needed to build a C1 Duck-
iebot, along with their price tag. If you are wondering what is the difference between
different Duckiebot configurations, read Unit C-1.
In general, keep in mind that:
The links might expire, or the prices might vary.
Shipping times and fees vary, and are not included in the prices shown below.
Buying the parts for more than one Duckiebot makes each one cheaper than buying
only one.
A few components in this configuration are custom designed, and might be trickier
to obtain.
Requir
equires:
es: A Duckiebot in C0+wjd configuration.
Requir
equires:
es: Cost: USD 77 + Bumpers manufacturing solution
Requir
equires:
es: Time: 21 Days (LED board manufacturing and shipping time)
Results: A kit of parts ready to be assembled in a C1 configuration Duckiebot.
Next Steps: - After receiving these components, you are ready to do some soldering
before assembling your C1 Duckiebot.
1.2. LEDs
The Duckiebot is equipped with 5 RGB LEDs (Figure 1.1). LEDs can be used to signal
to other Duckiebots, or just make fancy patterns.
The pack of LEDs linked in the table above holds 10 LEDs, enough for two Duckiebots.
1) LED HA
HAT
T
The LED HAT (Figure 1.2) provides an interface for our RGB LEDs and the compu-
tational stack. This board is a daughterboard for the Adafruit 16-Channel PWM/Servo
HAT, and enables connection with additional gadgets such as ADS1015 12 Bit 4 Chan-
nel ADC, Monochrome 128x32 I2C OLED graphic display, and Adafruit 9-DOF IMU
Breakout - L3GD20H+LSM303. This item will require soldering.
This board is custom degined and can only be ordered in minimum runs of 3 pieces.
The price scales down quickly with quantity, and lead times may be significant, so it is
better to buy these boards in bulk.
2) PWM/Serv
PWM/Servoo HA
HAT
T
The PWM/Servo HAT (Figure 1.3) mates to the LED HAT and provides the signals to
control the LEDs, without taking computational resources away from the Rasperry Pi
itself. This item will require soldering.
3) Pow
ower
er Cable
To power the PWM/Servo HAT from the battery, we use a short (30cm) angled male
USB-A to 5.5/2.1mm DC power jack cable (Figure 1.4).
Figure 1.4. The 30cm angled USB to 5.5/2.1mm power jack cable.
4) Male
Male-Male
-Male Jumper Wir
Wires
es
The Duckiebot needs one male-male jumper wire (Figure 1.5) to power the DC Stepper
Motor HAT from the PWM/Servo HAT.
5) Female
emale-F
-Female
emale Jumper Wir
Wires
es
20 Female-Female Jumper Wires (Figure 1.6) are necessary to connect 5 LEDs to the
LED HAT.
1.3. Bumpers
These bumpers are designed to keep the LEDs in place and are therefore used only in
configuration C1 . They are custom designed parts, so they must be produced and can-
not be bought. We used laser cutting facilities. Our design files are available [here].
132 ACQUIRING THE PARTS FOR THE DUCKIEBOT C1
Assigned tto:
o: Shiying
Resources necessary:
Requir
equires:
es: Duckiebot C1 parts. The acquisition process is explained in Unit E-1. The
configurations are described in Unit C-1.
Requir
equires:
es: Time: ??? minutes
Results:
TODO: finish above
134
UNIT E-3
Assembling the Duckiebot C1
Assigned tto:
o: Shiying
Requir
equires:
es: Duckiebot C1 parts. The acquisition process is explained in Unit E-1.
Requir
equires:
es: Soldering C1 parts. The soldering process is explained in Unit E-2.
Requir
equires:
es: Time: about ??? minutes.
TODO: estimate time.
Results:
An assembled Duckiebot in configuration C1 .
Assigned tto:
o: Andrea
136
PARTF
ART
Theory chapt
chapters
ers
Theory chapters benefit from a standardized exposition. Here, we define the template
for these chapters. Rememeber to check Unit B-2 for a comprehensive and up-to-date
list of Duckiebook supported features.
Start with a brief introduction of the discussed topic, describing its place in the bigger
picture, justifying the reading constraints/guidelines below. Write it as if the reader
knew the relevant terminology. For example:
PID control is the simplest approach to making a system behave in a desired way rather
than how it would naturally behave. It is simple because the measured output is direct-
ly feedbacked, as opposed to, e.g., the systems states. The control signal is obtained as a
weighted sum of the tracking error (Proportional term), its integral over time (Integra-
tive term) and its instantaneous derivative (Derivative term), from which the appella-
tive of PID control. The tracking error is defined as the instantaneous difference be-
tween a reference and a measured system output.
Knowledge necessary:
Required Reading: Insert here a list of topics and suggested resources related to nec-
essary knowledge in order to understand the content presented. Example:
Requir
equires:
es: Terminology: autonomy overview
Requir
equires:
es: System Modeling: basic kinematics, basic dynamics, linear algebra, State
space representations, Linear Time Invariant Systems
Suggested Reading: Insert here a list of topics and suggested resources related to rec-
ommended knowledge in order to better understand the content presented. Example:
Recommended: Definitions of Stability, Performances and Robustness: [5],
Recommended: observability/detectability and controllability/reachability: [5]
Recommended: Discrete time PID: [5]
Recommended: Bode diagrams: [5]
Recommended: Nyquist plots: [5]
Recommended: []
1.2. Pr
Problem
oblem Def
Definition
inition
In this section we crisply define the problem object of this chapter. It serves as a very
brief recap of exactly what is needed from previous atoms as well. E.g.
Let:
[]
Remember you can use the problem environment of to formally state a problem:
Pr
Problem
oblem 2. (PID) Given a system and measurements of the output
, find a set of PID coefficients that meet the specified require-
ments for: - stability, - performance, - robustness.
as shown in (Figure 1.1).
Figure 1.1. A classical block diagram for PID control. We like to use a lot of clear figures in the Duck-
iebook.
1.3. Intr
Introduced
oduced N
Notions
otions
1) Section 1: title
title-1
-1 (e.g
(e.g.:.: Def
Definitions)
initions)
Def
Definition
inition 4. (Reference signals) A reference signal is
Definition 4 is very important.
Check befor
beforee yyou
ou continue
Insert random checks to keep the readers attention up:
if you cant be woken up in the middle of the night and rememeber the definition
of , read: [5]
Def
Definition
inition 5. (Another definition) Lorem
2) Section 2: title
title-2
-2 (e.g
(e.g.:.: Output feedback)
Now that we know what were talking about, lets get in the meat of the problem. Here
CHAPTER TEMPLATE 139
is what is happening:
3) Section 3: title
title-3
-3 (e.g
(e.g.:.: T
Tuning
uning the contr
controller)
oller)
Introduce the synthesis through attempts methodology (a.k.a. tweak until death)
4) Section 4: title
title-4
-4 (e.g
(e.g.:.: P
Performance
erformance Metrics)
How do we know if the PID controller designed above is doing well? We need to define
some performance metrics first:
Overshoot, Module at resonance, Settling Time, Rising Time
[]
5) Section N: title
title-N
-N (e.g
(e.g.:.: Sa
Saving
ving the w
world
orld with PID)
1.4. Examples
This section serves as a collection of theoretical and practical examples that can clarify
part or all of the above.
1) Theor
Theoretical
etical Examples
2) Implementation Examples
1.5. Point
ointers
ers ttoo Ex
Exer
ercises
cises
Here we just add references to the suggested exercises, defined in the appropriate exer-
cise chapters.
140 CHAPTER TEMPLATE
1.6. Conclusions
1.7. Next St
Steps
eps
Strong of this new knowledge (what have we learned), we can now [].
Further Reading: insert here reference resources for the interested reader:
1.8. Refer
eferences
ences
Do not include a reference chapter. References are automatically compiled to the Bibli-
ography Section.
Author: Jacopo Maintainer: Jacopo Point of Contact: Jacopo
UNIT F-2
Symbols and con
convventions
Assigned tto:
o: Andrea
2.1. Con
Convventions
UNIT F-3
Linear alg
algebr
ebraa
3.1. Pr
Problem
oblem Def
Definition
inition
In this section we discuss vectors, matrices and linear spaces, along with their proper-
ties. Before introducing the these arguments, we need to formally define what we mean
by linearity. The word linear comes from the latin linearis, which means pertaining to
or resembling a line. You should recall that a line is represented by an equation like
, but here we intend linearity as a property of maps, so there is a little more
to linearity than lines (although lines are linear maps indeed). To avoid confusions, let
us translate the concept of linearity in mathematical language.
First, let us define a function, as a mapping between sets.
Def
Definition
inition 6. (Set) A set is a well-defined collection of distinct ele-
ments, or members of the set, , . For the time being, we assume elements
to (complex) numbers.
Def
Definition
inition 7. (Function) A function is a mapping between the sets and .
For every input element , the mapping will produce an output .
Recommended: Functions can be classified by the nature of the relationship be-
tween inputs and outputs in: injective, surjective or bijective add-ref.
TODO: add references
Def
Definition
inition 8. (Linearity) A function is linear when, , , and
:
LINEAR ALGEBRA 143
Condition is referred to as the property of homogeneity (of order 1), while condition
is referred to as additivity.
Remark 2. (Superposition Principle) Conditions and can be merged to express
the same meaning through:
3.2. Vect
ectors
ors
of components .
You can immagine a vector as a directional number, or an arrow that starts a certain
point and goes in a certain direction (in ). In this representation, the number is the
length of the arrow, or the modulus of the vector, and it can be derived through the vec-
tors components.
Def inition 10. (Length of a vector) We define the length, or modulus, of a vector
Definition
as:
Remark 3. (2-norm) Generally speaking, it is not always possible to define the length
of a vector (addref). But when it is possible (e.g., Hilbert spaces), and in Duckietown it
always is, there are many ways to define it. The most common and intuitive definition
is the Euclidian- or 2-norm, which is defined above in .
Definition of:
norms
p-norm, -norm
unit vector
144 LINEAR ALGEBRA
1) Vect
ector
or alg
algebr
ebraa
sum of vectors
dot product / inner product
3.3. cr
cross
oss pr
product
oduct
Orthogonality between vectors:
3.4. Matrices
Definitions:
matrix dimensions
flat and tall matrix
adjoint matrix
inverse matrix
rank of a matrix
condition number of a matrix (?)
identity matrix
null matrix
diagonal matrix
symmetric matrix
unit matrix
trace of a matrix
1) Matrix alg
algebr
ebraa
sum of matrices
product of matrices
matrix transpose
matrix scalar product
matrix Hadamart product
matrix concatenation
matrix-vector product
matrix power
matrix exponential
LINEAR ALGEBRA 145
Determinant:
2x2
3x3
nxn
Inverse:
general expression
Left and Right Inverse (topic for advanced-linear-algebra?):
what if the matrix is not square? (topic for advanced-linear-algebra?)
Moore-Penrose pseudo-inverse
Eigenvalues and Eigenvectors:
for square matrices
for rectangular matrices (topic for advanced-linear-algebra?)
singular value decomposition SVD (topic for advanced-linear-algebra?)
1) Fundamental spaces
Null space
Range/image
2) Pr
Preferr
eferred
ed spaces (matrix diag
diagonalization)
onalization)
show how to diagonalize matrices and why it is relevant (it will come in handy for
state space representation chapter chapter)
3.6. Examples
1) Theor
Theoretical
etical Examples
Calculate a (square) Matrix Inverse:
Find eigenvalues and eigenvectors:
Find range and null spaces of a matrix:
2) Implementation Examples
Inverting a well conditioned matrix:
Inverting a ill conditioned matrix:
3.7. Point
ointers
ers ttoo Ex
Exer
ercises
cises
Here we just add references to the suggested exercises, defined in the appropriate exer-
cise chapters.
146 LINEAR ALGEBRA
3.8. Conclusions
In this section we have defined the fundamental concept of linearity and introduced
the mathematical tools pertaining to it, in particular vectors and matrices. Moreover,
we have introduced their properties and interpretations as linear spaces.
We have found that matrices are a very convenient way to represent linear spaces, and
that the properties of the matrices such as eigenvalues and eigenvectors have important
implications in charachterizing these spaces.
These tools are useful because they are at the foundation of modeling of natural phe-
nomena. Modeling will be invaluable in understanding the behaviour of systems, and a
powerful tool to predict future behaviours of the system, and control them when need-
ed.
We have learned that
3.9. Next St
Steps
eps
[13]
Matrix cookbook
Author: Jacopo
Maintainer: Jacopo
Point of contact: Jacopo
UNIT F-4
Pr
Probability
obability basics
In this chapter we give a brief review of some basic probabilistic concepts. For a more
in-depth treatment of the subject we refer the interested reader to a textbook such as
[15].
4.1. Random V
Variables
ariables
The key underlying concept in probabilistic theory is that of an event, which is the out-
put of a random trial. Examples of an event include the result of a coin flip turning up
HEADS or the result of rolling a die turning up the number 4.
Def
Definition
inition 11. (Random Variable) A (either discrete or continuous) variable that can
take on any value that corresponds to the feasible output of a random trial.
For example, we could model the event of flipping a fair coin with the random variable
. We write the probability that takes as . The set of all pos-
sible values for the variable is its domain, . In this case,
Since can only take one of two values, it is a binary random variable. In the case of a
die roll,
and we refer to this as a discrete random variable. If the output is real value or a subset
of the real numbers, e.g., , then we refer to as a continuous random variable.
+ comment
Personally, I don't like using math formatting for letters or words that don't denote symbols,
e.g., $X = HEADS$ v.s. $X= \text{HEADS}$ - MW
Consider once again the coin tossing event. If the coin is fair, the have
. Here, the function is called the probabil-
ity mass function or pmf. The pmf is shown in Figure 4.1.
148 PROBABILITY BASICS
1) Joint Pr
Probabilities
obabilities
If we have two different RVs representing two different events and , then we repre-
sent the probability of two distinct events and both happening, which we
will denote as following: . The function is called
joint distribution.
2) Conditional Pr
Probabilities
obabilities
Again, considering that we have to RVs, and , imagine these two events are linked
in some way. For example, is the numerical output of a die roll and is the binary
even-odd output of the same die roll. Clearly these two events are linked since they are
PROBABILITY BASICS 149
both uniquely determined by the same underlying event (the rolling of the die). In this
case, we say that the RVs are dependent on one another. In the event that we know one
of events, this gives us some information about the other. We denote this using the fol-
lowing conditional distribution .
Check befor
beforee yyou
ou continue
Write down the conditional pmf for the scenario just described assuming an ora-
cle tells you that the die roll is even. In other words, what is p(x|EVEN)?
(Warning: if you think this is very easy thats good, but dont get over-confident.)
+ comment
I love editing. -AC
The joint and conditional distributions are related by the following (which could be
considered a definition of the joint distribution):
and similarly, the following could be considered a definition of the conditional distrib-
ution:
+ comment
We need to add spacing - MW
In other words, the conditional and joint distributions are inextricably linked (you cant
really talk about one without the other).
+ comment
I dont really have anything to say.
Just wanted to show the comment system.
Note that I can just go and on with my rambling; all this text will be collapsed
anyway.
(Keep this comment as an example.)
-AC
3) Ba
Bayyes R
Rule
ule
Upon closer inspection of , we can see that the choice of which variable to condition
upon is completely arbitrary. We can write:
and then after rearranging things we arrive at one of the most important formulas for
mobile robotics, Bayes rule:
150 PROBABILITY BASICS
Exactly why this formula is so important will be covered in more detail in later sections
, but we will give an initial intuition here. TODO
Consider that the variable represents something that we are trying to estimate but
cannot observe directly, and that the variable represents a physical measurement that
relates to . We want to estimate the distribution over given the measurement ,
, which is called the posterior distribution. Bayes rule lets us to do this. For every
possible state, you take the probability that this measurement could have been generat-
ed, , which is called the measurement likelihood, you multiply it by the probabil-
ity of that state being the true state, , which is called the prior, and you normalize
over the probability of obtaining that measurement from any state, , which is called
the evidence.
Check befor
beforee yyou
ou continue
From Wikipedia: Suppose a drug test has a 99% true positive rate and a 99% true
negative rate, and that we know that exactly 0.5% of people are using the drug.
Given that a persons test gives a positive result, what is the probability that this
person is actually a user of the drug.
Answer: 33.2%. This answer should surprise you. It highlights the power of the
prior.
4) Marginal Distribution
If we already have a joint distribution and we wish to recover the single variable
distribution , we must marginalize over the variable . The involves summing (for
discrete RVs) or integrating (for continuous RVs) over all values of the variable we wish
to marginalize:
This can be thought of as projecting a higher dimensional distribution onto a lower di-
mensional subspace. For example, consider Figure 4.3, which shows some data plotted
on a 2D scatter plot, and then the marginal histogram plots along each dimension of
the data.
PROBABILITY BASICS 151
4.5
3.5
y
2.5
1.5
4 4.5 5 5.5 6 6.5 7 7.5 8
x
5) Conditional Independence
Two RVs, and may be correlated, we may be able to encapsulate the dependence
through a third random variable . Therefore, if we know
Figure 4.4. A graphical representation of the conditional independence of $X$ and $Y$ given $Z$
+ comment
Is there a discussion of graphical models anywhere? Doing a good job of suffi-
ciently describing graphical models and the dependency relations that they ex-
press requires careful thought. Without it, we should refer readers to a graphical
models text (e.g., Koller and Friedman, even if it is dense)
6) Moments
7) Entr
Entropy
opy
Def inition 12. The entropy of an RV is a scalar measure of the uncertainty about the
Definition
value the RV.
A common measure of entropy is the Shannon entropy, whose value is given by
This measure originates from communication theory and literally represents how
many bits are required to transmit a distribution through a communication channel.
For many more details related to information theory we recommend [16].
As an example, we can easily write out the Shannon entropy associated with a binary
RV (e.g. flipping a coin) as a function of the probability that the coin turns up heads
(call this ):
PROBABILITY BASICS 153
where is called the mean of the distribution, and is called the standard deviation. A
plot of the 1D Gaussian was previously shown in Figure 4.2.
We will rarely deal with the univariate case and much more often deal with the multi-
variate Gaussian:
154 PROBABILITY BASICS
Assigned tto:
o: Jacopo
TODO: this is a repetition of Unit F-15.
156
UNIT F-6
Coor
Coordinat
dinatee syst
systems
ems
Assigned tto:
o: Falcon
TODO: Provide a basic description of coordinate systems. The description of general
coordinate systems should be brief, with the majority of the text focusing on Cartesian
coordinate systems (2D and 3D), polar coordinate systems, and spherical coordinate
systems.
UNIT F-7
Refer
eference
ence fr
frames
ames
Assigned tto:
o: TBD
Check befor
beforee yyou
ou continue
Required Reading: The following assumes a working familiarity with 2D and 3D
Cartesian coordinate systems. If you are not familiar with Cartesian coordinate
systems, please read the chapter on coordinate systems.
TODO: Provide a basic description of reference frames. This section is dependent upon
the coordinate systems chapter and could be moved there.
158
UNIT F-8
Transformations
Assigned tto:
o: TBD
Check befor
beforee yyou
ou continue
Required Reading: The following assumes a working familiarity with 2D and
3D Cartesian reference frames. If you are not familiar with Cartesian reference
frames, please read the chapter on reference frames.
Assigned tto:
o: Liam
In this chapter we will introduce some basic concepts ubiquitous in autonomous vehi-
cle navigation.
9.1. Aut
utonomous
onomous V
Vehicles
ehicles in the N
News
ews
These days it is hard to separate the fact from the fiction when it comes to autonomous
vehicles, particularly self-driving cars. Virtually every major car manufacturer has
pledged to deploy some form of self-driving technology in the next five years. In addi-
tion, there are many startups and software companies which are also known to be de-
veloping self-driving car technology.
Heres a non-exhaustive list of some of companies that are actively developing au-
tonomous cars:
Waymo
Tesla Autopilot project
Uber Advanced Technologies Group
Cruise Automation
Apple Project Titan (no official details released)
nuTonomy
Toyota Research Institute (Broader than just autonomous cars)
Aurora Innovation
Zoox
Audi
Nissans autonomous car
Baidu
9.2. Lev
Levels
els of A
Aut
utonom
onomyy
Before even discussing any detailed notion of autonomy, we have to specify exactly
what we are talking about. In the United States, the governing body is the NHTSA, and
they have recently (Oct 2016) redefined the so-called levels of autonomy for self-dri-
ving vehicles. In broad terms, they are as follows
Lev
Level
el 00: the human driver does everything;
Lev
Level
el 1: an automated system on the vehicle can sometimes assist the human driver
conduct some parts of the driving task;
Lev
Level
el 2: an automated system on the vehicle can actually conduct some parts of the
driving task, while the human continues to monitor the driving environment and per-
forms the rest of the driving task;
Lev
Level
el 3: an automated system can both actually conduct some parts of the driving
task and monitor the driving environment in some instances, but the human driver
must be ready to take back control when the automated system requests;
Lev
Level
el 4: an automated system can conduct the driving task and monitor the driving
environment, and the human need not take back control, but the automated system
160 AUTONOMY OVERVIEW
can operate only in certain environments and under certain conditions; and
Lev
Level
el 5: the automated system can perform all driving tasks, under all conditions
that a human driver could perform them.
The minimal basic backbone processing pipeline for autonomous vehicle navigation is
shown in Figure 9.1.
1) Sensors
AUTONOMY OVERVIEW 161
2) Ra
Raw
w Data Pr
Processing
ocessing
The raw data that is input from a sensor needs to be processed in order to become useful
and even understandandable to a human.
First, calibr
calibration
ation is usually required to convert convert units, for example from a voltage
to a physical quantity. As a simple example consider a thermometer, which measures
temperature via an expanding liquid (usually mercury). The calibration is the known
mapping from amount of expansion of liquid to temperature. In this case it is a linear
mapping and is used to put the markings on the thermometer that make it useful as a
162 AUTONOMY OVERVIEW
sensor.
We will distiguish between two fundamentally types of calibrations.
Def inition 14. (Intrinsic Calibration) An intrinsic calibration is required to determine
Definition
sensor-specific paramaters that are internal to a specific sensor.
Def inition 15. (Extrinsic Calibration) An extrinsic calibration is required to determine
Definition
the external configuration of the sensor with respect to some reference frame.
Check befor
beforee yyou
ou continue
For more information about reference frames check out Unit F-7
Calibration is very important consideration in robotics. In the field, the most advanced
algorithms will fail if sensors are not properly calibrated.
Once we have properly calibrated data in some meaningful units, we often do some
preprocessing to reduce the overall size of the data. This is true particularly for sensors
that generate a lot of data, like cameras. Rather than deal with every pixel value gen-
erated by the camera, we will process an image to generate feature-points of interest.
In ``classical computer vision many different feature descriptors have been proposed
(Harris, BRIEF, BRISK, SURF, SIFT, etc), and more recently Convolutional Neural Net-
works (CNNs) are being used to learn these features.
The important property of these features is that they should be as easily to associate as
possible across frames. In order to achieve this, the feature descriptors should be invari-
ant to nuissance parameters.
TODO: add a picture with basic feature detections
3) Stat
Statee Estimation
Now that we have used our sensors to generate a set of meaningful measurements, we
need to combine these measurements together to produce an estimate of the underly-
ing hidden state of the robot and possibly to environment.
Def
Definition
inition 16. (State) The state is a sufficient statistic of the environment, i.e. it
contains all sufficient information required for the robot to carry out its task in that en-
vironment. This can (and usually does) include the configuration of the robot itself.
What variables are maintained in the statespace depends on the problem at hand.
For example we may just be interested in a single robots configuration in the plane,
in which case . However, in other cases, such as simultaneous localization and
mapping, me may also be tracking the map in the state space.
According to Bayesian principles, any system parameters that are not fully known and
deterministic should be maintained in the state space.
In general, we do not have direct access to values in , instead we rely on our (noisy)
sensor measurements to tell us something about them, and then we infer the values.
4) Navig
vigation
ation and Planning
State->reference
AUTONOMY OVERVIEW 163
5) Contr
Control
ol
reference->control value
6) Actuation
7) Infr
Infrasctructur
asctructuree and Prior Information
9.4. Adv
dvanced
anced Building Blocks of A
Aut
utonom
onomyy
1) Object Det
Detection
ection
UNIT F-10
Aut
utonom
onomyy ar
archit
chitectur
ectures
es
Assigned tto:
o: Andrea
10.1. Contr
Contracts
acts
Assigned tto:
o: Matt
Check befor
beforee yyou
ou continue
Required Reading: The following assumes working knowledge of 2D and 3D
Cartesian coordinate systems, reference frames, and coordinate transformations.
If you are not familiar with these topics, please see the chapters on coordinate
systems, reference frames, and coordinate transformations.
Discuss
Discuss:
Introduction to the notion of state as a sufficient statistic that represents the agent
(robot) and environment.
Describe qualities: sufficient statistic; compact (i.e., not conveying unnecessary in-
formation); and readily interpretable.
Define notion of static and dynamic states.
Provide examples of robot and environment states.
The planning and control capabilities necessary for autonomy rely upon shared repre-
sentations of the agent (i.e., the robot) and the environment in which it operates. Re-
ferred to as the state, this representation consists of a compilation of all knowledge
about the robot and its environment that is sufficient both to perform a particular task
as well as to predict the future. Ignoring prior information, this knowledge is often ex-
tracted from the robots multimodal sensor streams (e.g., wheel encoders and cameras).
Consequently, a natural choice is to formulate the state as the collection of all of the
measurements that the robot acquires over time. Indeed, the use of low-level sensor
measurements as the representation of the state has a long history in robotics and arti-
ficial intelligence (cite) and has received renewed attention of-late (cite).
However, while measurement history is a sufficient representation of the robot and
its operating environment, several limitations limit its utility for planning and control.
First, measurement history is redundant within individual and across successive obser-
vations. Second, the observations contain a large amount of unnecessary information
(e.g., pixel intensities associated with clouds are not useful for self-driving vehicles).
Third, measurement history is very inefficient: its size grows linearly with time (i.e., as
the robot acquires new measurements), and it it may be computationally intractable to
access and process such a large amount of data. This motivates the desire for a minimal
representation that expresses knowledge that is both necessary and sufficient for the
robot to perform a given task. More concretely, we will consider parameterized (sym-
bolic) formulations of the state and will prefer representations that involve as small a
number of parameters as possible, subject to the constraints imposed by the task.
11.1. Pr
Preliminaries
eliminaries
Reference frames
Coordinate transformations
11.2. Robot R
Repr
epresentations
esentations
11.3. En
Envir
vironment
onment R
Repr
epresentations
esentations
Discuss:
Difference between topological and metric environment representations;
Details of topological representation;
Common metric representations, notably feature-based maps and gridmaps;
1) Duckiet
Duckietown
own En
Envir
vironment
onment R
Repr
epresentation
esentation
Assigned tto:
o: Andrea
168
UNIT F-13
Modern signal pr
processing
ocessing
Assigned tto:
o: Andrea
UNIT F-14
Basic Kinematics
Assigned tto:
o: Jacopo
170
UNIT F-15
Basic Dynamics
Assigned tto:
o: Jacopo
UNIT F-16
Odometry Calibr
Calibration
ation
Assigned tto:
o: Jacopo
172
UNIT F-17
Comput
Computer
er vision basics
Assigned tto:
o: Matt
1) Comput
Computer
er vision: What and wh
why?
y?
Topics
opics:
Objectiv
Objectivee: Discover what is present in the world, where things are, and what actions
are taking place from image sequences. In the context of robotics, this corresponds to
learning a (probabilistic) world model that encodes the robots environment, i.e., build-
ing a representation of the environment.
History of computer vision
Summer Vision Project
OCR (license plates, signs, checks, mail, etc.)
Face detection
Structure from motion
Dense reconstruction
Augmented reality
Applications to self-driving cars and beyond
2) Camer
Cameraa and Lens Geometry
Not
ote:
e: We could break this up into separate sub-sections for (prospective) projection
and lenses.
Topics
opics:
Pinhole cameras (tie into eclipse viewing, accidental cameras)
Geometry of projection: equations of projection; vanishing points; weak perspective;
orthographic projection;
Lenses: Why?; first-order optics (thin lens); thick lens
Review of 3D transformations (translation and rotation); homogeneous transforma-
tions
Perspective projection in homogeneous coordinates
3) Calibr
Calibration
ation
Not
ote:
e: The discussion of intrinsic and extrinsic models could be moved up to the
geometry subsection
Topics
Why calibration?
Intrinsic parameters: idealized perspective projection; pixel scaling (square and non-
square); offset; skew.
Intrinsic model expressed in homogeneous coordinates
Extrinsic parameters: translation and rotation of camera frame (non-homogeneous
and homogeneous)
Combined expression for intrinsic and extrinsic
Calibration targets
COMPUTER VISION BASICS 173
Calibration models
4) Imag
Imagee ffilt
iltering
ering
UNIT F-18
Illumination in
invvariance
Assigned tto:
o: Matt
UNIT F-19
Line Det
Detection
ection
Assigned tto:
o: Matt
176
UNIT F-20
Featur
eaturee eextr
xtraction
action
Assigned tto:
o: Matt
UNIT F-21
Place rrecognition
ecognition
Assigned tto:
o: Matt
178
UNIT F-22
Filt
Filtering
ering 1
Assigned tto:
o: Liam
TODO: Markov Property
TODO: Bayes Filter
TODO: Graphical representation
TODO: Kalman Filter
TODO: Extended Kalman Filter
UNIT F-23
Filt
Filtering
ering 2
Assigned tto:
o: Liam
TODO: MAP estimation
TODO: Laplace Approximation
TODO: Cholesky Decomposition?
TODO: Incrementalization - Givens Rotations - iSAM
180
UNIT F-24
Mission planning
Assigned tto:
o: ETH
UNIT F-25
Planning in discr
discret
etee domains
Assigned tto:
o: ETH
182
UNIT F-26
Motion planning
Assigned tto:
o: ETH
UNIT F-27
RR
RRT
T
Assigned tto:
o: ETH
184
UNIT F-28
Feedback contr
control
ol
Assigned tto:
o: Jacopo
UNIT F-29
PID Contr
Control
ol
Assigned tto:
o: Jacopo
186
UNIT F-30
MPC Contr
Control
ol
Assigned tto:
o: Jacopo
UNIT F-31
Object det
detection
ection
Assigned tto:
o: Nick and David
188
UNIT F-32
Object classif
classification
ication
Assigned tto:
o: Nick and David
UNIT F-33
Object tr
tracking
acking
Assigned tto:
o: Nick and David
190
UNIT F-34
Reacting ttoo obstacles
Assigned tto:
o: Jacopo
UNIT F-35
Semantic segmentation
Assigned tto:
o: Nick and David
192
UNIT F-36
Text rrecognition
ecognition
Assigned tto:
o: Nick
UNIT F-37
SLAM - Pr
Problem
oblem formulation
Assigned tto:
o: Liam
194
UNIT F-38
SLAM - Br
Broad
oad cat
categ
egories
ories
Assigned tto:
o: Liam
UNIT F-39
VINS
Assigned tto:
o: Liam
196
UNIT F-40
Adv
dvanced
anced place rrecognition
ecognition
Assigned tto:
o: Liam
UNIT F-41
Fleet lev
level
el planning (placeholder)
Assigned tto:
o: ETH
198
UNIT F-42
Fleet lev
level
el planning (placeholder)
Assigned tto:
o: ETH
UNIT F-43
Bibliogr
Bibliograph
aphyy
[1] Jacopo Tani, Liam Paull, Maria Zuber, Daniela Rus, Jonathan How, John Leonard, and Andrea Censi.
Duckiet
Duckietown:
own: an innov
innovativ
ativee way to teach aut onomyy. In EduRobotics 2016. Athens, Greece, December
autonom
2016. pdf
[2] Liam Paull, Jacopo Tani, Heejin Ahn, Javier Alonso-Mora, Luca Carlone, Michal Cap, Yu Fan Chen,
Changhyun Choi, Jeff Dusek, Daniel Hoehener, Shih-Yuan Liu, Michael Novitzky, Igor Franzoni Okuya-
ma, Jason Pazis, Guy Rosman, Valerio Varricchio, Hsueh-Cheng Wang, Dmitry Yershov, Hang Zhao,
Michael Benjamin, Christopher Carr, Maria Zuber, Sertac Karaman, Emilio Frazzoli, Domitilla Del Vec-
chio, Daniela Rus, Jonathan How, John Leonard, and Andrea Censi. Duckiet Duckietown:
own: an open, ine
inexpensiv
xpensivee
and fle
flexible
xible platform for aut
autonom
onomyy education and resear ch. In IEEE International Conference on Robot-
esearch.
ics and Automation (ICRA). Singapore, May 2017. pdf
[3] Bruno Siciliano and Oussama Khatib. Springer Handbook of Robotics. Springer-Verlag New York,
Inc., Secaucus, NJ, USA, 2007.
[4] Tosini, G., Ferguson, I., Tsubota, K. Effects of blue light on the circadian system and eye physiology.
Molecular Vision, 22, 6172, 2016 (online).
[5] Albert Einstein. Zur Elektrodynamik bewegter Krper. (German) On the electrodynamics of moving
bodies. Annalen der Physik, 322(10):891921, 1905. DOI
[13] Ivan Savov. Linear algebra explained in four pages. https://minireference.com/static/tutorials/lin-
ear_algebra_in_4_pages.pdf, 2017. Online; accessed 23 August 2017.
[12] Kaare Brandt Petersen and Michael Syskind Pedersen. The matrix cookbook. .pdf
[15] Athanasios Papoulis and S. Unnikrishna Pillai. Probability, Random Variables and Stochastic
Processes. McGraw Hill, fourth edition, 2002.
[16] David J. C. MacKay. Information Theory, Inference & Learning Algorithms. Cambridge University
Press, New York, NY, USA, 2002.
200
PARTG
ART
Ex
Exer
ercises
cises
These are the exercises - things that the students must do.
UNIT G-1
Ex
Exer
ercise:
cise: Git and con
convventions
TODO: move here the exercises we had last year about branching.
202
UNIT G-2
Ex
Exer
ercise:
cise: R
Robot
obot setup st
steps
eps
Not
ote:
e: I am not sure these go here. In any case these would be only pointers.
2.1. Milest
Milestone:
one: (setup st
step)
ep)
TODO: to write
2.2. Milest
Milestone:
one: (setup st
step)
ep)
TODO: to write
2.3. Milest
Milestone:
one: (setup st
step)
ep)
TODO: to write
2.4. Milest
Milestone:
one: (setup st
step)
ep)
TODO: to write
2.5. Milest
Milestone:
one: T
Tak
akee a log with rrobot
obot
TODO: to write
2.6. Milest
Milestone:
one: Calibr
Calibrat
ated
ed rrobot
obot wheels
TODO: to write
2.7. Milest
Milestone:
one: Camer
Cameraa calibr
calibrat
ated
ed
TODO: to write
UNIT G-3
Ex
Exer
ercise:
cise: R
ROS
OS node tut
tutorial
orial
3.2. Instructions
UNIT G-4
Ex
Exer
ercise:
cise: Basic imag
imagee oper
operations
ations
4.2. Instructions
$ image-op file
and creates a file called file.flipped.jpg that is flipped around the vertical axis.
5.2. Instructions
We give you a better specification of a program image-ops similar to the previous one.
This time, we specify exactly what should happen. This allows to do automated testing
of the script.
The program image-ops expects exactly two arguments: a filename (a JPG file) and a di-
rectory name.
If the file does not exist, the script must exit with error code 2 .
If the file cannot be decoded, the script must exit with error code 3 .
If the file exists, then the script must create:
outdir/regular.jpg : a copy of the initial file
outdir/flip.jpg : the file, flipped horizontally.
outdir/side-by-side.jpg : the two files, side by side.
If any other error occurs, the script should exit with error code 99 .
(a) The original picture. (b) The output flip.jpg (c) The output side-by-side.jpg
Figure 5.1. Example input-output for the program image-ops.
TODO: Some useful functions that you might want to use are:
We provide a script called image-ops-tester that can be used to make sure that you wrote
206 EXERCISE: SPECIFICATIONS AND TESTING
a conformant image-ops .
Use it as follows:
$ image-ops-tester candidate-image-ops
Bot
Botttom line
6.2. Instructions
$ image-ops-tester-tester candidate-image-ops-tester
Bot
Botttom line
Even if things are tested, you can never be sure that the tests themselves work.
208
UNIT G-7
Ex
Exer
ercise:
cise: Simple data analysis fr
from
om a bag
TODO: to write
7.2. Instructions
Create a program bag-analyze-all that analyzes all the topics in a bag file, and outpus the
data in YAML format.
topic:
num: ... # number of messages
period:
min:
max:
avg:
med:
Write a unit test that uses the file simple.bag , and runs your program, to checks that the
results are 1% between the following.
UNIT G-8
Ex
Exer
ercise:
cise: Bag in, bag out
Writing a bag.
8.2. Instructions
In this exercise, we start processing the data from a bag, creating another output bag in
the process.
Write a program bag-copy that reads a bag, and writes a copy of the same bag.
Write a program bag-decimate that reads a bag, and only writes a subset of the messagess.
$ bag-decimate n
This only writes 1/n messages in the output. (If n is 1, the output is the same as bag-
copy .)
None
Now process the data with bag-analyze-topic : you should see that the statistics have
changed.
UNIT G-9
Ex
Exer
ercise:
cise: Bag imag
images
es
9.2. Instructions
Write a program bag-thumbnails that creates thumbnails for some image topic in a bag
file.
output/00000.jpg
output/00001.jpg
output/00002.jpg
output/00003.jpg
output/00004.jpg
212
UNIT G-10
Ex
Exer
ercise:
cise: Use our API for arguments
10.2. Instructions
We have a useful API that makes it easy to create programs with command line argu-
ments.
TODO: to write
11.2. Instructions
Write a program bag-instagram that applier thumbnails for some image topic in a bag file.
$ bag-instagram --input bag --topic topic --filters filter names bag output
where:
topic is a topic name. Example: /topic/name
filter names is a colon-separated list of strings. Example: flip-h:grayscale .
Define the following filters:
flip-h : flips the image horizontally;
flip-v : flips the image vertically;
grayscale : make the image grayscale
sepia : make the image sepia
The filters should be applied in order to the image.
For example:
means that you first have to apply the filter flip-h , then the filter gray-scale .
214
UNIT G-12
Ex
Exer
ercise:
cise: Bouncing ball
12.2. Instructions
Create a program
13.2. Instruction
Create a program that for each image, finds the pixels that are closest to a certain color,
and creates as the output a big red, yellow white spot on them.
UNIT G-14
Ex
Exer
ercise:
cise: Mak
Makee that int
intoo a node
14.2. Instructions
Abstract the analysis above in a way that the same analysis code can be run equally
from a bag or on the laptop.
Make a ROS node and two launch files:
One runs everything on the Duckiebot, and the output is visualized on the laptop.
One runs the processing on the laptop.
UNIT G-15
Ex
Exer
ercise:
cise: Instagr
Instagram
am with EasyAlg
EasyAlgoo int
interface
erface
15.2. Instructions
Write a node using the EasyNode framework that decides which filters to run given the
configuration.
TODO: Also introduce the DUCKIETOWN_CONFIG_SEQUENCE.
15.5. Milest
Milestone:
one: Illumination in
invvariance (anti-instagr
(anti-instagram)
am)
TODO: Make them run our code, and also visualize whats going on
218
UNIT G-16
Ex
Exer
ercise:
cise: Launch ffiles
iles basics
Launch files
UNIT G-17
Ex
Exer
ercise:
cise: Unit ttests
ests
Unit tests
17.3. Unit
Unitee ttests
ests with R
ROS
OS ttests
ests
17.4. Unit
Unitee ttests
ests with compt
comptests
ests
220
UNIT G-18
Ex
Exer
ercise:
cise: P
Par
aramet
ameters
ers (standar
(standarddR
ROS
OS api)
Reading parameters
Dynamic modification of parameters
UNIT G-19
Ex
Exer
ercise:
cise: P
Par
aramet
ameters
ers (our API)
UNIT G-20
Ex
Exer
ercise:
cise: Place rrecognition
ecognition abstr
abstraction
action
20.2. Instructions
class FeatureDescription():
class AverageColor(FeatureDescription):
20.4. Bot
Botttom line
TODO: to write
UNIT G-21
Ex
Exer
ercise:
cise: P
Par
arallel
allel pr
processing
ocessing
21.2. Instructions
We introduce the support for parallel processing that we have in the APIs.
224
UNIT G-22
Ex
Exer
ercise:
cise: A
Adding
dding new ttest
est ttoo int
integr
egration
ation ttests
ests
TODO: to write
22.2. Instructions
TODO: to write
22.3. Bot
Botttom line
TODO: to write
22.4. Milest
Milestone:
one: Lane following
TODO: to write
UNIT G-23
Ex
Exer
ercise:
cise: localization
TODO: to write
23.1. Milest
Milestone:
one: N
Naavig
vigation
ation
TODO: to write
226
UNIT G-24
Ex
Exer
ercise:
cise: gr
group
oup forming
TODO: to write
24.1. Milest
Milestone:
one: Ducks in a rrow
ow
TODO: to write
UNIT G-25
Ex
Exer
ercise:
cise: Comparison of PID
TODO: to write
228
UNIT G-26
Ex
Exer
ercise:
cise: RR
RRT
T
TODO: to write
TODO: to write
26.2. Milest
Milestone:
one: Object Det
Detection
ection
TODO: to write
UNIT G-27
Ex
Exer
ercise:
cise: Object Det
Detection
ection
TODO: to write
27.1. Milest
Milestone:
one: Semantic per
perception
ception
TODO: to write
230
UNIT G-28
Ex
Exer
ercise:
cise: Semantic per
perception
ception
TODO: to write
28.1. Milest
Milestone:
one: R
Reacting
eacting ttoo obstacles
TODO: to write
UNIT G-29
Ex
Exer
ercise:
cise: R
Reacting
eacting ttoo obstacles
TODO: to write
29.1. Milest
Milestone:
one: SLAM demo
TODO: to write
232
UNIT G-30
Ex
Exer
ercise:
cise: SLAM
TODO: to write
30.1. Milest
Milestone:
one: fleet demo
TODO: to write
UNIT G-31
Ex
Exer
ercise:
cise: fleet
TODO: to write
31.1. Pr
Project
oject pr
proposals
oposals
TODO: to write
234
PARTH
ART
Softw
Softwar
aree rrefer
eference
ence
This part describes things that you should know about UNIX/Linux environments.
Documentation writers: please make sure that every command used has a section in
these chapters.
UNIT H-1
Ubuntu packaging with APT
TODO: to write
TODO: to write
1) apt dist-upgrade
1.3. apt-key
TODO: to write
1.4. apt-mark
TODO: to write
1.5. add-apt-repository
TODO: to write
1.6. wajig
TODO: to write
1.7. dpigs
TODO: to write
236
UNIT H-2
GNU/Linux ggener
eneral
al notions
Assigned tto:
o: Andrea
2.1. Back
Backgr
ground
ound rreading
eading
UNIX
Linux
free software; open source software.
UNIT H-3
Every da
dayy Linux
3.1. cd
TODO: to write
3.2. sudo
TODO: to write
3.3. ls
TODO: to write
3.4. cp
TODO: to write
3.5. mkdir
TODO: to write
3.6. touch
TODO: to write
3.7. reboot
TODO: to write
3.8. shutdown
TODO: to write
3.9. rm
TODO: to write
238
UNIT H-4
Users
4.1. passwd
TODO: to write
UNIT H-5
UNIX ttools
ools
5.1. cat
TODO: to write
5.2. tee
TODO: to write
5.3. truncate
TODO: to write
240
UNIT H-6
Linux disks and ffiles
iles
6.1. fdisk
TODO: to write
6.2. mount
TODO: to write
6.3. umount
TODO: to write
6.4. losetup
TODO: to write
6.5. gparted
TODO: to write
6.6. dd
TODO: to write
6.7. sync
TODO: to write
6.8. df
TODO: to write
UNIT H-7
Other administr
administration
ation commands
7.1. visudo
TODO: to write
7.2. update-alternatives
TODO: to write
7.3. udevadm
TODO: to write
7.4. systemctl
TODO: to write
242
UNIT H-8
Mak
Makee
8.1. make
TODO: to write
UNIT H-9
Python-r
Python-relat
elated
ed ttools
ools
9.1. virtualenv
TODO: to write
9.2. pip
TODO: to write
244
UNIT H-10
Raspberry
Raspberry-PI
-PI commands
10.1. raspi-config
TODO: to write
10.2. vcgencmd
TODO: to write
10.3. raspistill
TODO: to write
10.4. jstest
TODO: to write
10.5. swapon
TODO: to write
10.6. mkswap
TODO: to write
UNIT H-11
Users and permissions
11.1. chmod
TODO: to write
11.2. groups
TODO: to write
11.3. adduser
TODO: to write
11.4. useradd
TODO: to write
246
UNIT H-12
Downloading
12.1. curl
TODO: to write
12.2. wget
TODO: to write
12.3. sha256sum
TODO: to write
12.4. xz
TODO: to write
UNIT H-13
Shells and en
envir
vironments
onments
13.1. source
TODO: to write
13.2. which
TODO: to write
13.3. export
TODO: to write
248
UNIT H-14
Other misc commands
14.1. pgrep
TODO: to write
14.2. npm
TODO: to write
14.3. nodejs
TODO: to write
14.4. ntpdate
TODO: to write
14.5. chsh
TODO: to write
14.6. echo
TODO: to write
14.7. sh
TODO: to write
14.8. fc-cache
TODO: to write
UNIT H-15
Linux rresour
esources
ces usag
usagee
TODO: to write
Install using:
TODO: to write
Section 16.1.
250
UNIT H-16
SD Car
Cards
ds ttools
ools
Test SD Card (or any disk) speed using the following commands, which write to a file
called filename .
Note the sync and the echo command are very important.
Example results:
524288000 bytes (524 MB, 500 MiB) copied, 30.2087 s, 17.4 MB/s
524288000 bytes (524 MB, 500 MiB) copied, 23.3568 s, 22.4 MB/s
Requires:
A blank SD card.
An image file to burn.
An Ubuntu computer with an SD reader.
Results:
A burned image.
1) Finding yyour
our device name for the SD car
cardd
First, find out what is the device name for the SD card.
Insert the SD Card in the slot.
Run the command:
$ sudo fdisk -l
In this case, the device is /dev/mmcblk0 . That will be the device in the next commands.
You may see /dev/mmcblk0pX or a couple of similar entries for each partition on the card,
where X is the partition number. If you dont see anything like that, take out the SD
card and run the command again and see what disappeared.
2) Unmount partitions
Now that you know that the device is device , you can burn the image to disk.
Let the image file be image file .
Burn the image using the command dd :
Not
ote:
e: Use the name of the device, without partitions. i.e., /dev/mmcblk0 , not /dev/mm-
cblk0pX .
Requires:
An image file to burn.
An Ubuntu computer.
Results:
A shrunk image.
Not
ote:
e: Majority of content taken from here
We are going to use the tool gparted so make sure its installed
Take note of the start of the Linux partition (in our case 131072), lets call it start . Now
we are going to mount the Linux partition from the image:
In gparted click on the partition and click Resize under the Partition menu. Resize
drag the arrow or enter a size that is equal to the minimum size plus 20MB
Not
ote:
e: This didnt work well for me - I had to add much more than 20MB for it to work.
Click the Apply check mark. Before closing the final screen click through the arrows
in the dialogue box to find a line such a resize2fs -p /dev/loop0 1410048K . Take note of the
new size of your partition. Lets call it new size .
Now remove the loopback on the second partition and setup a loopback on the whole
image and run fdisk :
Not
ote:
e: on the last line include the + and the K as part of the size.
SD CARDS TOOLS 253
The kernel still uses the old table. The new table will be used at the next reboot or after
you run partprobe(8) or kpartx(8).
$ fdisk -l /dev/loop0
Note down the end of the second partition (in this case 21219327). Call this end .
You now have a shrunken image file. A further idea is to compress it:
$ xz image file
254
UNIT H-17
Netw
etworking
orking ttools
ools
Assigned tto:
o: Andrea
Preliminary reading:
Basics of networking, including
what are IP addresses
what are subnets
how DNS works
how .local names work
(ref to find).
TODO: to write
Make sure that you know:
17.1. hostname
TODO: to write
1) ping:: ar
aree yyou
ou ther
there?
e?
TODO: to write
2) ifconfig
TODO: to write
$ ifconfig
UNIT H-18
Accessing comput
computers
ers using SSH
Assigned tto:
o: Andrea
18.1. Back
Backgr
ground
ound rreading
eading
TODO: to write
Encryption
Public key authentication
~/.ssh/config
$ mkdir ~/.ssh
$ chmod 0700 ~/.ssh
HostKeyAlgorithms ssh-rsa
The reason is that Paramiko, used by roslaunch , does not support the ECSDA keys.
$ ssh remote-user@remote
1) Troubleshooting
Sympt
ymptom
om: Offending key error.
If you get something like this:
Warning: the ECDSA host key for ... differs from the key for the IP address ' ... '
18.5. Cr
Creating
eating an SSH k
keypair
eypair
This is a step that you will repeat twice: once on the Duckiebot, and once on your lap-
top.
The program will prompt you for the filename on which to save the file.
Use the convention
/home/username/.ssh/username@host name
/home/username/.ssh/username@host name.pub
where:
username is the current user name that you are using ( ubuntu or your chosen one);
host name is the name of the host (the Duckiebot or laptop);
An SSH key can be generated with the command:
$ ssh-keygen -h
/home/username/.ssh/username@host name
Then:
Press enter.
/home/username/.ssh/username@host name
The file that contains the public key has extension .pub :
/home/username/.ssh/username@host name.pub
$ touch ~/.ssh/config
IdentityFile PRIVATE_KEY_FILE
$ cat ~/.ssh/config
...
IdentityFile PRIVATE_KEY_FILE
...
Assumptions:
You have two computers, called local and remote , with users local-user
and remote-user .
The two computers are on the same network.
You have created a keypair for local-user on local .
This procedure is described in Section 18.5.
Results:
From the local computer, local-user will be able to log in to remote computer
without a password.
First, connect the two computers to the same network, and make sure that you can ping
remote from local :
/home/local-user/.ssh/local-user@local.pub
You will have to copy the contents of this file on the remote computer, to tell it that this
key is authorized.
On the remote computer, edit or create the file:
/home/remote-user/.ssh/authorized_keys
and add the entire line as above containing the public key.
Now, from the local computer, try to log in into the remote one:
This should succeed, and you should not be asked for a password.
Sometimes, SSH does not work because you have the wrong permissions on some files.
In doubt, these lines fix the permissions for your .ssh directory.
18.8. ssh-keygen
TODO: to write
260
UNIT H-19
Wir
Wireless
eless netw
networking
orking in Linux
19.1. iwconfig
TODO: to write
19.2. iwlist
1) Get
Getting
ting a list of WiFi netw
networks
orks
2) Do I ha
havve 5 GHz?
Example output:
Note that in this example only some 5Ghz channels are supported (36, 40, 44, 48, 149,
153, 157, 161, 165); for example, channel 38, 42, 50 are not supported. This means that
you need to set up the router not to use those channels.
262
UNIT H-20
Moving ffiles
iles betw
between
een comput
computers
ers
20.1. SCP
TODO: to write
1) Download a ffile
ile with SCP
TODO: to write
20.2. RS
RSync
ync
TODO: to write
UNIT H-21
VIM
Assigned tto:
o: Andrea
To do quick changes to files, especially when logged remotely, we suggest you use the
VI editor, or more precisely, VIM (VI iMproved).
21.1. Ext
External
ernal documentation
A VIM tutorial.
21.2. Installation
21.3. vi
TODO: to write
21.4. Sugg
Suggest
ested
ed conf
configur
iguration
ation
Suggested ~/.vimrc :
syntax on
set number
filetype plugin indent on
highlight Comment ctermfg=Gray
autocmd FileType python set complete isk+=.,(
TODO: to write
TODO: to write
266
UNIT H-23
Eclipse
TODO: to write
TODO: to write
UNIT H-24
Byobu
Assigned tto:
o: Andrea
You need to learn to use Byobu. It will save you much time later.
(Alternatives such as GNU Screen are fine as well.)
24.1. Adv
dvantag
antages
es of using B
Byyobu
TODO: To write
24.2. Installation
24.3. Documentation
You can change the escape sequence from Ctrl - A to something else by using the con-
figuration tool that appears when you type F9 .
Commands to use windows:
Previous window F3
Next window F4
24.5. Commands on OS X
Assigned tto:
o: Andrea
25.1. Back
Backgr
ground
ound rreading
eading
TODO: to write
Git
GitFlow
25.2. Installation
25.3. Set
Setting
ting up global conf
configur
igurations
ations for Git
This should be done twice, once on the laptop, and later, on the robot.
These options tell Git who you are:
Also do this, and it doesnt matter if you dont know what it is:
1) Shallow clone
25.5. Git tr
troubleshooting
oubleshooting
1) Pr
Problem
oblem 1: ht
https
tps inst
instead
ead of ssh:
$ git push
Username for 'https://github.com':
$ git remote -v
origin https://github.com/duckietown/Software.git (fetch)
origin https://github.com/duckietown/Software.git (push)
Expectation:
$ git remote -v
origin git@github.com:duckietown/Software.git (fetch)
origin git@github.com:duckietown/Software.git (push)
Solution:
Solution:
25.6. git
TODO: to write
UNIT H-26
Git LFS
Not
ote:
e: unresolved issues.
The instructions above do not work.
Following this, the error that appears is that golang on the Pi is 1.6 instead it should be
1.7.
1) Troubleshooting
Sympt
ymptom:
om: The binary files are not downloaded. In their place, there are short point-
er files.
If you have installed LFS after pulling the repository and you see only the pointer files,
do:
UNIT H-27
Setup Github access
Assigned tto:
o: Andrea
This chapter describes how to create a Github account and setup SSH on the robot and
on the laptop.
27.1. Cr
Creat
eatee a Github account
Figure 27.1
Go to your inbox and verify the email.
Give the administrators your account name. They will invite you.
Accept the invitation to join the organization that you will find in your email.
You will do this procedure twice: once for the public key created on the laptop, and
later with the public key created on the robot.
Requires:
A public/private keypair already created and configured.
This procedure is explained in Section 18.5.
Result:
You can access Github using the key provided.
SETUP GITHUB ACCESS 273
Figure 27.2
Add the public key that you created:
Figure 27.3
Figure 27.4
Figure 27.5
To check that all of this works, use the command
$ ssh -T git@github.com
The command tries to connect to Github using the private keys that you specified. This
is the expected output:
Warning: Permanently added the RSA host key for IP address ' ip address' to the list of known
hosts.
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
UNIT H-28
ROS installation and rrefer
eference
ence
Assigned tto:
o: Liam
28.1. Install R
ROS
OS
This part installs ROS. You will run this twice, once on the laptop, once on the robot.
The first commands are copied from this page.
Tell Ubuntu where to find ROS:
Tell Ubuntu that you trust the ROS people (they are nice folks):
Notote:
e: Do not install packages by the name of ros-X , only those by the name of ros-ki-
netic-X . The packages ros-X are from another version of ROS.
: not done in aug20 image:
Initialize ROS:
28.2. rqt_console
ROS INSTALLATION AND REFERENCE 275
TODO: to write
28.3. roslaunch
TODO: to write
28.4. rviz
TODO: to write
28.5. rostopic
TODO: to write
1) rostopic hz
TODO: to write
2) rostopic echo
TODO: to write
28.6. catkin_make
TODO: to write
28.7. rosrun
TODO: to write
28.8. rostest
TODO: to write
28.9. rospack
TODO: to write
28.10. rosparam
TODO: to write
276 ROS INSTALLATION AND REFERENCE
28.11. rosdep
TODO: to write
28.12. roswtf
TODO: to write
28.13. rosbag
28.14. roscore
TODO: to write
28.15. Troubleshooting R
ROS
OS
Sympt
ymptom:
om: computer is not in your SSH known_hosts file
See this thread. Remove the known_hosts file and make sure you have followed the in-
structions in Section 18.3.
Softw
Softwar
aree dev
development
elopment guide
UNIT I-1
Python
1.1. Back
Backgr
ground
ound rreading
eading
Python
Python tutorial
Install using:
matplotlib
seaborne
numpy
panda
scipy
opencv
...
1.4. Cont
Conteext manag
managers
ers
TODO: to write
1.5. Ex
Exception
ception hier
hierar
archies
chies
TODO: to write
TODO: to write
UNIT I-2
Working with Y
YAML
AML ffiles
iles
YAML files are useful for writing configuration files, and are used a lot in Duckietown.
2.1. Point
ointers
ers ttoo documentation
TODO: to write
2.2. Editing Y
YAML
AML ffiles
iles
TODO: to write
2.4. Duckiet
Duckietown
own wr
wrapping
apping API
TODO: to write
280
UNIT I-3
Duckiet
Duckietown
own code con
convventions
3.1. Python
1) Tabs
2) Spaces
Indentation is 4 spaces.
3) Line lengths
All files must have an encoding declared, and this encoding must be utf-8 :
5) Sha-bang lines
#!/usr/bin/env python
6) Comments
Comments, better:
DUCKIETOWN CODE CONVENTIONS 281
3.2. Logging
3.3. Ex
Exceptions
ceptions
DTConfigException
raise_wrapped
compact = True
3.4. Scripts
def summary():
fs = get_all_configuration_files()
if __name__ == '__main__':
wrap_script_entry_point(summary)
1) Imports
UNIT I-4
Conf
Configur
iguration
ation
This chapter explains what are the assumptions about the configuration.
While the Setup parts are imperative (do this, do that); this is the declarative part,
which explains what are the properties of a correct configuration (but it does not ex-
plain how to get there).
he tool what-the-duck (Subsection 7.1.3) checks some of these conditions. If you make a
change from the existing conditions, make sure that it gets implemented in what-the-duck
by filing an issue.
4.1. En
Envir
vironment
onment vvariables
ariables
1) Duckiet
Duckietown
own rroot
oot dir
direct ory DUCKIETOWN_ROOT
ectory
TODO: to write
2) Duckiefleet dir
direct ory DUCKIEFLEET_ROOT
ectory
${DUCKIEFLEET_ROOT}/scuderia.yaml
robot-name:
username: username
owner_duckietown_id: owner duckietown ID
emma:
username: andrea
owner_duckietown_id: censi
Assigned tto:
o: Andrea
TODO: Describe the people database; this is the evolution of the yaml files
1) The globally
globally-unique
-unique Duckiet
Duckietown
own ID
UNIT I-5
Node conf
configur
iguration
ation mechanisms
TODO: Where the config files are, how they are used.
UNIT I-6
Minimal R OS node - pkg_name
ROS
Assigned tto:
o: Andrea
This document outline the process of writing a ROS package and nodes in Python.
To follow along, it is recommend that you duplicate the pkg_name folder and edit the con-
tent of the files to make your own package.
1) CMakeLists.txt
For a Python package, you only have to pay attention to the following parts.
The line:
project(pkg_name)
You will have to specify the packages on which your package is dependent.
In Duckietown, most packages depend on duckietown_msgs to make use of the customized
messages.
The line:
catkine_python_setup()
2) package.xml
3) setup.py
setup_args = generate_distutils_setup(
packages=['pkg_name'],
package_dir={'': 'include'},
)
The parameter is set to a list of strings of the name of the folders inside the in-
packages
clude folder.
The convention is to set the folder name the same as the package name. Here its the
include/pkg_name folder.
You should put ROS-independent and/or reusable module (for other packages) in the
include/pkg_name folder.
Python files in this folder (for example, the util.py ) will be available to scripts in the
catkin workspace (this package and other packages too).
To use these modules from other packages, use:
1) Header
Header:
MINIMAL ROS NODE - PKG_NAME 287
#!/usr/bin/env python
import rospy
# Imports module. Not limited to modules in this package.
from pkg_name.util import HelloGoodbye
# Imports msg
from std_msgs.msg import String
The first line, #!/usr/bin/env python , specifies that the script is written in Python.
Every ROS node in Python must start with this line.
The line import rospy imports the rospy module necessary for all ROS nodes in Python.
The line from pkg_name.util import HelloGoodbye imports the class HelloGoodbye defined in the
file pkg_name/util.py.
Note that you can also include modules provided by other packages, if you specify the
dependency in CMakeLists.txt and package.xml .
The line from std_msgs.msg import String imports the String message defined in the std_msgs
package.
Note that you can use rosmsg show std_msgs/String in a terminal to lookup the definition of
String.msg .
2) Main
if __name__ == '__main__':
# Initialize the node with rospy
rospy.init_node('talker', anonymous=False)
1) Construct
Constructor
or
self.node_name = rospy.get_name()
The line:
defines a publisher which publishes a String message to the topic ~topic_a . Note that the
~ in the name of topic under the namespace of the node. More specifically, this will ac-
tually publishes to talker/topic_a instead of just topic_a . The queue_size is usually set to 1
on all publishers.
For more details see rospy overview: publisher and subscribers.
The line:
defines a subscriber which expects a String message and subscribes to ~topic_b . The
message will be handled by the self.cbTopic callback function. Note that similar to the
publisher, the ~ in the topic name puts the topic under the namespace of the node. In
this case the subscriber actually subscribes to the topic talker/topic_b .
It is strongly encouraged that a node always publishers and subscribes to topics under
their node_name namespace. In other words, always put a ~ in front of the topic names
when you defines a publisher or a subscriber. They can be easily remapped in a launch
file. This makes the node more modular and minimizes the possibility of confusion and
naming conflicts. See the launch file section for how remapping works.
The line
Sets the value of self.pub_timestep to the value of the parameter ~pub_timestep . If the para-
meter doesnt exist (not set in the launch file), then set it to the default value 1.0 . The
setupParameter function also writes the final value to the parameter server. This means
that you can rosparam list in a terminal to check the actual values of parameters being
set.
The line:
defines a timer that calls the self.cbTimer function every self.pub_timestep seconds.
2) Timer callback
Contents:
def cbTimer(self,event):
singer = HelloGoodbye()
# Simulate hearing something
msg = String()
msg.data = singer.sing("duckietown")
self.pub_topic_name.publish(msg)
3) Subscriber callback
Contents:
def cbTopic(self,msg):
rospy.loginfo("[%s] %s" %(self.node_name,msg.data))
Every time a message is published to ~topic_b , the cbTopic function is called. It simply
prints the messae using rospy.loginfo .
You should always write a launch file to launch a node. It also serves as a documenta-
tion on the I/O of the node.
Lets take a look at launch/test.launch .
<launch>
<node name="talker" pkg="pkg_name" type="talker.py" output="screen">
For the <node> , the name specify the name of the node, which overwrites rospy.init_node()
in the __main__ of talker.py . The pkg and type specify the package and the script of the
node, in this case its talke.py .
Dont forget the .py in the end (and remember to make the file executable through
chmod ).
The output="screen" direct all the rospy.loginfo to the screen, without this you wont see
any printouts (useful when you want to suppress a node thats too talkative.)
The <param> can be used to set the parameters. Here we set the ~pub_timestep to 0.5 . Note
that in this case this sets the value of talker/pub_timestep to 0.5 .
The <remap> is used to remap the topic names. In this case we are replacing ~topic_b with
~topic_a so that the subscriber of the node actually listens to its own publisher. Replace
the line with
will have the same effect. This is redundant in this case but very useful when you want
to subscribe to a topic published by another node.
First of all, you have to catkin_make the package even if it only uses Python. catkin makes
sure that the modules in the include folder and the messages are available to the whole
workspace. You can do so by
$ cd ${DUCKIETOWN_ROOT}/catkin_ws
$ catkin_make
Ask ROS to re-index the packages so that you can auto-complete most things.
$ rospack profile
SUMMARY
========
PARAMETERS
* /rosdistro: $ROS_DISTRO
* /rosversion: 1.11.16
* /talker/pub_timestep: 0.5
NODES
/
talker (pkg_name/talker.py)
$ rostopic list
/rosout
/rosout_agg
/talker/topic_a
292 MINIMAL ROS NODE - PKG_NAME
$ rosparam list
6.6. Documentation
You should document the parameters and the publish/subscribe topic names of each
node in your package. The user should not have to look at the source code to figure out
how to use the nodes.
6.7. Guidelines
Make sure to put all topics (publish or subscribe) and parameters under the name-
space of the node with ~ . This makes sure that the IO of the node is crystal clear.
Always include the name of the node in the printouts.
Always provide a launch file that includes all the parameters (using <param> ) and top-
ics (using <remap> ) with each node.
UNIT I-7
Mak
Makef
efile
ile syst
system
em
Assigned tto:
o: Andrea
We use Makefiles to describe frequently-used commands.
The command
$ make all
displays the help for each command. This help is also included here as Section 7.3.
7.2. Mak
Makef
efile
ile org
organization
anization
There is one Makefile at the root of the Software repository, which includes other make-
files in the directory Makefiles/ :
Makefile
Makefiles/
Makefile.build.mk
Makefile.demos.mk
Makefile.docker.mk
Makefile.generate.mk
Makefile.hw_test.mk
Makefile.maintenance.mk
Makefile.openhouse.mk
Makefile.stats.mk
Makefile.test.mk
Makefile.section.mk
The output should be valid Markdown, so that it can be included in this documenta-
tion.
7.3. Mak
Makef
efile
ile help
1) Statistics
2) Testing
3) Building commands
4) Dock
Docker
er commands
5) Aut
utomat
omated
ed ffiles
iles ggener
eneration
ation
Generation of documentation
make generate-all : Generates everything.
make generate-help : Generates help.
make generate-easy_node : Generates the easy node documentation.
make generate-easy_node-clean : Cleans the generated files.
6) Demos
7) Har
Hardw
dwar
aree ttests
ests
8) Maint
Maintenance
enance
UNIT I-8
ROS packag
packagee vverif
erification
ication
Assigned tto:
o: Andrea
This chapter describes formally what makes a conforming ROS package in the Ducki-
etown software architecture.
8.1. Naming
8.2. package.xml
8.3. Messag
Messages
es
TODO: to write
UNIT I-9
Duckiet
Duckietown
own utility libr
library
ary
The functions called d8n_??? have stable interface and can be reused.
298
UNIT I-10
Cr
Creating
eating unit ttests
ests with R
ROS
OS
11.1. Nev
ever
er br
break
eak the build
The system enforces the constraint that the branch master is always green, by preventing
changes to the branches that make the tests fail.
We use a service called CircleCI. This service continuously looks at our repositories.
Whenever there is a change, it downloads the repositories and runs the tests.
(It was a lot of fun to set up all of this, but fortunately you do not need to know how it
is done.)
At this page you can see the summary of the tests. (You need to be logged in with your
Github account and click authorize Github).
300 CONTINUOUS INTEGRATION
general concept.
1) Troubleshooting
If you see a message like merge failed (Figure 11.9), it probably means that somebody
pushed into master; merge master into your branch and continue the process.
PARTJ
ART
Duckiet
Duckietown
own syst
system
em
1.1. Implementation
Drivers:
Unit M-1 - Package adafruit_drivers
Unit M-10 - Package pi_camera
Operator interface:
Unit M-5 - Package joy_mapper
1.2. Camer
Cameraa
TODO: to write
1.3. Actuat
ctuators
ors
TODO: to write
1.4. IMU
TODO: to write
306
UNIT J-2
Par
arallel
allel aut
autonom
onomyy
TODO: to write
UNIT J-3
Lane contr
control
ol
3.1. Implementation
Perception:
Unit M-2 - Package anti_instagram
Unit M-4 - Package ground_projection
Unit M-9 - Package line_detector , Unit M-8 - Package line_detector2
Unit M-7 - Package lane_filter
Control:
Unit M-6 - Package lane_control
+ Ref. error
Not found '#car_supervisor' (also tried sec:car_supervisor, sub:car_supervisor,
subsub:car_supervisor, fig:car_supervisor, tab:car_supervisor, code:car_supervisor,
app:car_supervisor, appsub:car_supervisor, appsubsub:car_supervisor, def:car_supervisor,
eq:car_supervisor, rem:car_supervisor, lem:car_supervisor, prob:car_supervisor,
prop:car_supervisor, exa:car_supervisor, thm:car_supervisor)
Unit M-3 - Package dagu_car
308
UNIT J-4
Indef
Indefinit
initee na
navig
vigation
ation
4.1. Implementation
5.1. Implementation
UNIT J-6
Coor
Coordination
dination
6.1. Implementation
ros::NodeHandle nh_("~");
sub_lineseglist_ = nh_.subscribe("lineseglist_in", 1, &GroundProjection::lineseglist_cb, this);
pub_lineseglist_ = nh_.advertise<duckietown_msgs::SegmentList> ("lineseglist_out", 1);
7.2. Par
aramet
ameters
ers
Each node must have a launch file with the same name in the launch folder of the pack-
age. ex: joy_mapper.py must have a joy_mapper.launch . These are referred to as the elemental
launch files.
Each elemental launch file must only launch one node.
The elemental launch file should put the node under the correct namespace through
the veh arg, load the correct configuration and parameter file throught config and
param_file_name args respectively. veh must not have a default value. This is to ensure the
user to always provide the veh arg. config must be default to baseline and param_file_name
must be default to default .
When a node can be run on the vehicle or on a laptop, the elemental launch file should
provide a local arg. When set to true, the node must be launch on the launching ma-
chine, when set to false, the node must be launch on a vehicle throught the mahcine at-
tribute.
A node should always be launched by calling its corresponding launch file instead of
using rosrun . This ensures that the node is put under the correct namespace and all the
necessary parameters are provided.
312 DUCKIETOWN ROS GUIDELINES
Fall 2017
This is the first time that a class is taught jointly across 3 continents!
There are 4 universities involved in the joint teaching for the term:
ETH Zrich (ETHZ), with instructors Emilio Frazzoli, Andrea Censi, Jacopo Tani.
University of Montreal (UdeM), with instructor Liam Paull.
TTI-Chicago (TTIC), with instructor Matthew Walter.
National C T University (NCTU), with instructor Nick Wang.
This part of the Duckiebook describes all the information that is needed by the students
of the four institutions.
314
UNIT K-1
Gener
General
al rremarks
emarks
Assigned tto:
o: Andrea
The ffirst
irst rule of Duckiet
Duckietown
own
The first rule of Duckietown is: you dont talk about Duckietown, using email.
Instead, we use a communication platform called Slack.
There is one exception: inquiries about meta level issues, such as course enrollment
and other official bureaucratic issues can be communicated via email.
The second rule of Duckiet
Duckietown
own
The second rule of Duckietown is: be kind and respectful, and have fun.
The thir
thirdd rule of Duckiet
Duckietown
own
The third rule of Duckietown is: read the instructions carefully.
Do not blindly copy and paste.
Only run a command if you know what it does.
1.2. Synchr
ynchronization
onization betw
between
een classes
At ETHZ, UdeM, TTIC, the class will be more-or-less synchronized. The materials are
the same; there is some slight variation in the ordering.
Moreover, there will be some common groups for the projects.
The NCTU class is undergraduate level. Students will learn slightly simplified materi-
als. They will not collaborate directly with the classes.
To participate in Duckietown, students must use two accounts: Slack and Github.
1) Slack
2) Github
As an instructor/TA for the Fall 2017 class, in addition to the accounts above, these are
two more accounts that you need.
1) Twist
2) Google docs
UNIT K-2
Guide for E
ETH
TH Zrich students
Assigned tto:
o: Andrea
This section describes information specific for ETH Zrich students.
TODO: to write
1) Websit
ebsitee
2) Duckiebo
Duckieboxx distribution
TODO: to write
3) Lab access
TODO: To write
4) The local T
TAs
As
TODO: to write
UNIT K-3
Guide for U
UdeM
deM students
Assigned tto:
o: Liam
TODO: to write
318
UNIT K-4
Guide for TTIC students
Assigned tto:
o: Matt
TODO: to write
This section describes information specific to TTIC and UChicago students.
1) Websit
ebsitee
All really important information, such as deadlines, are available via Canvas:
http://canvas.uchicago.edu
2) Duckiebo
Duckieboxx distribution
TODO: to write
3) Lab access
4) The local T
TAs
As
Assigned tto:
o: Nick
TODO: to write
320
UNIT K-6
Guide for T
TAs
As
6.1. First st
steps
eps
2) Online accounts
3) Install Ubuntu
4) Duckuments
Start learning about Git and Github. You dont have to read the entirety of the following
references now, but keep them on your desk for later reference.
Good book
GUIDE FOR TAS 321
Git Flow
6) Continuous int
integr
egration
ation
7) Duckiebot building
TODO: to write
TODO: to write
322 GUIDE FOR TAS
TODO: to write
6.5. Duckiet
Duckietown
own bey
beyond
ond the class
Assigned tto:
o: Liam?
324
UNIT K-8
Pr
Project
oject pr
proposals
oposals
UNIT K-9
Templat
emplatee of a pr
project
oject
Have a Github account. See Unit H-27. See name conventions (TODO).
Be part of the Duckietown Github organization. You are sure only when you commit
and push one change to one of our repositories.
Be part of the Duckietown Slack. See name conventions (TODO).
Be signed up on
326
PARTL
ART
Packag
ackages
es - Infr
Infrastructur
astructuree
TODO: to write
UNIT L-1
ackagee duckietown
Packag
1.1. Packag
ackagee information
Essentials
Maintainer: Mack
Description
UNIT L-2
ackagee duckietown_msgs
Packag
2.1. Packag
ackagee information
Essentials
Maintainer: Mack
Description
3.1. Packag
ackagee information
Essentials
Description
TODO: to write
3.3. Conf
Configur
iguration
ation
line_detector.easy_algo.yaml
interface: line_detector.LineDetectorInterface
description: |
These are the line detectors.
tests:
- how to test it
my_line_detector.line_detector.yaml
description: |
These are
code:
- ClassName
- param1: value1
param2: value2
330
UNIT L-4
ackagee easy_logs
Packag
4.1. Packag
ackagee information
Essentials
Description
The package includes a few programs to query the database: find , summary , and details .
They all take the same form:
The find command is similar to summary , but it only displays the filenames:
PACKAGE EASY_LOGS 331
4.3. Select
Selector
or languag
languagee
Here are some examples for the query language (Table 4.1).
Show all the Ferrari logs:
The command-line program require downloads requires logs from the cloud.
The syntax is:
For example:
#!/bin/bash
set -ex
# Here, we know that we have the log. We use `find` to get the filename.
filename=`rosrun easy_logs find 20160223-amadoa-amadobot-RCDP2`
4.5. Br
Browsing
owsing the cloud
$ make cloud-download
You can query the DB by using summary with the option --cloud :
Not
ote:
e: This is not implemented yet.
my-set:
- "vehicle:ferrari,length:<10"
- ""
334 PACKAGE EASY_LOGS
Not
ote:
e: This is not implemented yet.
We want the ability to:
slice a log ferrari/slice(5) # now it is a list of a 5 seconds (vehice:ferrari) / slice(5) /
take(1) The second slice.
A physical log is is a file.
A generated log is given by
UNIT L-5
ackagee easy_node
Packag
5.1. Packag
ackagee information
Essentials
Description
For a node with the name my node , implemented in the file src/my node.py you must create
a file by the name my node.easy_node.yaml somewhere in the package.
This is the smallest example of an empty configuration:
description: My node
parameters:
subscriptions:
publishers:
contracts:
336 PACKAGE EASY_NODE
parameters:
name parameter:
type: type
desc: description
default: default value
where:
type is one of float , int , bool , str .
description is a description that will appear in the documentation.
The optional field default gives a default value for the parameter.
For example:
parameters:
k_d:
type: float
desc: The derivative gain.
default: 1.02
subscriptions:
name subscription:
topic: topic name
type: message type
desc: description
subscriptions:
segment_list:
topic: ~segment_list
type: duckietown_msgs/SegmentList
desc: Line detections
queue_size: 1
timeout: 3
publishers:
lane_pose:
topic: ~lane_pose
type: duckietown_msgs/LanePose
desc: Estimated pose
queue_size: 1
3) Describing contr
contracts
acts
Not
ote:
e: This is not implemented yet.
The idea is to have a place where we can describe constraints such as:
This topic must publish at least at 30 Hz.
Panic if you didnt receive a message for 2 seconds.
The maximum latency for this is 0.2 s
Then, we can implement all these checks once and for all in a proper way, instead of
relying on multiple broken implementations
1) Initialization
class MyNode(EasyNode):
def __init__(self):
EasyNode.__init__(self, 'my_package', 'my_node')
self.info('Initialized.')
if __name__ == '__main__':
MyNode().spin()
The node class must derive from EasyNode . You need to tell EasyNode what is the pack-
338 PACKAGE EASY_NODE
info()
debug()
error()
These are mapped to rospy.loginfo() etc.; they include the name of the node.
2) Using conf
configur
iguration
ation par
paramet
ameters
ers
parameters:
num_cells:
desc: Number of cells.
type: int
default: 42
subscriptions:
contracts:
publishers:
class MyNode():
def __init__(self):
EasyNode.__init__(self, 'my_package', 'my_node')
else:
if 'num_cells' in updated:
self.info('Number of cells changed.')
self.cells = [0] * self.config.num_cells
if __name__ == '__main__':
Node().spin()
EasyNode will monitor the ROS parameter server, and will call the function on_parame-
ters_changed if the user changes any parameters.
3) Using subscriptions
subscriptions:
joy:
desc: |
The `Joy.msg` from `joy_node` of the `joy` package.
The vertical axis of the left stick maps to speed.
The horizontal axis of the right stick maps to steering.
type: sensor_msgs/Joy
topic: ~joy
timeout: 3.0
class MyNode():
# ...
4) Time
Time-out
-out
TODO: to implement
The function on_timeout_subscription() is called when there hasnt been a message for the
specified timeout interval.
class MyNode():
# ...
5) Publishers
The publisher object can be accessed at self.publishers.name . EasyNode has taken care of
all the initialization for you.
For example, suppose we specify a publisher command using:
publishers:
command:
desc: The control command.
type: duckietown_msgs/Twist2DStamped
topic: ~car_cmd
class MyNode():
# ...
self.publishers.command.publish(out)
class MyNode(EasyNode):
# ...
def on_init(self):
self.info('Step 1 - Initialized')
def on_shutdown(self):
self.info('Step 3 - Preparing for shutdown.')
5.4. Conf
Configur ation using easy_node:: the user
iguration users point of view
So far, we have seen how to use parameters from the node, but we did not talk about
how to specify the parameters from the users point of view.
EasyNode introduces lots of flexibility compared to the legacy system.
1) Conf
Configur
iguration
ation ffile
ile location
package_name-node_name.config name.config.yaml
line_detector-line_detector.baseline.config.yaml
line_detector-line_detector.fall2017.config.yaml
line_detector-line_detector.andrea.config.yaml
where the baseline versions are the baseline parameters, fall2017 are the parameters we
are using for Fall 2017, and andrea are temporary parameters that the user is using.
However, there cannot be two configurations with the same filename e.g. two copies of
line_detector-line_detector.baseline.config.yaml . In this case, EasyNode will raise an error.
2) Conf
Configur
iguration
ation ffile
ile format
description: |
description of what this configuration accomplishes
extends: [config name, config name]
values:
parameter name: value
parameter name: value
The extends field (optional) is a list of string. It allows to use the specified configurations
as the defaults for the current one.
For example, the file line_detector-line_detector.baseline.config.yaml could contain:
description: |
These are the standard values for the line detector.
extends: []
values:
img_size: [120,160]
top_cutoff: 40
3) Conf
Configur
iguration
ation sequence
$ export DUCKIETOWN_CONFIG_SEQUENCE=baseline:fall2017:andrea
The line above specifies that the configuration sequence is baseline , fall2017 , andrea .
The system loads the configuration in order. First, it loads the baseline version. Then it
loads the fall2017 version. If a value was already specified in the baseline version, it is
overwritten. If a version does not exist, it is simply skipped.
If a parameter is not specified in any configuration, an error is raised.
Using this functionality, it is easy to have team-based customization and user-based
customization.
There are two special configuration names:
1. The configuration name defaults loads the defaults specified by the node. Note
that the defaults are ignored otherwise.
2. The configuration name vehicle expands to the name of the vehicle being used.
TODO: the vehicle part is not implemented yet.
4) Time
Time-v
-variant
ariant conf
configur
iguration
ation
The solution is to allow a date tag in the configuration name. The format for this is
package_name-node_name.config name.date.config.yaml
kinematics-kinematics.ferrari.20160404.config.yaml
kinematics-kinematics.ferrari.20170101.config.yaml
Given this, EasyNode will select the configuration to use intelligently. When reading
from a bag file from 2016, the first configuration is going to be used; for logs in 2017,
the second is going to be used.
TODO: not implemented yet.
The command
Parameters
Subcriptions
Publishers
2) easy_node eval:: E
Evvaluating a conf
configur
iguration
ation sequence
The tool shows also which file is responsible for the value of each parameter.
For example, the command
evaluates the configuration for the line_detector_node2 node with the configuration se-
quence defaults:andrea .
The result is:
PACKAGE EASY_NODE 345
Note how we can tell which configuration file is responsible for setting each parameter.
The program summary reads all the configuration files described in the repository and val-
idates them against the node description.
If a configuration file refers to parameters that do not exist, the configuration file is es-
tablished to be invalid.
The syntax is:
5.6. Benchmarking
EasyNode implements some simple timing statistics. These are accessed using the con-
text object passed to the message received callbacks.
Heres an example use, from line_detector2:
346 PACKAGE EASY_NODE
with context.phase('decoding'):
...
with context.phase('resizing'):
# Resize and crop image
...
stats = context.get_stats()
self.info(stats)
The idea is to enclose the different phases of the computation using the context man-
ager phase(name) .
A summary of the statistics can be accessed by using context.get_stats() .
For example, this will print:
Last 24.4 s: received 734 (30.0 fps) processed 301 (12.3 fps) skipped 433 (17.7 fps) (59 %)
decoding | total latency 25.5 ms | delta wall 20.7 ms | delta clock 20.7 ms
resizing | total latency 26.6 ms | delta wall 0.8 ms | delta clock 0.7 ms
correcting | total latency 29.1 ms | delta wall 2.2 ms | delta clock 2.2 ms
detection | total latency 47.7 ms | delta wall 18.2 ms | delta clock 21.3 ms
preparing-images | total latency 55.0 ms | delta wall 7.0 ms | delta clock 7.0 ms
publishing | total latency 55.5 ms | delta wall 0.1 ms | delta clock 0.1 ms
draw-lines | total latency 59.7 ms | delta wall 4.0 ms | delta clock 3.9 ms
published-images | total latency 61.2 ms | delta wall 0.9 ms | delta clock 0.8 ms
pub_edge/pub_segment | total latency 86.3 ms | delta wall 24.7 ms | delta clock 24.0 ms
5.7. Aut
utomatic
omatic documentation ggener
eneration
ation
For each node documented using a *.easy_node.yaml , this generates a Markdown file
called node name-easy_node-autogenerated.md in the package directory.
The contents are enclosed in a div with ID #package name-node name-autogenerated .
The intended use is that this can be used to move the contents to the place in the docu-
mentation using the move-here tag.
For example, in the README.md of the joy_mapper package, we have:
PACKAGE EASY_NODE 347
## Node `joy_mapper_node`
<move-here src="#joy_mapper-joy_mapper_node-autogenerated"/>
5.8. Par
aramet
ameters
ers and services def
defined
ined for all packag
packages
es
Par
aramet
ameters
ers
No parameters defined.
Subscriptions
No subscriptions defined.
Publishers
No publishers defined.
UNIT L-6
ackagee easy_regression
Packag
6.1. Packag
ackagee information
Essentials
Description
A package to make it easy to abstract about algorithm configuration and create regres-
sion tests.
TODO: to write
6.3. Formalization
Not
ote:
e: These are incomplete design notes.
A regression test is given by:
1. A log set. These are either physical logs or just
2. One or more log processors. These take a bag and write a bag. Multiple bags are
merged.
3. One or more visualizers.
4. One of more statistics.
5. Acceptance conditions.
The regression test engine does the following.
It reads the log test. It makes the logs available. (This might imply downloading the
logs.)
A physical log is a physical .bag file. These are generated
PACKAGE EASY_REGRESSION 349
regression1.regression_test.yaml
description:
Simple regression test.
a
logs:
- "vehicle:ferrari,length:<10"
processors:
- transformer: Identity
stats:
visualizers:
identity.job_processors.yaml
description:
constructor: IdentityProcessor
parameters:
count:
S is a dict of YAML
6.4. Languag
Languagee
Simple checks:
v:analyzer/log/statistics == value
v:analyzer/log/statistics >= value
v:analyzer/log/statistics <= value
v:analyzer/log/statistics < value
v:analyzer/log/statistics > value
7.1. Packag
ackagee information
Essentials
Description
3) The what-the-duck pr
progr
ogram
am
$ ./what-the-duck
The idea is to add to what-the-duck all the tests that can be automated.
The documentation about to do that is not ready yet.
Camera is detected
Scipy is installed
sklearn is installed
Date is set correctly
Not running as root
Not running as ubuntu
Member of group sudo
Member of group input
Member of group video
Member of group i2c
~/.ssh exists
~/.ssh permissions
~/.ssh/config exists
SSH option HostKeyAlgorithms is set
At least one key is configured.
~/.ssh/authorized_keys exists
Git configured
Git email set
Git name set
Git push policy set
Edimax detected
The hostname is configured
/etc/hosts is sane
Correct kernel version
Messages are compiled
Shell is bash
Working internet connection
Github configured
Joystick detected
Environment variable DUCKIETOWN_ROOT
${DUCKIETOWN_ROOT} exists
Environment variable DUCKIETOWN_FLEET
${DUCKIETOWN_FLEET} exists
${DUCKIETOWN_FLEET}/scuderia.yaml exists
${DUCKIETOWN_FLEET}/scuderia.yaml is valid
machines file is valid
Wifi network configured
Python: No CamelCase
Python: No tab chars
Python: No half merges
PARTM
ART
Packag
ackages
es - Lane contr
control
ol
TODO: to write
UNIT M-1
ackagee adafruit_drivers
Packag
1.1. Packag
ackagee information
Essentials
Description
UNIT M-2
ackagee anti_instagram
Packag
2.1. Packag
ackagee information
Essentials
Author: mfe
Maintainer: Mack
Description
Par
aramet
ameters
ers
Par
aramet
ameter
er publish_corrected_image: bool ; default value: False
Whether to compute and publish the corrected image.
Subscriptions
Publishers
UNIT M-3
ackagee dagu_car
Packag
3.1. Packag
ackagee information
Essentials
Description
Par
aramet
ameters
ers
No parameters defined.
Subscriptions
No subscriptions defined.
Publishers
No publishers defined.
Par
aramet
ameters
ers
No parameters defined.
Subscriptions
No subscriptions defined.
Publishers
PACKAGE DAGU_CAR 359
No publishers defined.
Par
aramet
ameters
ers
No parameters defined.
Subscriptions
No subscriptions defined.
Publishers
No publishers defined.
Par
aramet
ameters
ers
No parameters defined.
Subscriptions
No subscriptions defined.
Publishers
No publishers defined.
Par
aramet
ameters
ers
No parameters defined.
Subscriptions
No subscriptions defined.
Publishers
360 PACKAGE DAGU_CAR
No publishers defined.
Par
aramet
ameters
ers
No parameters defined.
Subscriptions
No subscriptions defined.
Publishers
No publishers defined.
UNIT M-4
ackagee ground_projection
Packag
4.1. Packag
ackagee information
Essentials
Description
Par
aramet
ameters
ers
No parameters defined.
Subscriptions
No subscriptions defined.
Publishers
No publishers defined.
362
UNIT M-5
ackagee joy_mapper
Packag
5.1. Packag
ackagee information
Essentials
Maintainer: Mack
Description
5.2. Testing
Connect joystick.
Run:
$ roslaunch launch/joy_mapper_test.launch
5.3. Dependencies
rospy
sensor_msgs : for the Joy.msg
duckietown_msgs : for the CarControl.msg
Par
aramet
ameters
ers
Par
aramet
ameter
er simulated_vehicle_length: float ; default value: 0.18
Subscriptions
Publishers
UNIT M-6
ackagee lane_control
Packag
6.1. Packag
ackagee information
Essentials
Author: steven
Author: Shih-Yuan Liu
Maintainer: Liam Paull
Description
6.2. lane_controller_node
Par
aramet
ameters
ers
Par
aramet
ameter
er k_theta: float
Proportional gain for .
Par
aramet
ameter
er theta_thres: float
Maximum desired .
Par
aramet
ameter
er d_offset: float
A configurable offset from the lane position.
Par
aramet
ameter
er d_thres: float
Cap for error in .
Par
aramet
ameter
er v_bar: float
Nominal linear velocity (m/s).
Par
aramet
ameter
er k_d: float
Propertional gain for .
Subscriptions
Publishers
PACKAGE LANE_CONTROL 365
UNIT M-7
ackagee lane_filter
Packag
Assigned tto:
o: Liam
7.1. Packag
ackagee information
Essentials
Description
7.2. lane_filter_node
Par
aramet
ameters
ers
Par
aramet
ameter
er peak_val: float ; default value: 10.0
Par
aramet
ameter
er linewidth_white: float ; default value: 0.04
Subscriptions
Publishers
8.1. Packag
ackagee information
Essentials
Description
The following are instructions to test the line detector from bag files.
You can run from a bag with the following:
Where:
bag in is the absolut
absolutee path of the input bag.
vehicle is the name of the vehicle that took the log.
bag out is the absolut
absolutee path if the output bag.
Not
ote:
e: you always need to use absolute paths for bag files.
You can let this run for a few seconds, then stop using Ctrl - C .
You can then inspect the result using:
$ roscore &
$ rosbag play -l bag out
$ rviz &
In rviz click add, click by topic tab, expand line_detector and click im-
age_with_lines .
Observe on the result that:
1. There are lots of detections.
2. Predominantly white detections (indicated in black) are on white lines, yellow de-
tections (shown in blue) are on blue lines, and red detections (shown in green) are on
red lines.
These are some sample logs on which to try:
370 PACKAGE LINE_DETECTOR2
https://www.dropbox.com/s/vwznjke4xvnhi9o/160122_manual2-ferrari.bag?dl=1
https://www.dropbox.com/s/y7uljl98punj0mp/160122_manual3_corner-ferrari.bag?dl=1
https://www.dropbox.com/s/d4n9otmlans4i62/160122-calibration-good_lighting-tesla.bag?dl=1
Sample output:
8.3. Quantitativ
Quantitativee ttests
ests
PACKAGE LINE_DETECTOR2 371
8.4. line_detector_node2
Par
aramet
ameters
ers
Par
aramet
ameter
er top_cutoff: int
This parameter decides how much of the image we should cut off. This is a perfor-
mance improvement.
Par
aramet
ameter
er line_detector: str
This is the instance of line_detector to use.
Par
aramet
ameter
er img_size: not known
TODO: Missing description for entry img_size .
Par
aramet
ameter
er verbose: bool ; default value: True
Whether the node is verbose or not. If set to True , the node will write timing statistics
to the log.
Subscriptions
Publishers
9.1. Packag
ackagee information
Essentials
Description
This package is being replaced by the cleaned-up version, line_detector2. Do not write
documentation here.
However, at the moment, all the launch files still call this one.
374
UNIT M-10
ackagee pi_camera
Packag
10.1. Packag
ackagee information
Essentials
Description
Par
aramet
ameters
ers
No parameters defined.
Subscriptions
No subscriptions defined.
Publishers
No publishers defined.
Par
aramet
ameters
ers
Par
aramet
ameter
er res_w: int ; default value: 320
Resolution (width)
Par
aramet
ameter
er framerate: float ; default value: 60.0
Frame rate
Par
aramet
ameter
er res_h: int ; default value: 200
Resolution (height)
Subscriptions
PACKAGE PI_CAMERA 375
No subscriptions defined.
Publishers
Par
aramet
ameters
ers
Par
aramet
ameter
er publish_freq: float ; default value: 1.0
Frequency at which to publish (Hz).
Subscriptions
Publishers
Par
aramet
ameters
ers
No parameters defined.
Subscriptions
No subscriptions defined.
Publishers
No publishers defined.
Par
aramet
ameters
ers
Par
aramet
ameter
er image_type: str ; default value: 'compressed'
Subscriptions
Publishers
Packag
ackages
es - Indef
Indefinit
initee na
navig
vigation
ation
TODO: to write
378
UNIT N-1
AprilT
AprilTags
ags libr
library
ary
1.1. Packag
ackagee information
Essentials
Description
UNIT N-2
ackagee apriltags_ros
Packag
2.1. Packag
ackagee information
Essentials
Description
A package that provides a ROS wrapper for the apriltags C++ package
UNIT N-3
ackagee fsm
Packag
3.1. Packag
ackagee information
Essentials
Description
Par
aramet
ameters
ers
Par
aramet
ameter
er states: dict ; default value: ``
Subscriptions
No subscriptions defined.
Publishers
4.1. Packag
ackagee information
Essentials
Description
UNIT N-5
ackagee intersection_control
Packag
5.1. Packag
ackagee information
Essentials
Description
6.1. Packag
ackagee information
Essentials
Author: igor
Maintainer: Mack
Description
UNIT N-7
ackagee stop_line_filter
Packag
7.1. Packag
ackagee information
Essentials
Description
Packag
ackages
es - Localization and planning
TODO: to write
388
UNIT O -1
ackagee duckietown_description
Packag
1.1. Packag
ackagee information
Essentials
Description
2.1. Packag
ackagee information
Essentials
Author: teddy
Maintainer: Mack
Description
PARTP
ART
Packag
ackages
es - Coor
Coordination
dination
TODO: to write
UNIT P-1
ackagee led_detection
Packag
1.1. Packag
ackagee information
Essentials
Description
Pick your favourite duckiebot as the observer-bot. Refer to it as robot name for this step.
If you are in good company, this can be tried on all the available duckiebots. First, acti-
vate the camera on the observer-bot:
In a separate terminal, fire up the LED detector and the custom GUI by running:
Not
ote:
e: to operate without a GUI:
$ roslaunch led_detector LED_detector.launch veh:=robot name
To run the unit tests for the LED detector, you need to have the F23 rosbags on you hard
disk. These bag files should be synced from [this dropbox link] (https://www.drop-
392 PACKAGE LED_DETECTION
box.com/sh/5kx8qwgttu69fhr/AAASLpOVjV5r1xpzeW7xWZh_a?dl=0).
For the test to locate the bag files, you should have the DUCKIETOWN_DATA environment vari-
able set, pointing to the location of you duckietown-data folder. This can be achieved
by:
$ export DUCKIETOWN_DATA=local-path-to-duckietown-data-folder
All the available tests are specified in file all_tests.yaml in the scripts/ folder of the pack-
age led_detection in the duckietown ROS workspace. To run these, use the command:
More in general:
where:
tests is a comma separated list of algorithms. May use * .
algorithms is a comma separated list of algorithms. May use * .
The default algorithm is called baseline , and its tests are invoked using:
2.1. Packag
ackagee information
Essentials
Description
2.2. In depth
This launches the joy controller, the mapper controller, and the led emitter nodes. You
should not need to run anything external for this to work. Use the joystick buttons A, B
and C to change your duckiebots LEDs blinking frequency.
Button A broadcasts signal CAR_SIGNAL_A (2.8hz), button B broadcasts signal
CAR_SIGNAL_B (4.1hz), and button CAR_SIGNAL_C (Y on the controller) broadcasts
signal C(5hz).The LB button will make the LEDs all white, the RB button will make
some LEDs blue and some LEDs green, and the logitek button (middle button) will
make the LEDs all red
Repeat this for each vehicle at the intersection that you wish to be blinking. Use previ-
ous command replacing robot name the names of the vehicles and try command different
blinking patterns on different duckiebots.
(optional tests) For a grasp of the low level LED emitter, run:
You can then publish to the topic manually by running the following command in an-
other screen on the duckiebot:
Where float-value is the desired blinking frequency, e.g. 1.0, .5, 3.0, etc. If you wish to
run the LED emitter test, run the following:
394 PACKAGE LED_EMITTER
This will cycle through frequencies of 3.0hz, 3.5hz, and 4hz every 5 seconds. Once
done, kill everything and make sure you have joystick control as described above.
UNIT P-3
ackagee led_interpreter
Packag
3.1. Packag
ackagee information
Essentials
Author: qlai
Maintainer: Mack
Description
UNIT P-4
ackagee led_joy_mapper
Packag
4.1. Packag
ackagee information
Essentials
Author: lapentab
Maintainer: Mack
Description
5.1. Packag
ackagee information
Essentials
Description
5.2. Demos
Fancy test:
To do other tests:
UNIT P-6
ackagee traffic_light
Packag
6.1. Packag
ackagee information
Essentials
Maintainer: Mack
Description
Packag
ackages
es - A
Additional
dditional functionality
TODO: to write
400
UNIT Q -1
ackagee mdoap
Packag
1.1. Packag
ackagee information
Essentials
Description
The mdoap package which handles object recognition and uses ground projection to
estimate distances of objects for duckie safety. Also contains controllers for avoiding
said obstacles
UNIT Q -2
ackagee parallel_autonomy
Packag
2.1. Packag
ackagee information
Essentials
Description
UNIT Q -3
ackagee vehicle_detection
Packag
3.1. Packag
ackagee information
Essentials
Description
Packag
ackages
es - T
Templat
emplates
es
UNIT R-1
ackagee pkg_name
Packag
1.1. Packag
ackagee information
Essentials
Description
2.1. Packag
ackagee information
Essentials
Description
PARTS
ART
Packag
ackages
es - Con
Convvenience
These packages are convenience packages that group together launch files and tests.
UNIT S-1
ackagee duckie_rr_bridge
Packag
1.1. Packag
ackagee information
Essentials
Author: greg
Maintainer: Mack
Description
The duckie_rr_bridge package. Creates a Robot Raconteur Service to drive the Duck-
iebot.
408
UNIT S-2
ackagee duckiebot_visualizer
Packag
2.1. Packag
ackagee information
Essentials
Description
Par
aramet
ameters
ers
Par
aramet
ameter
er veh_name: str ; default value: 'megaman'
Subscriptions
Publishers
3.1. Packag
ackagee information
Essentials
Description
UNIT S-4
ackagee duckietown_logs
Packag
4.1. Packag
ackagee information
Essentials
Description
4.2. Misc
5.1. Packag
ackagee information
Essentials
Maintainer: Mack
Description
The duckietown_unit_test meta package contains all the unit test launch files for Ducki-
etown.
412
UNIT S-6
ackagee veh_coordinator
Packag
6.1. Packag
ackagee information
Essentials
Description
Packag
ackages
es - T
Too sort