I’m working on modeling a conveyor system using low cost hardware (lego bricks, IR Sensor, DC Motor and Raspberry Pi). I have already built the conveyor belt and now I need to model it using Papyrus-RT.
Papyrus-RT model must have Restrictions:
- The behavioural logic, in the form of C++ code snippets along Transition Effects and State Entry/Exit, should be kept short and simple. Restricted to use only the port related instructions and any direct attribute changes, but avoid any other functional code.
- Replace code blocks with the design elements wherever possible. For example, variable declarations to be handled with UML-RT attributes, if-else logic to be replaced with pseudo states and transitions with effect, and so on.
- Messages within user-defined Protocols are to be limited to carry at max one payload of integer type only. Comments about the domain set of this parameter should also be updated and must always include a non-functional ‘0’.
- Do not use payload directly for any computation, but always use a designated local attribute to read the incoming payload and then use this updated value.
- A single attribute should not be updated more than ones along one complete transition between two stable states.
- In case of port-replication, where the outgoing messages could be sent/broadcasted in any random order, separate controller threads to be used for each receiving capsule.
- For every integer type attribute, a pair of read-only integer attributes should be included to mark the domain max and min values.
Optional Restrictions:
8. Try to avoid functions specific to C++ libraries. This is because, the behaviour of any special C++ library used in code, needs to be manually abstracted into the nuXmv model for translation.
9. Use only port related functionalities or direct assignments in the state entry/exit actions.
This is what I have done so far:
- DCMotorCapsule: status of the conveyor (moving, stopped).
- SensorCapsule: to track whether an item has been detected.
- ControllerCapsule: manages the overall system status and stores the current state of each component for decision-making purposes.
- Raspberry Pi Top Capsule: contains all capsules.
DCMotor Capsule
Variables:
- conveyorStatus: Integer, tracks the status (0 for stopped, 1 for running).
Protocols: - ConveyorControl: Single integer payload for commands like start (1), stop (0).
Sensor Capsule:
Variables: - sensorStatus: Integer attribute to track the sensor status. 0 for no item detected, 1 for item detected.
Protocols: - DetectionProtocol: Single integer payload to communicate detection status (1 for item detected, 0 for not detected).
Controller Capsule
Variables: - systemStatus: An integer to represent the overall status of the system.
- errorStatus: An integer for error codes (0 for no error, other values for specific errors).
Protocols:
- ControlProtocol: Uses an integer payload for control commands.
- StatusProtocol: Uses an integer payload for status updates.
Ports:
Step-by-step:**
- The IR sensor capsule detects an item and changes its sensorStatus to ‘1’.
- The IR sensor sends a message via its DetectionOutput port using the DetectionProtocol.
- Controller Receiving the Detection Hint:
- The Controller capsule has a StatusInput port that is connected to the DetectionOutput port of the Sensor capsule.
- When an item is detected, the Sensor sends an ItemDetected message with a payload of ‘1’ to the Controller.
- The Controller’s StatusInput port has a trigger set up to listen for this ItemDetected message.
- Controller to Conveyor Belt Communication:
- Upon receiving the ItemDetected message, the Controller processes it and then sends a command to start the conveyor belt through the ControlOutput port of the Controller, which is connected to the ControlInput port of the DCMotorCapsule using the DCMotorCapsule protocol.
- ‘1’ is sent to the DCMotorCapsule capsule, instructing it to start.
Code:
IR Sensor Capsule
class SensorCapsule {
public:
// UML-RT Attributes (Variables)
int sensorStatus; // The sensor status: 0 for no item, 1 for item detected
// Constructor
SensorCapsule() : sensorStatus(0) {
// Initialization of sensor capsule, sensor starts with no item detected
}
// This function is a placeholder for an actual sensor read operation.
void detectItem() {
int detected = readSensor(); // Reading sensor
if (sensorStatus != detected) {
sensorStatus = detected; // Updating the sensor status
sendDetectionStatus(); // Send the detection status if it has changed
}
}
private:
// Read the sensor hardware to detect an item
int readSensor() {
// sensor reading code
// Return 1 if item is detected, 0 otherwise
}
// Send the detection status to the controller capsule
void sendDetectionStatus() {
// send msg via DetectionOutput port using the DetectionProtocol
}
};
Code:
Controller Capsule
class ControllerCapsule {
public:
ControllerCapsule();
void handleDetectionMessage(int message);
void commandConveyorBelt(int command);
};
void ControllerCapsule::handleDetectionMessage(int message) {
// Simple if-statement to determine the command for the conveyor
int command = (message == 1) ? 1 : 0; // 1 to start, 0 to stop
commandConveyorBelt(command);
}
void ControllerCapsule::commandConveyorBelt(int command) {
// send the command to the DCMotor Capsule
}
Code:
DCMotor Capsule
class DCMotor Capsule {
public:
ConveyorBeltCapsule();
void handleControlCommand(int command); // To handle incoming control commands
};
ConveyorBeltCapsule::ConveyorBeltCapsule() {}
void ConveyorBeltCapsule::handleControlCommand(int command) {
// 1 for start, 0 for stop
if (command == 1) {
// Code to start the conveyor belt
// maybe: setConveyorStatus(1); where setConveyorStatus is a function to start the belt
} else if (command == 0) {
// Code to stop the conveyor belt
}
}
// Define the function that will interface with the hardware or the simulation API
void setConveyorStatus(int status) {
// hardware control logic
}
Can someone help fill in the rest of the code and help with the model in papyrus? I can’t find that much information online considering this is not so used and I’m not that good in C++.
Thanks!