A Gentle Introduction to Robotics Volume 1 : Mblock and the Mbot
Total Page:16
File Type:pdf, Size:1020Kb
A Gentle Introduction to Robotics Volume 1: mBlock and the mBot Charles McKnight 2016 Senestone, Inc. ******** Copyright © 2016, Senestone, Inc. All rights reserved. ISBN-10: 0-9975317-0-3 ISBN-13: 978-0-9975317-0-1 No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without the prior written permission of the publisher. ii Dedication When I was a child my grandfather told me to make sure that I spent time educating children when I was an adult or I would deserve the future I would get. This book is dedicated to those who taught me as a child and to the children who continue to teach me as an adult. I also want to express my gratitude, love, and appreciation for my lovely wife, Jie, and my son, Ian, whose patience and support enabled me to complete this book. iii iv Contents Contents v Acknowledgments xi Preface xiii Robots All Around Us...................................... xiii What is a Robot?......................................... xiii What is Robotics?........................................ xiv Why Is Robotics Important?.................................. xiv Why This Book?......................................... xiv 1 Getting Set Up 1 Before You Start.........................................1 Installing the Arduino Driver..................................1 What is an mBot?........................................2 Building the mBot........................................2 Connecting Power........................................2 Connecting to the mBot.....................................3 Connecting to the mBlock Environment............................4 2 The Software Development Process5 Requirements...........................................5 Analysis..............................................5 Design...............................................5 Implementation..........................................6 Testing & Debugging.......................................6 3 Programming Guidelines7 Naming Conventions.......................................7 Valid Characters.........................................7 Snake-Case vs. Camel-Case...................................7 Design First............................................8 Breaking Down the Boulders..................................8 Do One Thing Well........................................8 Flowcharting, Pseudocode, and Design.............................8 Pseudo-Coding.......................................... 10 Test, Test, Test!......................................... 10 v CONTENTS 4 The mBlock Programming Environment 11 mBlock and Scratch....................................... 11 A Quick Tour of mBlock..................................... 11 All Scratch Blocks Are Not Supported in mBot Programs.................. 13 Arduino Mode.......................................... 14 Editing with Arduino IDE.................................... 15 Block Palettes.......................................... 16 Control Palette....................................... 19 Data & Blocks Palette................................... 21 Operators Palette...................................... 24 Robots Palette....................................... 28 5 Blinking LEDs 35 Program Description....................................... 35 Requirements........................................... 35 Analysis.............................................. 36 Design............................................... 36 Program Code.......................................... 37 Testing and Validation...................................... 40 Troubleshooting and Debugging................................. 40 Challenges............................................. 41 6 Play an Octave 43 Program Description....................................... 43 Requirements........................................... 43 Analysis.............................................. 44 Design............................................... 44 Program Code.......................................... 46 Testing & Validation....................................... 55 Troubleshooting and Debugging................................. 55 Challenges............................................. 56 7 Press the Button 57 Program Description....................................... 57 Requirements........................................... 58 Analysis.............................................. 58 Design............................................... 58 Program Code.......................................... 59 Testing & Validation....................................... 61 Troubleshooting & Debugging.................................. 61 Challenges............................................. 61 8 Light It Up! 63 Program Description....................................... 63 Requirements........................................... 63 Analysis.............................................. 63 Design............................................... 64 Program Code.......................................... 65 Testing & Validation....................................... 66 Troubleshooting & Debugging.................................. 66 Challenges............................................. 67 vi Contents 9 Ultrasonic Theremin 69 Program Description....................................... 69 Requirements........................................... 69 Analysis.............................................. 70 Design............................................... 71 Program Code.......................................... 72 Testing & Validation....................................... 75 Troubleshooting & Debugging.................................. 75 Challenges............................................. 76 10 Baby You Can Drive My Bot 77 Program Description....................................... 77 Requirements........................................... 77 Analysis.............................................. 77 Design............................................... 79 Program Code.......................................... 80 Testing & Validation....................................... 80 Troubleshooting & Debugging.................................. 81 Challenges............................................. 81 11 Where’s My Line? 83 Program Description....................................... 83 Requirements........................................... 83 Analysis.............................................. 83 Design............................................... 85 Program Code.......................................... 86 Testing & Validation....................................... 87 Troubleshooting & Debugging.................................. 87 Challenges............................................. 88 12 Robotic Movement Part 1 89 Controlling Robotic Movement................................. 89 Thinking Like an Engineer................................... 89 Program Description....................................... 90 Requirements........................................... 90 Analysis.............................................. 90 Design............................................... 90 Program Code.......................................... 91 Testing & Validation....................................... 91 Challenges............................................. 91 13 We Like to Move It! 93 Program Description....................................... 93 Requirements........................................... 93 Analysis.............................................. 93 Design............................................... 94 Program Code.......................................... 95 Testing & Validation....................................... 95 Troubleshooting & Debugging.................................. 96 Challenges............................................. 96 vii CONTENTS 14 Robotic Movement Part 2 97 Program Description....................................... 98 Requirements........................................... 99 Analysis.............................................. 99 Design............................................... 99 Program Code.......................................... 99 Testing & Validation....................................... 100 15 Trace A Shape 101 Program Description....................................... 101 Requirements........................................... 101 Analysis.............................................. 101 Design............................................... 102 Program Code.......................................... 103 Testing & Validation....................................... 104 Troubleshooting & Debugging.................................. 104 Challenges............................................. 105 16 Obstacle Avoidance 107 Program Description....................................... 108 Requirements........................................... 108 Analysis.............................................. 108 Design............................................... 109 Program Code.......................................... 111 Testing & Validation....................................... 114 Troubleshooting & Debugging.................................. 114 Challenges............................................. 114 17 Bashin’ at the Basho 115 Program Description....................................... 116 Requirements........................................... 116 Analysis.............................................. 116 Design............................................... 117 Program Code.........................................