CMPE 118 MECHATRONICS Modular Programming Where the rubber meets the Code.

Slides:



Advertisements
Similar presentations
Construction process lasts until coding and testing is completed consists of design and implementation reasons for this phase –analysis model is not sufficiently.
Advertisements

R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
CS 450 Module R4. R4 Overview Due on March 11 th along with R3. R4 is a small yet critical part of the MPX system. In this module, you will add the functionality.
Programming Languages and Paradigms The C Programming Language.
Input and Output CS 215 Lecture #20.
Chapter 1: Computer Systems
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 6 Functions.
CMPE 118 MECHATRONICS Group Design Review Here we go…
CMPE 118 MECHATRONICS Event-Driven Programming and State Machines.
Computer System Overview
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 6: Functions by.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Lesson 6 Functions Also called Methods CS 1 Lesson 6 -- John Cole1.
TCP: Software for Reliable Communication. Spring 2002Computer Networks Applications Internet: a Collection of Disparate Networks Different goals: Speed,
EDGE AVOIDER ROBOT USING I-BOT mini V3. EDGE AVOIDER USING I-BOT mini V3 Edge Avoider Robot is built using the IR based Line Detecting Module. The modules.
Hardware Interface Design Patterns Ahmet Selman Bozkır – Hacettepe Univ.
Shell and Flashing Images Commands and upgrades. RS-232 Driver chip – ST3232C Driver chip is ST3232C Provides electrical interface between UART port and.
Tom and Jerry By: Nicholas Johnson & Joshua Hartman EEL-5666 – Intelligent Machines Design Lab.
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.
Operator Precedence First the contents of all parentheses are evaluated beginning with the innermost set of parenthesis. Second all multiplications, divisions,
Computer System Overview Chapter 1. Operating System Exploits the hardware resources of one or more processors Provides a set of services to system users.
The Java Programming Language
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 6 Functions.
Copyright © 2012 Pearson Education, Inc. Chapter 6: Functions.
Chapter 6: Functions Starting Out with C++ Early Objects
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
1-1 NET+OS Software Group Flash API Multiple flash memory bank support New Flash API introduction Detailed Flash API Function presentation Supporting.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
VHDL FLI. FLI Definition FLI routines are C programming language functions that provide procedural access to information within the HDL simulator.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Software Engineering Gabriel Hugh Elkaim Spring 2013.
Introduction to Biometrics Dr. Bhavani Thuraisingham The University of Texas at Dallas Lecture #23 Biometrics Standards - II November 14, 2005.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6: Functions Starting Out with C++ Early Objects Seventh Edition.
Device Drivers CPU I/O Interface Device Driver DEVICECONTROL OPERATIONSDATA TRANSFER OPERATIONS Disk Seek to Sector, Track, Cyl. Seek Home Position.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Object-Oriented Programming •Object-Oriented Programming (OOP) allows you to create your program based upon modeling objects.  Your program’s properties.
RELIABILITY ENGINEERING 28 March 2013 William W. McMillan.
Overview Task State Diagram Task Priority Idle Hook AND Co-Routines
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
PLC ARCHITECTURE - CPU by Dr. Amin Danial Asham.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 6 Functions.
Starting Out with C++ Early Objects ~~ 7 th Edition by Tony Gaddis, Judy Walters, Godfrey Muganda Modified for CMPS 1044 Midwestern State University 6-1.
1 Brief Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 29P. 1Winter Quarter Software Design Project Lecture 29.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Why Use Classes - Anatomy of a Class.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Brief Edition Chapter 6 Functions.
Chapter 6 Functions. Topics Basics Basics Simplest functions Simplest functions Functions receiving data from a caller Functions receiving data from a.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Network Architecture Protocol hierarchies Design Issues for the layers
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
Embedded Programming B. Furman 09MAY2011. Learning Objectives Distinguish between procedural programming and embedded programming Explain the Events and.
Using HeaderDoc to make complete documentation as Html file. By Naveed Khalid.
TinyOS Sandeep Gupta. Operating System (OS) What is an OS? Main functions  Process management  Memory management  Resource management Traditional OSs.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 6: Functions.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
Chapter 6 Functions. 6-2 Topics 6.1 Modular Programming 6.2 Defining and Calling Functions 6.3 Function Prototypes 6.4 Sending Data into a Function 6.5.
CEN6502, Spring Understanding the ORB: Client Side Structure of ORB (fig 4.1) Client requests may be passed to ORB via either SII or DII SII decide.
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
6 Chapter Functions.
Introduction to Classes and Objects
COP 3330 Object-oriented Programming in C++
Standard Version of Starting Out with C++, 4th Edition
Classes and Objects Systems Programming.
Presentation transcript:

CMPE 118 MECHATRONICS Modular Programming Where the rubber meets the Code

CMPE 118 MECHATRONICS The three uses of static

CMPE 118 MECHATRONICS Encapsulation Groups Publishes Hides together the data and the functions that operate on the data an interface to the rest of the code the details of the implementation

CMPE 118 MECHATRONICS Encapsulation

CMPE 118 MECHATRONICS What goes into a header file?

CMPE 118 MECHATRONICS What shouldn’t be in a header file?

CMPE 118 MECHATRONICS Where do you #include the header file?

CMPE 118 MECHATRONICS

Module Design by Interface Specification View: The module provides Services to the rest of the code Design Activities: Specify the Services Describe Functionality Name the Services Design the implementation

CMPE 118 MECHATRONICS Application Programming Interfaces (API) for the ME218c Master modules Module: Communications to UI on PC To avoid hanging up the master during the transmission or reception of messages, this module should implement buffered, interrupt driven transmit and receive. The communications routines for this module will need to be interrupt driven because the UI may send its message at any time. Char InitializeUICommunications(void); Do whatever hardware and software initialization necessary to prepare for communications with the UI on SC1. Void TellUINewUserReady(void); Should send the message to the UI that a new iButton has been inserted and read. Unsigned char IsNameReady(void); Should check to see if a new name is ready from the UI. Return TRUE if a new name is ready, FALSE otherwise. Unsigned char GetNewName( unsigned char NameSpace[]) Should copy the name gotten from the UI into the array NameSpace. The copy operation should copy no more than 16 characters, including the terminating NULL. Should return TRUE if there was a new name ready, FALSE otherwise. A Real Example

CMPE 118 MECHATRONICS Design the interfaces to modules for Driving the platform Gathering sensor data Produce: Public interface specification What are the details that are being hidden?

CMPE 118 MECHATRONICS Mike, Ian, and James // mike, james, and ian // cmpe 118, spring 05 // these functions or for the motor and sensory control of our final project // motor direction defines #define forward 1 #define brake0 #define backward-1 #define success1 #define failure0 // Motor control functions char wheel_left(char direction, char speed); char wheel_right(char direction, char speed); // given a direction and a speed between 0 and 10 it return 0 if failure // and 1 if successful. // The bot can coast by giving a direction of "forward" or "backward" with a speed of 0, // or it can brake by giving any speed with a direction of "brake".

CMPE 118 MECHATRONICS // bump sensors char bump_sensors(void); // When called it will return a char where the upper four bits are always 0 then front left, front right, back right, back left. // line sensors char line_sensors(void); // when called it will return a char where the upper four bits are always 0 then forward left, // forward middle, forward right, and middle; // aiming sensors char aim_sensors(void); // when called it will return a char where the top six bits are zero left aiming photo transistor, // and right aiming photo transistor. // firing solenoid char firing(char); // when passed a 1 solenoid is open and it firing, when passed a 0 is closed. Will return 0 for // failure and 1 for success.

CMPE 118 MECHATRONICS Thomas, Maria, and Oscar DRIVING void LeftMtrSpeed(uchar speed) void RightMtrSpeed(uchar speed) IR uchar getBroadIR() //Returns IR level for broad sensor uchar getAccurateIR() //Returns IR level for narrow sensor TAPE uchar checkTape() //Returns solid state for tape (could be boolean) TURRET uchar TurnLeft(uchar distance) // Returns status uchar TurnRight(uchar distance) // checks for homeswitch BUMPERS uchar getBumpers() //Returns which bumpers are pressed

CMPE 118 MECHATRONICS John and Suraj #ifndef DROID_H #define DROID_H #include "util.h" // types typedef enum { DIRECTION_LEFT, DIRECTION_RIGHT, DIRECTION_FORWARD, DIRECTION_BACKWARD } Direction; // functions /** Makes the droid search for a target (tie fighter or death-star beacon) by slowly rotating and scanning in the direction a_dir The direction in which to scan for a false when no target has been detected. */ boolean Droid_scan(Direction a_dir); /** Makes the droid seek out its nearest target and orient itself such that it is facing the target. From here, the droid may proceed forward and engage the false when no target has been detected. */ boolean Droid_seek(); /**Makes the droid engage its nearest target by driving forward, while dynamically adjusting its trajectory, until the droid is within point-blank firing range. Next, the droid fires a foam ball at the false when no target has been detected. */ boolean Droid_engage();

CMPE 118 MECHATRONICS /**Rotates the droid, in the given direction, by the given number of a_dir The direction in which the droid shall a_numSteps The number of discrete rotational steps the droid shall undertake in its false upon failure. */ boolean Droid_rotate(Direction a_dir, uint a_numSteps); /**Drives the droid, in the given direction, by the given number of a_dir The direction in which the droid shall a_numSteps The number of discrete translational steps the droid shall undertake in its false upon failure. */ boolean Droid_drive(Direction a_dir, uint a_numSteps); #endif

CMPE 118 MECHATRONICS #ifndef SENSORS_H #define SENSORS_H #include "util.h" // types typedef enum { SENSOR_PRECISION, SENSOR_LEFT, SENSOR_RIGHT, SENSOR_BUMP } Sensor; // functions /** Initializes all sensors on the droid. */ void Sensors_init(); /** Initializes the specified sensor on the a_sensor The sensor we wish to initialize. */ void Sensors_initSensor(const Sensor a_sensor); /** Returns the quantified strength of the signal being sensed by the specified a_sensor The sensor whose signal strength we wish to retrieve.*/ uint Sensors_getSensorStrength(const Sensor a_sensor); #endif

CMPE 118 MECHATRONICS Mike, Ian, and Dev

CMPE 118 MECHATRONICS

Hierarchical State Machines (Harel Statecharts)

CMPE 118 MECHATRONICS

A Possible Top-Level State Diagram

CMPE 118 MECHATRONICS Work out State Diagrams to Implement Finding Tape I

CMPE 118 MECHATRONICS

Implementing Hierarchical State Machines What do you need?

CMPE 118 MECHATRONICS If current state is state one Execute During function for state one If an event is active If event is event one Execute action function for state one : event one Decide what the next state will be Endif If event is event two Execute action function for state one : event two Decide what the next state will be Endif Repeat the block above as required for each of the possible events affecting this state. If next state is different from current state Execute exit function for state one Execute entry function for new state Modify state variable to reflect the new state Endif Return from state machine function State Machine Function Template

CMPE 118 MECHATRONICS /**************************************************************************** Module d:\me218b\Lectures\Lecture 29\SMTemplate.c Description This is a template file for implementing state machines. Notes History When Who What/Why /18/99 10:19 jec built template from MasterMachine.c 02/14/99 10:34 jec Began Coding ****************************************************************************/ /* Include Files */ /* include header files for this state machine as well as any machines at the next lower level in the hierarchy that are sub-machines to this machine */ /* Module Defines */ // define constants for the states and event for this machine /* Module Functions */ /* prototypes for private functions for this machine, things like entry & exit functions. */ /* Module Variables */ // everybody needs a state variable, you may need others as well static unsigned char CurrentState;

CMPE 118 MECHATRONICS void RunStateMachine(unsigned char CurrentEvent ) { unsigned char NextState = CurrentState; switch ( CurrentState ) { case STATE_ONE : // If current state is state one DuringStateOne(); //Execute During function for state one if ( CurrentEvent != NO_EVENT ) //If an event is active { switch ( CurrentEvent) { case EVENT_ONE : //If event is event one // Execute action function for state one : event one NextState = STATE_TWO;//Decide what the next state will be break; } // If next state is different from current state if ( NextState != CurrentState) { // Execute exit function for current state // Execute entry function for new state CurrentState = NextState; //Modify state variable } return;

CMPE 118 MECHATRONICS /**************************************************************************** Function StartStateMachine Parameters None Returns None Description Does any required initialization for this state machine Notes Author J. Edward Carryer, 2/18/99, 10:38AM ****************************************************************************/ void StartStateMachine ( void ) { CurrentState = ENTRY_STATE; // call the (optional) entry function for the ENTRY_STATE // any other initialization necessary to re-start the state machine }