ENGG1100 Ch6: Introduction To Engineering Design (Digital Logic) Part 2 of digital logic KH WONG ENGG1100. Ch6-Digital Logic (part2) v3h1.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Robofest 2005 Introduction to Programming RIS 2.0 RCX Code.
ROBOTC for CORTEX While Loops Part 1
Ch-11 Project Execution and Termination. System Testing This involves two different phases with two different outputs First phase is system test planning.
ENGG1100 Ch7: Introduction To Engineering Design (Digital Logic)
Combinational Circuits CS370 – Spring BCD to 7 Segment Display Controller Understanding the problem: input is a 4 bit bcd digit output is the control.
Lab7: Introduction to Arduino
Copyright © 2005 Rockwell Automation, Inc. All rights reserved. 1 Micro Logix 1100 RSLogix 500 LAB#2 Timing, Counting & Comparing.
ME 322: Instrumentation Lecture 35 April 18, 2014 Professor Miles Greiner.
Add and Use a Sensor & Autonomous For FIRST Robotics
V EX C OACHES ' T RAINING October 12, Agenda for Today 9 – 10 AM : Tina Reeves and the Engineering Notebook 10 – Noon : Finish Building, Basic Robot.
Available at: – Program Optical Quad Encoders in Autonomous Mode Program optical quad encoders in autonomous mode.
Vex 1.0 © 2005 Carnegie Mellon Robotics Academy Inc. Programming in easyC.
Laboratory 5: Introduction to LabVIEW. Overview Objectives Background Materials Procedure Report / Presentation Closing.
State Machines Used to Design Sequential Circuits.
Arduino. Arduino is a tool for making computers that can sense and control more of the physical world than your desktop computer. It's an open-source.
Programming Fundamentals (750113) Ch1. Problem Solving
Introduction to Arduino Prepared by R. Lamond.  “Arduino is an open-source electronics prototyping platform based on flexible, easy- to-use hardware.
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
ENGG1100 Lecture 6: Introduction To Engineering Design (Digital Logic) Part 1 Kin Hong Wong ENGG1100. Ch6-Digital Logic (Part1) 25/2/14 1.
Testbed: Exercises.
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
ENGG1100 Lecture7: Introduction To Engineering Design (Digital Logic) Part 2 Kin Hong Wong ENGG1100. Ch7-Digital Logic (part 2) 16/02/15 1.
ENGG1100 Introduction to Engineering Design Digital Logic (Part 2) Prof. Kin Hong Wong Department of Computer Science and Engineering.
ENGG1100 Ch6: Introduction To Engineering Design (Digital Logic) Part 1 KH WONG ENGG1100. Ch6-Digital Logic (v3e2.v5)1.
Program ultrasonic range sensor in autonomous mode
Programming Concepts Part B Ping Hsu. Functions A function is a way to organize the program so that: – frequently used sets of instructions or – a set.
Available at: Lesson 3.6 – Program Line Follower in Autonomous Mode Program Line Follower in Autonomous Mode.
Introduction to the Arduino
ERGM 1413 Programming and Playing with Intelligent Robots Prof. K.H. Wong Robot building v4.7b1.
ENGG1100 Ch5: Introduction To Engineering Design (Digital Logic) Part 1 of digital logic KH WONG ENGG1100. Ch5-Digital Logic (v3e2)1.
7.2 V battery pack and charger Put the battery in the charger station at the end of the lab. period. Red light indicates charging. Ken Youssefi Introduction.
Available at: Lesson 3.5 – Program Light Sensor in Autonomous Mode Program Light Sensor in Autonomous Mode.
ENGG1100 Introduction to Engineering Design Digital Logic (Part 1) Prof. Kin Hong Wong Department of Computer Science and Engineering.
Robot Programming. Programming Behaviors Behaviors describe the actions and decisions of your robot.
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4/Lab3.
The George Washington University Electrical & Computer Engineering Department ECE 002 Dr. S. Ahmadi Class3/Lab 2.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
4) Design the logic to control the motor on a simple remote control car. There are two buttons on the remote control for the motor. If neither button is.
Introduction to LabVIEW
Introduction to the DE0 Board Prof. Taeweon Suh Computer Science & Engineering Korea University COSE221, COMP211 Computer Logic Design.
Vex Robotics program three: using motors and sensors together.
Casne.ncl.ac.uk Taking care of the CrumbleBot Please do NOT stress the robot's motors 1.Do NOT push the robot 2.Do NOT hold the.
Mechanical Components and Programming Ken Youssefi Introduction to Engineering – E10 1.
Copyright © 2007 by Pearson Education 1 UNIT 6A COMBINATIONAL CIRCUIT DESIGN WITH VHDL by Gregory L. Moss Click hyperlink below to select: Tutorial for.
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
Sensor Information: while loops and Boolean Logic.
ROBOTC for CORTEX Teacher Training © 2011 Project Lead The Way, Inc. Automation and Robotics VEX.
What is Arduino? It's an open source electronics prototyping platform: Open source: resources that can be used, redistributed or rewritten free of charge,
Introduction to the FPGA and Labs
VEX IQ Curriculum Smart Machines Lesson 09 Lesson Materials:
ROBOTC for VEX On-Site Professional Development
Lab02 :Logic Gate Fundamentals:
Introduction To Flowcharting
Movement using Shaft Encoders
ECET 405 Innovative Education--snaptutorial.com
The Finch Robot and the While Loop
MicroEconomix 1500 RSLogix 500 LAB#2
Automation and Robotics
Robot Programming Computer Literacy S2.
Thursday, 22 November 2018 Logic Gates
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Switch Blocks check a value and choose a path based on that value
Programming Fundamentals (750113) Ch1. Problem Solving
Robotics Programming Using Shaft Encoders
1.15: Dual Joystick Control (Tank)
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Concepts (Part B) ENGR 10 Introduction to Engineering
Presentation transcript:

ENGG1100 Ch6: Introduction To Engineering Design (Digital Logic) Part 2 of digital logic KH WONG ENGG1100. Ch6-Digital Logic (part2) v3h1

Part 2 Implementations of logic functions in programs – Method1: Logic Formula (use of IF-Then-Else) – Method2: Truth table (Use of Switch-case) – Examples – **For both methods, you don’t need to write the full programs, you only need to understand and modify the examples given. Video link ENGG1100. Ch6-Digital Logic (part2) v3h2

Method 1: to implement logic operations in a program using Logic Formula (use of IF-Then-Else) ENGG1100. Ch6-Digital Logic (part2) v3h3

Sensors of our robot Sensors – S1,S2,S3 each can be ‘1’ or ‘0’ – Magnetic field detected =>Si=0 – No Magnetic field detected =>Si=1 ENGG1100. Ch6-Digital Logic (part2) v3h 44 S2 S3 S1 The robot is facing you

Motors of our robot Motors: LM1, LM2, RM1 and RM2 – Instruction LM1(0) sets LM1 to be 0 – Instruction LM1(1) sets LM1 to be 1 Motor control method – {LM1=1 and LM2=0}=> Left-motor moves forward – {LM1=0 and LM2=1} => Left-motor moves backward – {LM1=0 and LM2=0} => Left-motor stops – Similar for the right-motor ENGG1100. Ch6-Digital Logic (part2) v3h55 RM1 RM2 LM1 LM2 The robot is facing you

In the lab : use switches to simulate sensors; use LEDs to simulate motors Testing hardware setup in our robot system LM1 is an output for a Light Emitting Diode LED – When LM1=1 it is on – When LM1=0 it is off – Same for LM2,RM1 and RM2 etc S1 is a switch – When depressed S1=0 – When released S1=1 – Same for S2,S3 and S4 ENGG1100. Ch6-Digital Logic (part2) v3h6 Simulate sensors S1,S2 etc Simulate Motors LM1,LM2 RM1,EM2

Programing procedures Details in the document – “Document B: A tutorial of how to use the controller board”, of Engg1100 Lab manual 5 from elearninghttps://elearn.cuhk.edu.hk/webapps/login/ Edit program Compile Download to the SMART-car-board Run the program Demo video in ENGG1100. Ch6-Digital Logic (part2) v3h7

Method 1 (Use of If-then-else): This program will enable the robot to follow the magnetic path The program segment: Void loop() { LM1(0);LM2(0);RM1(0);RM2(0); //comment :LM1 =S1 AND S2 If (S1()==1 && S2()==1) LM1(1); Else LM1(0); //comment :LM2 = S3 OR S4 If (S3()==1 || S4()==1) LM2(1); Else LM2(0); } Notations used in the program Void Loop= repeated the execution of the lines LM1(0) sets the digital output LM1 to 0 LM1(1) sets the digital output LM1 to 1 == means condition &&= logic operation AND || = Logic OR // comment, for you to put in notes ENGG1100. Ch6-Digital Logic (part2) v3h 8 S2 S1 RM1 RM2 LM1 LM2

How to use “If” in a program IF (condition) then output is result 1, else output is result 2 Example1: //just to illustrate the idea, not a runnable program – If (“you_eat” and “you_drink”) you _can_live; – Else “you_die”; Example2: // && means “AND” – If (S1()==1 && S2()==1) LM1(1); – Else LM1(0); – The above program means if S1 is 1 AND S2 is 1, the LM1 will be 1 else LM1 is 0 Example3: // || means “OR” – If (S3()==1 || S4()==1) LM2(1); – Else LM2(0); – The above program means if S3 is 1 OR S4 is 1, the LM2 will be 1 else LM2 is 0 ENGG1100. Ch6-Digital Logic (part2) v3h9

Exercise1 //LM2 = S3 OR S4 If (S3()==1 || S4()==1) LM2(1); Else LM2(0); If (S4()==0 && S1()==1) LM1(0); Else LM1(1); Explain in English the meaning of the above statements – ?? ENGG1100. Ch6-Digital Logic (part2) v3h10

Method 2 : to implement logic operation in a program using truth table (Use of Switch-Case) ENGG1100. Ch6-Digital Logic (part2) v3h11

Using two sensors S2,S1 to follow a magnetic stripe Sensors: S2 S1 ENGG1100. Ch6-Digital Logic (part2) v3h12 Magnetic sensors S1, S2 Terminal 12 S2 S1

Robot specifications of the sensor input and motor outputs Inputs: – S1 S2 are magnetic sensors S1 =‘1’ if it detects no magnetic material S1 =‘0’ if it detects magnetic material Outputs for left motor (similar to right motor) : – LM1, LM2=“10” left motor moves forward – LM1, LM2=“01” left motor moves backward – LM1, LM2=“00” or “11” left motor stops ENGG1100. Ch6-Digital Logic (part2) v3h13 Magnetic sensors S1, S2 Magnetic stripe Robot car Terminal

Motor control Motor control outputs for both motors – Robot forward: LM1, LM2, RM1, RM2=“1010” – Robot turns right: LM1, LM2, RM1, RM2=“1000” – Robot turns left: LM1, LM2, RM1, RM2=“0010” ENGG1100. Ch6-Digital Logic (part2) v3h14

Exercise2: Truth table example to make our robot follow the magnetic strip Case 1)S2=1, S1=1 (on both sides of magnetic strip): Robot should move forward 2)S2=0, S1=1 (robot on the left side of the magnetic strip): Robot should turn right 3)S2=1, S1=0 (robot on the right side of the magnetic strip): Robot should turn left 4)S2=0,S1=0 (robot reaches the terminal) : Robot should stop ENGG1100. Ch6-Digital Logic (part2) v3h15 Case InputsOutputs S2S1LM1LM2RM1RM2 1) ) 01?__ 3) 10?__ 4) 00?__ ?__ ?__ ?__ Magnetic strip S1 S2 forward:LM1, LM2, RM1, RM2=“1010” turn right:LM1, LM2, RM1, RM2=“1000” turn left:LM1, LM2, RM1, RM2=“0010” S1 S2 Fill in the table Robot

Add another sensor at the front to detect the target object Sensors: S2 S1 facing the ground for following the to follow the magnetic stripe S3 is used to detect the target object – S3=1 if no object is detected – S3=0 if an object is detected ENGG1100. Ch6-Digital Logic (part2) v3h16 Magnetic sensors S1, S3 S2 16 S2 S3 S1

Use of “Switch – case” in a program You may treat it as a table lookup method In English it means: – If INPUT is code1, result 1 will occur – If INPUT is code2, result 2 will occur – If INPUT is code3, result 3 will occur – Etc…… switch (INPUT) { case code1 : result 1; break; case code2 : result 2; break; case code3 : result 3; break; : } ENGG1100. Ch6-Digital Logic (part2) v3h17

Program example for our robot You only need to edit the program to change the desired truth table The program segment that produces the truth table on the right void LogicTable() { // S4,S3,S2,S1 are the least significant 4 bits of IN_sensor in the program switch (IN_sensor) // 0b00FEDCBA { case 0bxxxxxx11 : LM1(1);LM2(0);RM1(1);RM2(0); break; case 0bxxxxxx10 : LM1(1);LM2(0);RM1(0);RM2(0); break; case 0bxxxxxx01 : LM1(0);LM2(0);RM1(1);RM2(0); break; default : LM1(0);LM2(0);RM1(0);RM2(0 ); break; } ENGG1100. Ch6-Digital Logic (part2) v3h 18 InputsOutputs S2S1LM1LM2RM1RM Magnetic sensors S1, S3 S2 S2 S3 S1

To be done in the lab : Lab5.ino from Experiment 1.3: Fill in the truth table of the AND logic function after you completed the following procedures. (Hardware experiment is required for this and the following exercises) //program segment in the main loop of Lab5.ino void loop() { // Experiment 1.3 OUT1=S1 AND S3 if(Din1() && Din3()) Out1(1); else Out1(0); : } ENGG1100. Ch6-Digital Logic (part2) v3h19 Din1 (), Din(3) LED to represent OUT1() InputsOutputs Q S3S1LED3LED1LED7Out1 00ON 01 OFF 10 ON 11OFF

Appendix1: Answer for the exercise1 //LM2 = S3 OR S4 If (S3()==1 || S4()==1) LM2(1); Else LM2(0); If (S4()==0 && S1()==1) LM1(0); Else LM1(1); Explain in English the meaning of the above statements – ?? ans: if S3 is 1 OR S4 is 1 LM2 is 1, else LM2 is 0 – ans: if S4 is 0 AND S1 is 1 LM1 is 0, else LM2 is 1 ENGG1100. Ch6-Digital Logic (part2) v3h20

Appendix2: Answer: Exercise 2:Truth table example to make our robot follow the magnetic strip Case 1)S2=1, S1=1 (on both sides of magnetic strip): Robot should move forward 2)S2=0, S1=1 (robot on the left side of the magnetic strip): Robot should turn right 3)S2=1, S1=0 (robot on the right side of the magnetic strip): Robot should turn left 4)S2=0,S1=0 (robot reaches the terminal) : Robot should stop ENGG1100. Ch6-Digital Logic (part2) v3h21 Case InputsOutputs S2S1LM1LM2RM1RM2 1) ) ) ) Magnetic strip S1 S2 forward:LM1, LM2, RM1, RM2=“1010” turn right:LM1, LM2, RM1, RM2=“1000” turn left:LM1, LM2, RM1, RM2=“0010” S1 S2 Fill in the table Robot

Appendix 3: Reference Main loop of experiment5(lab5.ino) from void loop() { // Experiment 1.3 OUT1=S1 AND S3 if(Din1() && Din3()) Out1(1); else Out1(0); // Experiment 1.4 OUT3=S1 OR S3 if(Din1() || Din3()) Out3(1); else Out3(0); // Experiment 2.1 OUT2=(S2 AND S3) AND S4 if((Din2() && Din3()) && Din4()) Out2(1); else Out2(0); // Experiment 2.2 OUT4=(S2 AND S3) OR S4 if((Din2() && Din3()) || Din4()) Out4(1); else Out4(0); } ENGG1100. Ch6-Digital Logic (part2) v3h22

Appendix 4 Truth table example to make our robot follow the magnetic strip InputsOutputs S4S3S2S1LM1LM2RM1RM Table 1: Truth Table of Smart car control logic ENGG1100. Ch6-Digital Logic (part2) v3h23