Teaching Assistant: Roi Yehoshua

Slides:



Advertisements
Similar presentations
Teaching Assistant: Roi Yehoshua
Advertisements

CMSC 2021 C++ I/O and Other Topics. CMSC 2022 Using C++ Stream I/O Default input stream is called cin Default output stream is called cout Use the extraction.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
Command-line arguments CS 201 Fundamental Structures of Computer Science.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
ARRAYS AND POINTERS Although pointer types are not integer types, some integer arithmetic operators can be applied to pointers. The affect of this arithmetic.
Teaching Assistant: Roi Yehoshua
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
1 Chapter 8 Scope, Lifetime, and More on Functions Dale/Weems/Headington.
CSE 332: C++ program structure and development environment C++ Program Structure (and tools) Today we’ll talk generally about C++ development (plus a few.
Teaching Assistant: Roi Yehoshua
1 The UNIX date command myclock.cpp example The C/C++ time() and ctime() functions myclock2.cpp example Inline function definitions Inline class member.
Teaching Assistant: Roi Yehoshua
University of Calgary – CPSC 441. C PROGRAM  Collection of functions  One function “main()” is called by the operating system as the starting function.
Teaching Assistant: Roi Yehoshua
1 Chapter 9 Scope, Lifetime, and More on Functions.
Teaching Assistant: Roi Yehoshua
Pointers CS362. Pointers A Pointer is a variable that can hold a memory address Pointers can be used to: Indirectly reference existing variables (sometimes.
Variables, Functions & Parameter Passing CSci 588 Fall 2013 All material not from online sources copyright © Travis Desell, 2011.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
SEN 909 OO Programming in C++ Final Exam Multiple choice, True/False and some minimal programming will be required.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Teaching Assistant: Roi Yehoshua
CHAPTER 13 CLASSES AND DATA ABSTRACTION. In this chapter, you will:  Learn about classes  Learn about private, protected, and public members of a class.
ITEC 320 C++ Examples.
1 C++ Syntax and Semantics, and the Program Development Process.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Command Line Arguments.
File IO and command line input CSE 2451 Rong Shi.
1 Command-Line Processing In many operating systems, command-line options are allowed to input parameters to the program SomeProgram Param1 Param2 Param3.
CPS4200 Unix Systems Programming Chapter 2. Programs, Processes and Threads A program is a prepared sequence of instructions to accomplish a defined task.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
4.1 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Project1: Unix Shell with History Feature Goals Descriptions Methodology Submission.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Teaching Assistant: Roi Yehoshua
C++ / G4MICE Course Session 2 Basic C++ types. Control and Looping Functions in C Function/method signatures and scope.
Teaching Assistant: Roi Yehoshua
Operating Systems Process Creation
What is a Process? u A process is an executable “cradle” in which a program may run u This “cradle” provides an environment in which the program can run,
Fall 2002 CS 325 Class Notes Page 1 Lecture 25 Today –exec() in Unix –CreateProcess in Windows Announcements.
Navigating the C++ Development Environment
Java and C++ Transitioning. A simple example public class HelloWorldApp { public static void main(String[] args) { //Display the string. System.out.println("Hello.
Teaching Assistant: Roi Yehoshua
Copyright © Curt Hill The Compound Statement C-Family Languages and Scope.
System Programming Practical Session 7 C++ Memory Handling.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Recursion.
Teaching Assistant: Roi Yehoshua
1 CSC 222: Computer Programming II Spring 2004 Stacks and recursion  stack ADT  push, pop, top, empty, size  vector-based implementation, library 
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
Teaching Assistant: Roi Yehoshua
1 Chapter 8 Scope, Lifetime, and More on Functions CS185/09 - Introduction to Programming Caldwell College.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
CSE 332: C++ Exceptions Motivation for C++ Exceptions Void Number:: operator/= (const double denom) { if (denom == 0.0) { // what to do here? } m_value.
Lecturer: Roi Yehoshua
Chapter 6 CS 3370 – C++ Functions.
Command Line Arguments
Agenda Make Utility Command Line Arguments in Unix
OOP-4-Templates, ListType
Command-Line Arguments
C Basics.
Multi-Robot Systems with ROS Lesson 10
Pointers, Dynamic Data, and Reference Types
Robotic Perception and Action
Robotic Perception and Action
Functions Reasons Concepts Passing arguments to a function
Presentation transcript:

Teaching Assistant: Roi Yehoshua

Basic TAO plan example Runtime inspection of DM models World model (C)2015 Roi Yehoshua

TAO_PLAN(PLAN_NAME) { TAO_START_CONDITION TAO_ALLOCATION TAO_CALL_TASK(TaskName) TAO_STOP_CONDITION TAO_NEXT TAO_CLEANUP_BGN { TAO_CALL_TASK(TaskName) } TAO_CLEANUP_END } TAO_PLAN(PLAN_NAME) { TAO_START_CONDITION TAO_ALLOCATION TAO_CALL_TASK(TaskName) TAO_STOP_CONDITION TAO_NEXT TAO_CLEANUP_BGN { TAO_CALL_TASK(TaskName) } TAO_CLEANUP_END } Tasks called upon plan execution After STOP_CONDITION is satisfied, apply PROTOCOL to select next plan for execution Optional exit actions Allocate sub-plans Validated before plan is selected for running Validated all the time while the plan is running

(C)2015 Roi Yehoshua We will start with a basic plan that will increment a counter from 0 to 100 and will stop when reaching 100 Create a new package in dmw workspace called single_dm_demos with dependencies on decision_making and decision_making_parser: $ cd dmw/src $ catkin_create_pkg tao_plans roscpp decision_making decision_making_parser $ cd dmw/src $ catkin_create_pkg tao_plans roscpp decision_making decision_making_parser

(C)2015 Roi Yehoshua Compile the package and create an Eclipse project file for it: Now open the project in Eclipse If there are issues with compiling the project, then: – Go to Project Properties --> C/C++ General --> Preprocessor Include Paths, Macros, etc. --> Providers tab – Check CDT GCC Built-in Compiler Settings [Shared] – Rebuild the C/C++ index by Right click on project -> Index -> Rebuild $ cd ~/dmw $ catkin_make --force-cmake -G"Eclipse CDT4 - Unix Makefiles" $ cd ~/dmw $ catkin_make --force-cmake -G"Eclipse CDT4 - Unix Makefiles"

(C)2015 Roi Yehoshua Add a C++ source file to the project called BasicPlan.cpp

(C)2015 Roi Yehoshua #include #include using namespace std; using namespace decision_making; int counter = 0; #include #include using namespace std; using namespace decision_making; int counter = 0;

(C)2015 Roi Yehoshua TAO(Incrementer) { TAO_PLANS { Increment } TAO_START_PLAN(Increment); TAO_BGN { TAO_PLAN(Increment) { TAO_START_CONDITION(counter < 100); counter++; cout << "counter: " << counter << endl; sleep(1); TAO_ALLOCATE_EMPTY TAO_STOP_CONDITION(true); TAO_NEXT(NextFirstReady) { TAO_NEXT_PLAN(Increment); } TAO_END } TAO(Incrementer) { TAO_PLANS { Increment } TAO_START_PLAN(Increment); TAO_BGN { TAO_PLAN(Increment) { TAO_START_CONDITION(counter < 100); counter++; cout << "counter: " << counter << endl; sleep(1); TAO_ALLOCATE_EMPTY TAO_STOP_CONDITION(true); TAO_NEXT(NextFirstReady) { TAO_NEXT_PLAN(Increment); } TAO_END } The code block here is executed before the stop condition is checked. Thus, the stop condition is relevant only when working with tasks

(C)2015 Roi Yehoshua int main(int argc, char **argv) { ros::init(argc, argv, "basic_plan"); ros::NodeHandle nh; ros_decision_making_init(argc, argv); ros::AsyncSpinner spinner(1); spinner.start(); RosEventQueue eventQueue; CallContext context; eventQueue.async_spin(); ROS_INFO("Starting incrementer plan..."); TaoIncrementer(&context, &eventQueue); eventQueue.close(); ROS_INFO("TAO finished."); return 0; } int main(int argc, char **argv) { ros::init(argc, argv, "basic_plan"); ros::NodeHandle nh; ros_decision_making_init(argc, argv); ros::AsyncSpinner spinner(1); spinner.start(); RosEventQueue eventQueue; CallContext context; eventQueue.async_spin(); ROS_INFO("Starting incrementer plan..."); TaoIncrementer(&context, &eventQueue); eventQueue.close(); ROS_INFO("TAO finished."); return 0; }

(C)2015 Roi Yehoshua To execute a given TAO, call the following function in your C++ code: – ctx: pointer to current context Can be NULL – eventQueue: pointer to events system Cannot be NULL This function is blocked until TAO is finished (preempted, stopped by TAO_RESULT or EventQueue is closed) TaskResult TaoNAME(const CallContext* ctx, EventQueue* eventQueue)

(C)2015 Roi Yehoshua This class is used for sharing parameters and context information across different TAO machines Utility functions for handling parameters: – void createParameters(A* a= new A()) - create instance of parameters of type A(template) – A& parameters() - get parameters – bool isParametersDefined() const - check if parameters have been created before Context is used for teamwork as well (more on this later)

Add the following lines to CMakeLists.txt Build the package by calling catkin_make (C)2015 Roi Yehoshua add_executable(basic_plan src/BasicPlan.cpp) target_link_libraries(basic_plan ${catkin_LIBRARIES}) add_executable(basic_plan src/BasicPlan.cpp) target_link_libraries(basic_plan ${catkin_LIBRARIES})

Use rosrun to run the node: (C)2015 Roi Yehoshua

You can use ros and rqt to view, monitor, record and interact with the decision making model To enable visualization of the model add the following line to the CMakeLists.txt file (just after target_link_libraries command): This command ensures that your model will be converted to xml and dot formats (for visualization) decision_making_parsing(src/BasicPlan.cpp)

(C)2015 Roi Yehoshua The xml and dot files will be created in the folder ~/dmw/devel/share/tao_plans/graphs

(C)2015 Roi Yehoshua Incrementer plan’s graph (incrementer.dot.gif):

(C)2015 Roi Yehoshua Plan converted to XML:

(C)2015 Roi Yehoshua In order to see visually the model in runtime, use the Decision Making rqt plugin First run rqt: Choose the Decision Making graph plugin: $ rqt

Once the model is running, the visualization of your model should be loaded automatically (C)2015 Roi Yehoshua

WorldModel is a struct derived from CallContextParameters and holds parameters that are shared across TAO machines It must implement a str() function that returns its string representation In the next example we will use a world model to store the counter instead of the global counter variable Copy BasicPlan.cpp to BasicPlanWithWM.cpp and add the following code

(C)2015 Roi Yehoshua struct WorldModel : public CallContextParameters { int counter; string str() const { stringstream s; s << "counter=" << counter; return s.str(); } }; #define WM TAO_CONTEXT.parameters () struct WorldModel : public CallContextParameters { int counter; string str() const { stringstream s; s << "counter=" << counter; return s.str(); } }; #define WM TAO_CONTEXT.parameters ()

(C)2015 Roi Yehoshua TAO(Incrementer) { TAO_PLANS { Increment } TAO_START_PLAN(Increment); TAO_BGN { TAO_PLAN(Increment) { TAO_START_CONDITION(WM.counter < 100); WM.counter++; cout << "counter: " << WM.counter << endl; boost::this_thread::sleep(boost::posix_time::milliseconds(100)); TAO_ALLOCATE_EMPTY TAO_STOP_CONDITION(true); TAO_NEXT(NextFirstReady){ TAO_NEXT_PLAN(Increment); } TAO_END } TAO(Incrementer) { TAO_PLANS { Increment } TAO_START_PLAN(Increment); TAO_BGN { TAO_PLAN(Increment) { TAO_START_CONDITION(WM.counter < 100); WM.counter++; cout << "counter: " << WM.counter << endl; boost::this_thread::sleep(boost::posix_time::milliseconds(100)); TAO_ALLOCATE_EMPTY TAO_STOP_CONDITION(true); TAO_NEXT(NextFirstReady){ TAO_NEXT_PLAN(Increment); } TAO_END }

(C)2015 Roi Yehoshua int main(int argc, char **argv) { ros::init(argc, argv, "basic_plan_wm"); ros::NodeHandle nh; ros_decision_making_init(argc, argv); ros::AsyncSpinner spinner(1); spinner.start(); RosEventQueue eventQueue; CallContext context; context.createParameters(new WorldModel()); eventQueue.async_spin(); ROS_INFO("Starting incrementer plan..."); TaoIncrementer(&context, &eventQueue); eventQueue.close(); ROS_INFO("TAO finished."); return 0; } int main(int argc, char **argv) { ros::init(argc, argv, "basic_plan_wm"); ros::NodeHandle nh; ros_decision_making_init(argc, argv); ros::AsyncSpinner spinner(1); spinner.start(); RosEventQueue eventQueue; CallContext context; context.createParameters(new WorldModel()); eventQueue.async_spin(); ROS_INFO("Starting incrementer plan..."); TaoIncrementer(&context, &eventQueue); eventQueue.close(); ROS_INFO("TAO finished."); return 0; }

Use rosrun to run the node: (C)2015 Roi Yehoshua