SlideShare a Scribd company logo
Lecture 3 - Driving
MIT BWSI
Autonomous RACECAR Course
Presented By: Chris Lai & Paul Thai
1
Welcome Back!
2
Code Clash #5 has begun. Good Luck!
3
Sensors and Control Flow
How does the robot know where to go?
Outlook of the Vehicle
5
Hardware Components
● Intel RealSense Camera -
○ Functions like a normal camera where the lens are able to
take color images.
○ Functions as a depth camera.
■ Camera uses software to compute the distance of each
pixel in an image
6
Depth Camera and Color Camera
7
LIDAR
● Short for Light and Radar
● Similar to depth camera, LIDAR computes the
distance of points surrounding the RACECAR.
8
How does it work?
● Emits a laser and records the time it takes for the laster to
bounce back to find distance.
● Capable of rotating many times per second and able to update
the distance of all objects in all directions of the plane.
● Cannot detect objects above or below its view.
9
Image
10
Questions
● Why do we need two sensors to measure
distance?
● What do you think are the limitations of both
sensors?
11
RACECAR Libraries & Modules
Specific to RACECAR!
The Start-Update Paradigm
● start()
○ Function that is called once at the start of the code
○ Used for setup (Initial conditions)
● update()
○ Equivalent to an infinite while loop
○ Runs at a clock speed of ~60Hz, but may be slower due to
calculations done inside function
○ Has no memory! Do not save data inside this function!
13
Global Variables
● scope
○ Describes all locations where a variable can be accessed
○ If a variable is used inside of a function, it cannot be used outside
of a function!
● global
○ Keyword that allows variables to be accessed from everywhere
14
Why is this important?
● Variables used in the update() function are not saved!
● Memory allocated to the garbage collector (python only) after it has
been run, similar to erasing the function’s memory
● To “save” our data after a single instance, use a global variable
1. Create the global variable in the setup() function
2. Edit the variable in the update() function
3. Contents of the variable are now saved for later use!
15
Code Analysis
1. As time goes on, what happens to the value of variable foo?
2. What happens if we omit the global keyword from the start() function?
3. Why do we not need the global keyword to access foo from the bar()
function?
16
The Drive Module
● Most important function!
○ rc.drive.set_speed_angle(speed, angle)
● rc: The racecar object
● drive: A module inside the racecar library
● set_speed_angle: A function inside the drive module
● speed: Abstract value for speed of car (-1 to 1)
● angle: Abstract value for angle of car (-1 to 1)
17
The Drive Module
● speed: Abstract value for speed of car (-1 to 1)
○ -1 = Drive Backwards
○ 0 = Stop Moving
○ 1 = Drive Forwards
● angle: Abstract value for angle of car (-1 to 1)
○ -1 = Turn the wheels left
○ 0 = Turn the wheels straight
○ 1 = Turn the wheels right
18
More Modules
● rc.get_delta_time()
○ Returns the time in seconds since the last time the update()
function was called
● rc.drive.stop()
○ Stops the car in place (speed 0, angle 0)
19
Controlling the Racecar
20
The Controller Module
● rc.controller.Button.A
● rc.controller.Button.B
● rc.controller.Button.X
● rc.controller.Button.Y
● rc.controller.Button.RB (The right bumper)
● rc.controller.Button.LB (The left bumper)
● rc.controller.Button.LJOY (The Left Joystick button)
● rc.controller.Button.RJOY (The Right Joystick button)
21
The Controller Module
● Toggleable buttons
○ A, B, C, D (1, 2, 3, 4 on keyboard)
● Binary Values
○ 0 or 1 only! Pressed or not pressed
● rc.controller.is_down(button)
○ Returns true for every frame that the button is down
● rc.controller.was_pressed(button)
○ Returns true for the first time that the button is down
● rc.controller.was_released(button)
○ Returns true the frame after the button is no longer being pressed
22
The Controller Module
● Left and Right Triggers
○ Control Car Speed
○ 0 or 1 only! Pressed or not pressed
● rc.controller.get_trigger(trigger)
○ Returns the value (from 0-1) of the trigger
23
The Controller Module
● Left and Right Joystick
○ Joysticks have 2 axes, the x and y
○ Ranges from -1 to 1, where
■ -1 = left/down, 0 = center, and 1 = right/up
● rc.controller.get_joystick(joystick)
○ Returns the (x,y) value of the joystick
24
Code Analysis
1. What buttons on the controller are used in this script?
2. Where does the variable speed get its definition from?
3. What does the script do?
25
Running Scripts in the Sim
From VSC to the .exe!
Let’s Double Check our Setup
● Open terminal. If you’re on windows type bash and press enter.
● Type racecar test and press enter
27
Run demo.py
1. Open up the racecar sim and press Begin Simulation (demo
level should be selected in the drop down menu)
2. Go back into your bash terminal and type “racecar cd” and
press enter
3. Then type ls
28
29
4. Type “racecar sim demo.py” into your terminal
5. Start the program from the sim
30
Jupyter Notebooks
A review from PLYMI
Jupyter Notebooks have space for
code and text
● Think like google collab, you can have text boxes with
instructions, or explanations of your code, and boxes with
runnable python code
○ Textboxes are called “markdowns”
○ Python boxes are “code”
32
Kernel
● The kernel is the “engine” of your code
● When you open a notebook document the associated kernel is
automatically launched
● When the notebook is executed, the kernel performs all the
computations
33
34
35
Text Formatting in markdown
● Use # to create a title
● Use ** to bold
● Use * to italicize
● To create a new line, press the spacebar twice before hitting
enter
36
37
Creating a Jupyter Notebook
1. Go into VSC
2. Create new file (with the extension .ipynb)
3. Select Jupyter Notebook
38
Data Structures
How do we store and manage data?
Data Structures
● What is the purpose of data structures?
○ Store data in an organized manner
○ Establish a relationship between data points
● Why do we use data structures in our code?
○ Improve data retrieval algorithms
○ Organize data using sorting methods
○ Carry out a program operation
40
Direct Data Structures
● Arrays (C family, Java)
○ Immutable memory
○ Allocation of memory within hardware registers
● Python List
○ Mutable storage component
○ Flexible data types
● Python Dictionary
○ Hyper-flexible data storage
○ Cross-platform capability with JSON file type
41
Abstract Data Structures
● What is the purpose of abstract data?
● How is one piece of data related to another?
● How do we take data out of the structure?
● How is data organized within the structure?
● Why do we use ADTs?
42
Abstract Data Structures
● Linked List
○ Focuses on sequences of data
○ Each data “item” is connected to the next via a link
○ Can take out any item at any location via algorithm
● Queue
○ A “tunnel” of data
○ Can extract data only from the beginning and the end
● Stack
○ Think of it as a stack of cards
○ Can only take a card (data) from the top of the deck
43
Linked Lists
● Simple Linked List: Items travel forward only
● Double Linked List: Items travel both forwards and backwards
● Circular Linked List: Last item points back to the first item
Double Linked List
44
Circular Linked List
Linked Lists
● Insertion: Add an element to the beginning of a list
● Deletion: Delete an element at the end of a list
● Display: Display the complete list
● Search: Given a key, find an element in the list
● Delete: Given a key, remove an element from the list
45
Linked List Insertion
Queues
● FIFO structure (First In, First Out)
○ Visualize this as a one-way tunnel of data
○ “Nodes” only contain the data
○ The first node must be the first to leave the queue
○ The final node must be the final node to leave the queue
FIFO Queue
46
Queues
● Extremely important applications:
○ Process Management
○ Task Management
● If you have multiple tasks inside a queue, which task is
performed first? Which task is performed last?
FIFO Queue
47
Queues
48
● What operation is being
performed in the
following sequence of
events?
● How does this follow the
queue structure?
● How is this implemented
within the code?
Queues
49
● What operation is being performed in the following sequence of
events?
● How does this follow the queue structure?
● How is this implemented within the code?
Stack
50
● LIFO structure (Last In, First Out)
○ Visualize this as a stack of cards / stack of paper
○ “Nodes” only contain the data
○ The first node must be the last node to leave the queue
○ The final node must be the first node to leave the queue
LIFO Stack
Stack
51
● Some Applications of stacks
○ Operation Evaluation: RPN Solving
○ Function Calls: How does the compiler know to keep track
of function locations within the code?
LIFO Stack
Implementation of ADTs
52
● All ADTs can be represented as a algorithmically modified
version of a direct data type in Python!
○ Python Classes -> Linked List
○ Python List -> FIFO Queue
○ Python List -> Lifo Stack
Queue Implementation in Python
53
Stack Implementation in Python
54
Lab 1: Driving in Shapes
Let’s draw some shapes!
Lab 1 Tasks
1. When the A button is pressed, drive in a circle.
2. When the B button is pressed, drive in a square
3. When the X button is pressed, drive in a figure-eight
4. When the Y button is pressed, drive in any shape of your choice
Keep in mind that all these buttons must work in a single script!
Hint: Use global variables and look at demo.py for an example!
56
Lab 1 Tips
1. Watch out for racecar acceleration! The first side of a square may not
contain the same movement script as the second side of the square.
2. How do we organize code in a script with multiple reused operations
such as in this lab? How can we make our overall code neater?
3. How can we use data structures and the relationship between data
points to provide the RACECAR with varying movements?
4. You may have to apply guess and check (quite a lot). Be patient! We’re
here to help if you need it!
57
Demo Environment Challenges
Make a copy of Lab1.py (call it Lab1challenge.py for example) and write some code to
solve the following problem statements (This is done in the MISC Level):
1. Write a script to make the racecar drive backwards into the wall of bricks in the
demo simulation when the B button is pressed. Stop the car when it and the wall
collides.
2. Write a script to make the racecar drive in an “S” shape through the 3 intro cones
without touching any of them. Drive the car up the ramp and stop the script right
before the car falls off the edge. Make the racecar perform this task when the X
button has been pressed. (You can program another button to drive the car off
the ramp and crash into the pyramid of bricks if you want)
58
See you all tomorrow!
59

More Related Content

Similar to Lecture 3 - Driving.pdf

jn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdfjn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdf
VinayNassa3
 
Everybody be cool, this is a roppery!
Everybody be cool, this is a roppery!Everybody be cool, this is a roppery!
Everybody be cool, this is a roppery!
zynamics GmbH
 
Web dynpro
Web dynproWeb dynpro
Web dynpro
Chinmoy Chiranjivi
 
Distributed implementation of a lstm on spark and tensorflow
Distributed implementation of a lstm on spark and tensorflowDistributed implementation of a lstm on spark and tensorflow
Distributed implementation of a lstm on spark and tensorflow
Emanuel Di Nardo
 
Dfrws eu 2014 rekall workshop
Dfrws eu 2014 rekall workshopDfrws eu 2014 rekall workshop
Dfrws eu 2014 rekall workshop
Tamas K Lengyel
 
lecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdflecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdf
AyushKumar93531
 
How to build TiDB
How to build TiDBHow to build TiDB
How to build TiDB
PingCAP
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
Zhen Wei
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developers
bennuttall
 
Esd module2
Esd module2Esd module2
Esd module2
SOURAV KUMAR
 
Shop 2 presentation slide
Shop 2 presentation slideShop 2 presentation slide
Shop 2 presentation slide
Andrea Tucci
 
Sayeh basic computer
Sayeh basic computerSayeh basic computer
Sayeh basic computer
Farzan Dehbashi
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
Priyanka Aash
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
Mohammed Romi
 
The Volcano/Cascades Optimizer
The Volcano/Cascades OptimizerThe Volcano/Cascades Optimizer
The Volcano/Cascades Optimizer
宇 傅
 
Mirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in GoMirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in Go
linuxlab_conf
 
Hadoop and cassandra
Hadoop and cassandraHadoop and cassandra
Hadoop and cassandra
Christina Yu
 
Module 1_ Introduction.pptx
Module 1_ Introduction.pptxModule 1_ Introduction.pptx
Module 1_ Introduction.pptx
nikshaikh786
 
Industrial Applications of Arduino using Ladder Logic
Industrial Applications of Arduino using Ladder LogicIndustrial Applications of Arduino using Ladder Logic
Industrial Applications of Arduino using Ladder Logic
Robocraze
 
Feature engineering pipelines
Feature engineering pipelinesFeature engineering pipelines
Feature engineering pipelines
Ramesh Sampath
 

Similar to Lecture 3 - Driving.pdf (20)

jn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdfjn;lm;lkm';m';;lmppt of data structure.pdf
jn;lm;lkm';m';;lmppt of data structure.pdf
 
Everybody be cool, this is a roppery!
Everybody be cool, this is a roppery!Everybody be cool, this is a roppery!
Everybody be cool, this is a roppery!
 
Web dynpro
Web dynproWeb dynpro
Web dynpro
 
Distributed implementation of a lstm on spark and tensorflow
Distributed implementation of a lstm on spark and tensorflowDistributed implementation of a lstm on spark and tensorflow
Distributed implementation of a lstm on spark and tensorflow
 
Dfrws eu 2014 rekall workshop
Dfrws eu 2014 rekall workshopDfrws eu 2014 rekall workshop
Dfrws eu 2014 rekall workshop
 
lecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdflecture16-recap-questions-and-answers.pdf
lecture16-recap-questions-and-answers.pdf
 
How to build TiDB
How to build TiDBHow to build TiDB
How to build TiDB
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
 
Python for PHP developers
Python for PHP developersPython for PHP developers
Python for PHP developers
 
Esd module2
Esd module2Esd module2
Esd module2
 
Shop 2 presentation slide
Shop 2 presentation slideShop 2 presentation slide
Shop 2 presentation slide
 
Sayeh basic computer
Sayeh basic computerSayeh basic computer
Sayeh basic computer
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
 
The Volcano/Cascades Optimizer
The Volcano/Cascades OptimizerThe Volcano/Cascades Optimizer
The Volcano/Cascades Optimizer
 
Mirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in GoMirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in Go
 
Hadoop and cassandra
Hadoop and cassandraHadoop and cassandra
Hadoop and cassandra
 
Module 1_ Introduction.pptx
Module 1_ Introduction.pptxModule 1_ Introduction.pptx
Module 1_ Introduction.pptx
 
Industrial Applications of Arduino using Ladder Logic
Industrial Applications of Arduino using Ladder LogicIndustrial Applications of Arduino using Ladder Logic
Industrial Applications of Arduino using Ladder Logic
 
Feature engineering pipelines
Feature engineering pipelinesFeature engineering pipelines
Feature engineering pipelines
 

Recently uploaded

一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
afkxen
 
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa WarheitExpanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Forth
 
Globalfleet - global fleet survey 2021 full results
Globalfleet - global fleet survey 2021 full resultsGlobalfleet - global fleet survey 2021 full results
Globalfleet - global fleet survey 2021 full results
vaterland
 
Kaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality EngineerspptxKaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality Engineerspptx
vaibhavsrivastava482521
 
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill RoadsWhat Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
Sprinter Gurus
 
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
afkxen
 
Catalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptxCatalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptx
Blue Star Brothers
 
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
78tq3hi2
 
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
MarynaYurchenko2
 
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) RaipurAadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects
 
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
78tq3hi2
 
Hand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptxHand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptx
wstatus456
 
EV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin DonnellyEV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin Donnelly
Forth
 
What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?
Hyundai Motor Group
 
Here's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDsHere's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDs
jennifermiller8137
 
EN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptxEN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptx
aichamardi99
 
EV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker JamiesonEV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker Jamieson
Forth
 

Recently uploaded (17)

一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
一比一原版(Columbia文凭证书)哥伦比亚大学毕业证如何办理
 
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa WarheitExpanding Access to Affordable At-Home EV Charging by Vanessa Warheit
Expanding Access to Affordable At-Home EV Charging by Vanessa Warheit
 
Globalfleet - global fleet survey 2021 full results
Globalfleet - global fleet survey 2021 full resultsGlobalfleet - global fleet survey 2021 full results
Globalfleet - global fleet survey 2021 full results
 
Kaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality EngineerspptxKaizen SMT_MI_PCBA for Quality Engineerspptx
Kaizen SMT_MI_PCBA for Quality Engineerspptx
 
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill RoadsWhat Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
What Could Be Behind Your Mercedes Sprinter's Power Loss on Uphill Roads
 
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
一比一原版(WashU文凭证书)圣路易斯华盛顿大学毕业证如何办理
 
Catalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptxCatalytic Converter theft prevention - NYC.pptx
Catalytic Converter theft prevention - NYC.pptx
 
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
快速办理(napier毕业证书)英国龙比亚大学毕业证在读证明一模一样
 
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
53286592-Global-Entrepreneurship-and-the-Successful-Growth-Strategies-of-Earl...
 
AadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) RaipurAadiShakti Projects ( Asp Cranes ) Raipur
AadiShakti Projects ( Asp Cranes ) Raipur
 
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
原版制作(Exeter毕业证书)埃克塞特大学毕业证完成信一模一样
 
Hand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptxHand Gesture Control Robotic Arm using image processing.pptx
Hand Gesture Control Robotic Arm using image processing.pptx
 
EV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin DonnellyEV Charging at Multifamily Properties by Kevin Donnelly
EV Charging at Multifamily Properties by Kevin Donnelly
 
What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?What do the symbols on vehicle dashboard mean?
What do the symbols on vehicle dashboard mean?
 
Here's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDsHere's Why Every Semi-Truck Should Have ELDs
Here's Why Every Semi-Truck Should Have ELDs
 
EN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptxEN Artificial Intelligence by Slidesgo.pptx
EN Artificial Intelligence by Slidesgo.pptx
 
EV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker JamiesonEV Charging at MFH Properties by Whitaker Jamieson
EV Charging at MFH Properties by Whitaker Jamieson
 

Lecture 3 - Driving.pdf

  • 1. Lecture 3 - Driving MIT BWSI Autonomous RACECAR Course Presented By: Chris Lai & Paul Thai 1
  • 3. Code Clash #5 has begun. Good Luck! 3
  • 4. Sensors and Control Flow How does the robot know where to go?
  • 5. Outlook of the Vehicle 5
  • 6. Hardware Components ● Intel RealSense Camera - ○ Functions like a normal camera where the lens are able to take color images. ○ Functions as a depth camera. ■ Camera uses software to compute the distance of each pixel in an image 6
  • 7. Depth Camera and Color Camera 7
  • 8. LIDAR ● Short for Light and Radar ● Similar to depth camera, LIDAR computes the distance of points surrounding the RACECAR. 8
  • 9. How does it work? ● Emits a laser and records the time it takes for the laster to bounce back to find distance. ● Capable of rotating many times per second and able to update the distance of all objects in all directions of the plane. ● Cannot detect objects above or below its view. 9
  • 11. Questions ● Why do we need two sensors to measure distance? ● What do you think are the limitations of both sensors? 11
  • 12. RACECAR Libraries & Modules Specific to RACECAR!
  • 13. The Start-Update Paradigm ● start() ○ Function that is called once at the start of the code ○ Used for setup (Initial conditions) ● update() ○ Equivalent to an infinite while loop ○ Runs at a clock speed of ~60Hz, but may be slower due to calculations done inside function ○ Has no memory! Do not save data inside this function! 13
  • 14. Global Variables ● scope ○ Describes all locations where a variable can be accessed ○ If a variable is used inside of a function, it cannot be used outside of a function! ● global ○ Keyword that allows variables to be accessed from everywhere 14
  • 15. Why is this important? ● Variables used in the update() function are not saved! ● Memory allocated to the garbage collector (python only) after it has been run, similar to erasing the function’s memory ● To “save” our data after a single instance, use a global variable 1. Create the global variable in the setup() function 2. Edit the variable in the update() function 3. Contents of the variable are now saved for later use! 15
  • 16. Code Analysis 1. As time goes on, what happens to the value of variable foo? 2. What happens if we omit the global keyword from the start() function? 3. Why do we not need the global keyword to access foo from the bar() function? 16
  • 17. The Drive Module ● Most important function! ○ rc.drive.set_speed_angle(speed, angle) ● rc: The racecar object ● drive: A module inside the racecar library ● set_speed_angle: A function inside the drive module ● speed: Abstract value for speed of car (-1 to 1) ● angle: Abstract value for angle of car (-1 to 1) 17
  • 18. The Drive Module ● speed: Abstract value for speed of car (-1 to 1) ○ -1 = Drive Backwards ○ 0 = Stop Moving ○ 1 = Drive Forwards ● angle: Abstract value for angle of car (-1 to 1) ○ -1 = Turn the wheels left ○ 0 = Turn the wheels straight ○ 1 = Turn the wheels right 18
  • 19. More Modules ● rc.get_delta_time() ○ Returns the time in seconds since the last time the update() function was called ● rc.drive.stop() ○ Stops the car in place (speed 0, angle 0) 19
  • 21. The Controller Module ● rc.controller.Button.A ● rc.controller.Button.B ● rc.controller.Button.X ● rc.controller.Button.Y ● rc.controller.Button.RB (The right bumper) ● rc.controller.Button.LB (The left bumper) ● rc.controller.Button.LJOY (The Left Joystick button) ● rc.controller.Button.RJOY (The Right Joystick button) 21
  • 22. The Controller Module ● Toggleable buttons ○ A, B, C, D (1, 2, 3, 4 on keyboard) ● Binary Values ○ 0 or 1 only! Pressed or not pressed ● rc.controller.is_down(button) ○ Returns true for every frame that the button is down ● rc.controller.was_pressed(button) ○ Returns true for the first time that the button is down ● rc.controller.was_released(button) ○ Returns true the frame after the button is no longer being pressed 22
  • 23. The Controller Module ● Left and Right Triggers ○ Control Car Speed ○ 0 or 1 only! Pressed or not pressed ● rc.controller.get_trigger(trigger) ○ Returns the value (from 0-1) of the trigger 23
  • 24. The Controller Module ● Left and Right Joystick ○ Joysticks have 2 axes, the x and y ○ Ranges from -1 to 1, where ■ -1 = left/down, 0 = center, and 1 = right/up ● rc.controller.get_joystick(joystick) ○ Returns the (x,y) value of the joystick 24
  • 25. Code Analysis 1. What buttons on the controller are used in this script? 2. Where does the variable speed get its definition from? 3. What does the script do? 25
  • 26. Running Scripts in the Sim From VSC to the .exe!
  • 27. Let’s Double Check our Setup ● Open terminal. If you’re on windows type bash and press enter. ● Type racecar test and press enter 27
  • 28. Run demo.py 1. Open up the racecar sim and press Begin Simulation (demo level should be selected in the drop down menu) 2. Go back into your bash terminal and type “racecar cd” and press enter 3. Then type ls 28
  • 29. 29
  • 30. 4. Type “racecar sim demo.py” into your terminal 5. Start the program from the sim 30
  • 32. Jupyter Notebooks have space for code and text ● Think like google collab, you can have text boxes with instructions, or explanations of your code, and boxes with runnable python code ○ Textboxes are called “markdowns” ○ Python boxes are “code” 32
  • 33. Kernel ● The kernel is the “engine” of your code ● When you open a notebook document the associated kernel is automatically launched ● When the notebook is executed, the kernel performs all the computations 33
  • 34. 34
  • 35. 35
  • 36. Text Formatting in markdown ● Use # to create a title ● Use ** to bold ● Use * to italicize ● To create a new line, press the spacebar twice before hitting enter 36
  • 37. 37
  • 38. Creating a Jupyter Notebook 1. Go into VSC 2. Create new file (with the extension .ipynb) 3. Select Jupyter Notebook 38
  • 39. Data Structures How do we store and manage data?
  • 40. Data Structures ● What is the purpose of data structures? ○ Store data in an organized manner ○ Establish a relationship between data points ● Why do we use data structures in our code? ○ Improve data retrieval algorithms ○ Organize data using sorting methods ○ Carry out a program operation 40
  • 41. Direct Data Structures ● Arrays (C family, Java) ○ Immutable memory ○ Allocation of memory within hardware registers ● Python List ○ Mutable storage component ○ Flexible data types ● Python Dictionary ○ Hyper-flexible data storage ○ Cross-platform capability with JSON file type 41
  • 42. Abstract Data Structures ● What is the purpose of abstract data? ● How is one piece of data related to another? ● How do we take data out of the structure? ● How is data organized within the structure? ● Why do we use ADTs? 42
  • 43. Abstract Data Structures ● Linked List ○ Focuses on sequences of data ○ Each data “item” is connected to the next via a link ○ Can take out any item at any location via algorithm ● Queue ○ A “tunnel” of data ○ Can extract data only from the beginning and the end ● Stack ○ Think of it as a stack of cards ○ Can only take a card (data) from the top of the deck 43
  • 44. Linked Lists ● Simple Linked List: Items travel forward only ● Double Linked List: Items travel both forwards and backwards ● Circular Linked List: Last item points back to the first item Double Linked List 44 Circular Linked List
  • 45. Linked Lists ● Insertion: Add an element to the beginning of a list ● Deletion: Delete an element at the end of a list ● Display: Display the complete list ● Search: Given a key, find an element in the list ● Delete: Given a key, remove an element from the list 45 Linked List Insertion
  • 46. Queues ● FIFO structure (First In, First Out) ○ Visualize this as a one-way tunnel of data ○ “Nodes” only contain the data ○ The first node must be the first to leave the queue ○ The final node must be the final node to leave the queue FIFO Queue 46
  • 47. Queues ● Extremely important applications: ○ Process Management ○ Task Management ● If you have multiple tasks inside a queue, which task is performed first? Which task is performed last? FIFO Queue 47
  • 48. Queues 48 ● What operation is being performed in the following sequence of events? ● How does this follow the queue structure? ● How is this implemented within the code?
  • 49. Queues 49 ● What operation is being performed in the following sequence of events? ● How does this follow the queue structure? ● How is this implemented within the code?
  • 50. Stack 50 ● LIFO structure (Last In, First Out) ○ Visualize this as a stack of cards / stack of paper ○ “Nodes” only contain the data ○ The first node must be the last node to leave the queue ○ The final node must be the first node to leave the queue LIFO Stack
  • 51. Stack 51 ● Some Applications of stacks ○ Operation Evaluation: RPN Solving ○ Function Calls: How does the compiler know to keep track of function locations within the code? LIFO Stack
  • 52. Implementation of ADTs 52 ● All ADTs can be represented as a algorithmically modified version of a direct data type in Python! ○ Python Classes -> Linked List ○ Python List -> FIFO Queue ○ Python List -> Lifo Stack
  • 55. Lab 1: Driving in Shapes Let’s draw some shapes!
  • 56. Lab 1 Tasks 1. When the A button is pressed, drive in a circle. 2. When the B button is pressed, drive in a square 3. When the X button is pressed, drive in a figure-eight 4. When the Y button is pressed, drive in any shape of your choice Keep in mind that all these buttons must work in a single script! Hint: Use global variables and look at demo.py for an example! 56
  • 57. Lab 1 Tips 1. Watch out for racecar acceleration! The first side of a square may not contain the same movement script as the second side of the square. 2. How do we organize code in a script with multiple reused operations such as in this lab? How can we make our overall code neater? 3. How can we use data structures and the relationship between data points to provide the RACECAR with varying movements? 4. You may have to apply guess and check (quite a lot). Be patient! We’re here to help if you need it! 57
  • 58. Demo Environment Challenges Make a copy of Lab1.py (call it Lab1challenge.py for example) and write some code to solve the following problem statements (This is done in the MISC Level): 1. Write a script to make the racecar drive backwards into the wall of bricks in the demo simulation when the B button is pressed. Stop the car when it and the wall collides. 2. Write a script to make the racecar drive in an “S” shape through the 3 intro cones without touching any of them. Drive the car up the ramp and stop the script right before the car falls off the edge. Make the racecar perform this task when the X button has been pressed. (You can program another button to drive the car off the ramp and crash into the pyramid of bricks if you want) 58
  • 59. See you all tomorrow! 59