Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   COmmand based software Interrupts (http://www.chiefdelphi.com/forums/showthread.php?t=135550)

JefferMC 12-03-2015 21:07

Re: COmmand based software Interrupts
 
Quote:

Originally Posted by otherguy (Post 1457041)

Here's why using the joy1button4->WhileHeld(new DropElevator()); as an example:
  1. Joy 1 Button 4 is pressed.
  2. A new command is created and added into the scheduler (DropElevator)

A small nit. The DropElevator() will be constructed by the new operator when this line of code in OI.CPP is executed. A pointer to that object will be passed to the WhileHeld method of the CommandButton class for the joy1button4 object. It will retain this pointer for use later when the button is held, thus, the correct order is:
  1. OI's constructor is called.
  2. The DropElevator command is created and its constructor called
    ...
  3. The button is pushed, triggering the WhileHeld
  4. The DropElevator's Initialize method is called
  5. The DropElevator's Execute method is called for the first time and will be called for every iteration until the button is released. To be honest, if Interupted() is called, or IsFinished() returns true, I'm not sure what the command based system might do with the fact that the button is still held.

The fact there is only one object created at Robot init (vs. one created every time the button is held) is only important if your command has member variables that might make a difference to you how many objects there are.


All times are GMT -5. The time now is 14:02.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi