The Cruise Control Control System shall maintain a desired speed when engaged. It shall receive control commands (on, set, compare, resume, brake, and off) from cruise control HW (Timer, Driver Buttons, and Brake Sensor). It shall get the current speed from cruise control HW (Speedometer). It shall send a throttle setting (released, increasing, no_change, decreasing) to cruise control HW (Throttle).
| System Name | Attribute Names | System Operation Names |
| CruiseControlHW | getSpeed setThrottle releaseThrottle | |
| CruiseControlSystem | currentSpeed desiredSpeed throttleSetting | on setDesiredSpeed compare brake resume off |
System Name: Cruise Control System
System Access: Public
System Imports: NA
Enclosing System: NA
System Description: The Cruise Control System controls
an automotive throttle.
| Entity Name | Type of Entity | Enclosing System |
| CruiseControlSystem | System | -- |
| CruiseControlHW | Interacting System | -- |
| currentSpeed | System Attribute | CruiseControlSystem |
| desiredSpeed | System Attribute | CruiseControlSystem |
| throttleSetting | System Attribute | CruiseControlSystem |
| getSpeed | System Operation | CruiseControlHW |
| setThrottle | System Operation | CruiseControlHW |
| releaseThrottle | System Operation | CruiseControlHW |
| on | System Operation | CruiseControlSystem |
| setDesiredSpeed | System Operation | CruiseControlSystem |
| compare | System Operation | CruiseControlSystem |
| brake | System Operation | CruiseControlSystem |
| resume | System Operation | CruiseControlSystem |
| off | System Operation | CruiseControlSystem |
| Number | Initiating Actor | Use Case/Subuse Case | Use Case Description |
| 1 | User | Operate Cruise Control | This use case has 6 sub-use cases |
| 1.1 | User | Turn Cruise Control On | Input Event on |
| 1.2 | User | Set Desired Speed | Input Event setDesiredSpeed - Output Event getSpeed |
| 1.3 | User | Compare Desired and Current Speed | Input Event compare - Output Events getSpeed setThrottle |
| 1.4 | User | Brake and Release Cruise Control | Input Event brake Output Event releaseThrottle |
| 1.5 | User | Resume Cruise Control | Input Event resume |
| 1.6 | User | Turn Cruise Control Off | Input Event off Output Event releaseThrottle |
| Sequence
Number | Sender System | Receiver System | Invoked Operation | Description |
| 1 | Cruise Control HW | Cruise Control System | on | Input Event |
| 2 | Cruise Control HW | Cruise Control System | setDesiredSpeed | Input Event |
| 3 | Cruise Control System | Cruise Control HW | getSpeed | Output Event |
| 4 | Cruise Control HW | Cruise Control System | compare | Input Event |
| 5 | Cruise Control System | Cruise Control HW | getSpeed | Output Event |
| 6 | Cruise Control System | Cruise Control HW | setThrottle | Output Event |
| 7 | Cruise Control HW | Cruise Control System | brake | Input Event |
| 8 | Cruise Control System | Cruise Control HW | releaseThrottle | Output Event |
| 9 | Cruise Control HW | Cruise Control System | resume | Input Event |
| 10 | Cruise Control HW | Cruise Control System | off | Input Event |
| 11 | Cruise Control System | Cruise Control HW | releaseThrottle | Output Event |
| State Name | Event Name | Transition Condition | Transition Action | Transition Next State |
| OffState | on() | ReadyState | ||
| OffState | off() | TerminalState | ||
| ReadyState | setDesiredSpeed() | getSpeed | ControllingState | |
| ReadyState | off() | releaseThrottle | TerminalState | |
| ControllingState | off() | releaseThrottle | TerminalState | |
| ControllingState | compare() | getSpeed setThrottle | ControllingState | |
| ControllingState | brake() | releaseThrottle | SuspendedState | |
| SuspendedState | resume() | ControllingState | ||
| SuspendedState | off() | releaseThrottle | TerminalState |
Creams (return aNumber) Returns number of creams
| System Name | System Operation Name | Input Parameters | Transformation | Return Type |
| CruiseControlSystem | on | void | ||
| CruiseControlSystem | setDesiredSpeed | desiredSpeed = currentSpeed | void | |
| CruiseControlSystem | compare | if (currentSpeed < desiredSpeed) throttleSetting = increasing;
if (currentSpeed == desiredSpeed) throttleSetting = no_change; if (currentSpeed > desiredSpeed) throttleSetting = decreasing; | void | |
| CruiseControlSystem | brake | throttleSetting = released | void | |
| CruiseControlSystem | resume | void | ||
| CruiseControlSystem | off | throttleSetting = released | void |
| Class Name | Attribute Names | Relationship Traversal Path Names | Operation Names |
| HWInterfaceResponses | getSpeed setThrottle releaseThrottle | ||
| Throttle | setting | getThrottleSetting | |
| Speed | desiredSpeed currentSpeed speedComparison | setCurrentSpeed setDesiredSpeed currentSpeedComparison | |
| CruiseControl | state | theHWInterface theThrottle theSpeed | on setDesiredSpeed compare brake resume off |
| HWInterfaceEvents | theCruiseControl | on setDesiredSpeed compare brake resume off |
| Entity Name | Type of Entity | Enclosing Class |
| HWInterfaceResponses | Class | -- |
| Throttle | Class | -- |
| Speed | Class | -- |
| CruiseControl | Class | -- |
| HWInterfaceEvents | Class | -- |
| setting | Attribute | Throttle |
| desiredSpeed | Attribute | Speed |
| currentSpeed | Attribute | Speed |
| speedComparison | Attribute | Speed |
| state | Attribute | CruiseControl |
| getSpeed | Operation | HWInterfaceResponses |
| setThrottle | Operation | HWInterfaceResponses |
| releaseThrottle | Operation | HWInterfaceResponses |
| getThrottleSetting | Operation | Throttle |
| setCurrentSpeed | Operation | Speed |
| setDesiredSpeed | Operation | Speed |
| currentSpeedComparison | Operation | Speed |
| on | Operation | CruiseControl |
| setDesiredSpeed | Operation | CruiseControl |
| compare | Operation | CruiseControl |
| brake | Operation | CruiseControl |
| resume | Operation | CruiseControl |
| off | Operation | CruiseControl |
| on | Operation | HWInterfaceEvents |
| setDesiredSpeed | Operation | HWInterfaceEvents |
| compare | Operation | HWInterfaceEvents |
| brake | Operation | HWInterfaceEvents |
| resume | Operation | HWInterfaceEvents |
| off | Operation | HWInterfaceEvents |
| theHWInterface | Traversal Path for 1:1 Aggregation | CruiseControl |
| theThrottle | Traversal Path for 1:1 Aggregation | CruiseControl |
| theSpeed | Traversal Path for 1:1 Aggregation | CruiseControl |
| theCruiseControl | Traversal Path for 1:1 Aggregation | HWInterfaceEvents |
| Sequence # | Sender System/Object | Receiver System/Object | Invoked Operation | Description |
| 0 | Cruise Control HW | theHWInterfaceEvents | on | Input Event |
| 1 | theHWInterfaceEvents | theCruiseControl | on | Message |
| 2 | Cruise Control HW | theHWInterfaceEvents | setDesiredSpeed | Input Event |
| 3 | theHWInterfaceEvents | theCruiseControl | setDesiredSpeed | Message |
| 4 | theCruiseControl | theHWInterfaceResponse | getSpeed | Message |
| 5 | theHWInterfaceResponse | Cruise Control HW | getSpeed | Output Event |
| 6 | theCruiseControl | theSpeed | setDesiredSpeed | Message |
| 7 | Cruise Control HW | theHWInterfaceEvents | compare | Input Event |
| 8 | theHWInterfaceEvents | theCruiseControl | compare | Message |
| 9 | theCruiseControl | theHWInterfaceResponse | getSpeed | Message |
| 10 | theHWInterfaceResponse | Cruise Control HW | getSpeed | Output Event |
| 11 | theCruiseControl | theSpeed | setDesiredSpeed | Message |
| 12 | theCruiseControl | theSpeed | getSpeedComparison | Message |
| 13 | theCruiseControl | theThrottle | getThrottleSetting | Message |
| 14 | theCruiseControl | theHWInterfaceResponse | setThrottle | Message |
| 15 | theHWInterfaceResponse | Cruise Control HW | setThrottle | Output Event |
| 16 | Cruise Control HW | theHWInterfaceEvents | brake | Input Event |
| 17 | theHWInterfaceEvents | theCruiseControl | brake | Message |
| 18 | theCruiseControl | theHWInterfaceResponse | releaseThrottle | Message |
| 19 | theHWInterfaceResponse | Cruise Control HW | releaseThrottle | Output Event |
| 20 | Cruise Control HW | theHWInterfaceEvents | off | Input Event |
| 21 | theHWInterfaceEvents | theCruiseControl | off | Message |
| 22 | theCruiseControl | theHWInterfaceResponse | releaseThrottle | Message |
| 23 | theHWInterfaceResponse | Cruise Control HW | releaseThrottle | Output Event |
| State Name | Event Name | Transition Condition | Transition Action | Transition Next State |
| OffState | on() | ReadyState | ||
| OffState | off() | TerminalState | ||
| ReadyState | setDesiredSpeed() | theHWInterface.getSpeed theSpeed.setDesiredSpeed | ControllingState ReadyState | |
| ControllingState | off() | theHWInterface.releaseThrottle | TerminalState | |
| ControllingState | compare() | theHWInterface.getSpeed theSpeed.setCurrentSpeed theSpeed.currentSpeedComparison theThrottle.getThrottleSetting theHWInterface.setThrottle | ControllingState | |
| ControllingState | brake() | theHWInterface.releaseThrottle | SuspendedState | |
| SuspendedState | off() | theHWInterface.releaseThrottle | TerminalState | |
| SuspendedState | resume() | ControllingState |
| Class Name | Operation Name | Input Parameters | Transformation | Return Type |
| CruiseControl | on | void | ||
| CruiseControl | setDesiredSpeed | void | ||
| CruiseControl | compare | void | ||
| CruiseControl | brake | void | ||
| CruiseControl | resume | void | ||
| CruiseControl | off | void | ||
| HWInterfaceEvents | on | void | ||
| HWInterfaceEvents | setDesiredSpeed | void | ||
| HWInterfaceEvents | compare | void | ||
| HWInterfaceEvents | brake | void | ||
| HWInterfaceEvents | resume | void | ||
| HWInterfaceEvents | off | void | ||
| HWInterfaceResponses | getSpeed | int | ||
| HWInterfaceResponses | setThrottle | ThrottleSetting setting | void | |
| HWInterfaceResponses | releaseThrottle | void | ||
| Speed | setCurrentSpeed | int aSpeed | currentSpeed = aSpeed; | void |
| Speed | setDesiredSpeed | int aSpeed | desiredSpeed = aSpeed; | void |
| Speed | currentSpeedComparison | if (currentSpeed < desiredSpeed)
speedComparison = too_slow; if (currentSpeed > desiredSpeed) speedComparison = too_fast; if (currentSpeed == desiredSpeed) speedComparison = ok; | SpeedComparison | |
| Throttle | getThrottleSetting | SpeedComparison speed_comparison | switch (speed_comparison)
{ case too_slow : setting = increasing; break; case ok : setting = no_change; break; case too_fast : setting = decreasing; break; default: cout << "\nUnknown speed comparison - try again"; } return setting; | ThrottleSetting |
//Cruise Control Application Prototype file cruise.cpp
//Single file C++ prototype for educational purposes
#include <stdio.h>
#include <iostream.h>
enum SpeedComparison {too_slow,ok,too_fast};
enum States {off_state,ready,controlling,suspended};
enum ThrottleSetting
{released,increasing,no_change,decreasing};
//-----------------------------------------------------------
class HWInterfaceResponses {
public:
HWInterfaceResponses () { }
int getSpeed () const ;
void setThrottle (ThrottleSetting setting);
void releaseThrottle ();
};
int HWInterfaceResponses::getSpeed () const
{ int currentSpeed; cout << "\nEnter the current speed ";
cin >> currentSpeed; return currentSpeed;}
void HWInterfaceResponses::setThrottle (ThrottleSetting setting)
{ cout << "The throttle setting is " << setting;
cout << "\n0 - released, 1 - increasing,
2 - no_change, 3 -decreasing";}
void HWInterfaceResponses::releaseThrottle ()
{ cout << "\nThe throttle is released\n";}
class Throttle {
private:
ThrottleSetting setting;
public:
Throttle();
ThrottleSetting getThrottleSetting (SpeedComparison speed_comparison);
};
Throttle::Throttle() { setting = released; }
ThrottleSetting Throttle::getThrottleSetting (SpeedComparison speed_comparison)
{ switch (speed_comparison)
{ case too_slow : setting = increasing; break;
case ok : setting = no_change; break;
case too_fast : setting = decreasing; break;
default: cout << "\nUnknown speed comparison - try again";
}
cout << "\nThrottle adjustment - current speed is " << speed_comparison;
cout << "\n0 - too slow, 1 - ok, 2 - too fast\n";
return setting;
}
//---------------------------------------------------------------
class Speed {
private:
int desiredSpeed;
int currentSpeed;
SpeedComparison speedComparison;
public:
Speed();
void setCurrentSpeed (int aSpeed);
void setDesiredSpeed(int aSpeed);
SpeedComparison currentSpeedComparison();
};
Speed::Speed()
{ desiredSpeed = 0; currentSpeed = 0; speedComparison = ok;
}
void Speed::setCurrentSpeed(int aSpeed)
{ currentSpeed = aSpeed; }
SpeedComparison Speed::currentSpeedComparison ()
{ if (currentSpeed < desiredSpeed)
speedComparison = too_slow;
if (currentSpeed > desiredSpeed)
speedComparison = too_fast;
if (currentSpeed == desiredSpeed)
speedComparison = ok;
return (speedComparison);
}
void Speed::setDesiredSpeed (int aSpeed)
{ desiredSpeed = aSpeed;
}
//---------------------------------------------------------------
class CruiseControl {
private:
HWInterfaceResponses theHWInterface;
States state;
Throttle theThrottle; //object theThrottle
Speed theSpeed; //object theSpeed
public:
CruiseControl ();
void on ();
void setDesiredSpeed ();
void compare ();
void brake ();
void resume ();
void off ();
};
CruiseControl::CruiseControl()
{ state=off_state;
}
void CruiseControl::on ()
{ cout <<"\nDriver pressed the on button";
switch (state)
{ case off_state:
state = ready; break;
default: cout <<"\nCannot respond to the command - try again";
}
}
void CruiseControl::setDesiredSpeed ()
{ cout <<"\nDriver pressed the set desired speed button";
switch (state)
{ case ready || controlling || suspended:
int aSpeed = theHWInterface.getSpeed();
theSpeed.setDesiredSpeed (aSpeed);
cout << "\nDesired Speed is " << aSpeed;
state = controlling; break;
default: cout <<"\nCannot respond to the command - try again";
}
}
void CruiseControl::compare ()
{ SpeedComparison aSpeedComparison;
cout <<"\nTimer sent compare command";
switch (state)
{case controlling:
int aSpeed = theHWInterface.getSpeed();
theSpeed.setCurrentSpeed (aSpeed);
cout << "The current speed is " << aSpeed;
aSpeedComparison = theSpeed.currentSpeedComparison();
ThrottleSetting aSetting = theThrottle.getThrottleSetting
(aSpeedComparison);
theHWInterface.setThrottle (aSetting);
state = controlling; break;
default: cout <<"\nCannot respond to the command - try again";
}
}
void CruiseControl::brake ()
{ cout <<"\nDriver pressed the brake";
switch (state)
{ case controlling:
theHWInterface.releaseThrottle();
state = suspended; break;
default: cout <<"\nCannot respond to the command - try again";
}
}
void CruiseControl::resume ()
{ cout <<"\nDriver pressed the resume button";
switch (state)
{ case suspended:
state = controlling; break;
default: cout <<"\nCannot respond to the command - try again";
}
}
void CruiseControl::off ()
{ cout <<"\nDriver pressed the off button.";
theHWInterface.releaseThrottle();
cout << "\nThe Cruise Control is OFF";
state = off_state;
}
//---------------------------------------------------------------
class HWInterfaceEvents {
CruiseControl theCruiseControl;
public:
void on ();
void setDesiredSpeed ();
void compare ();
void brake ();
void resume ();
void off ();
};
void HWInterfaceEvents::on () {theCruiseControl.on
();};
void HWInterfaceEvents::setDesiredSpeed ()
{theCruiseControl.setDesiredSpeed ();}
void HWInterfaceEvents::compare ()
{theCruiseControl.compare ();}
void HWInterfaceEvents::brake ()
{ theCruiseControl.brake ();}
void HWInterfaceEvents::resume ()
{theCruiseControl.resume ();}
void HWInterfaceEvents::off () {theCruiseControl.off ();}
//---------------------------------------------------------------------
int main ()
{ HWInterfaceEvents theHWInterfaceEvents;
theHWInterfaceEvents.on(); //an Event
theHWInterfaceEvents.setDesiredSpeed(); //an Event
theHWInterfaceEvents.compare(); //an Event
theHWInterfaceEvents.brake(); //an Event
theHWInterfaceEvents.resume (); //an Event
theHWInterfaceEvents.off(); //an Event
return 0;
}
//-----------------------Sample Output----------------------------------
/*Driver pressed the on button
Driver pressed the set desired speed button
Enter the current speed: 55
Timer sent compare command
Enter the current speed: 66
Throttle adjustment - current speed is: 2
0 - too slow, 1 - ok, 2 - too fast
The throttle setting is 3.
0 - released, 1 - increasing, 2 - no_change,
3 -decreasing
Driver pressed the brake
The throttle is released
Driver pressed the resume button
Driver pressed the off button
The throttle is released
The Cruise Control is OFF
*/