Tutorial: Exclusive Component Control

The JAUS reference architecture defines a method for a component to take exclusive control of another component. This mechanism resolves any ambiguity that might occur if a component were to recieve a commands from multiple sources. With exclusive control, one component requests that only commands from itself will be executed by the component under control. An example of this is when an Operator Control Unit (OCU) requests exclusive control of a vehicle's primitive driver. This prevents wrench commands from other OCUs from being accepted by that primitive driver. This resolves any ambiguity that might occur and ensures safe operation, because the vehicle only performs manuevers commanded to it by a single OCU.

To obtain control of another component, the commanding component must first send a requestComponentControlMessage to the desired component. When that component recieves the message, the OpenJAUS default message processor will automatically accept control if the component is not already under control by another commander (this assumes that a callback function for the requestComponentControlMessage is not registered). After it accepts control it sends the confirmComponentControlMessage to the requesting source. The code below demonstrates how the commanding component would send the requestComponentControlMessage. Notice that the authorityCode field in the request message is set to the authority value of the commanding component. Exclusive component control is automatically given to the component witht the highest authority. This allows a component of higher authority to take control even if the desired component is already under control by one of lower authority.

 // Create the request control message structure
requestControl = requestComponentControlMessageCreate();
 
// Copy the address of the desired component into the destination
jausAddressCopy(requestControl->destination, pdAddress);
 
// Set the authority to the component's authority
requestControl->authorityCode = ojCmptGetAuthority(myCmpt);
 
// Convert to a JausMessage type (this serializes the data to send)
message = requestComponentControlMessageToJausMessage(requestControl);
 
// Send the message via the node manager
ojCmptSendMessage(myCmpt, message);
 
// Free the allocated JausMessage memory
jausMessageDestroy(message);
 
// Free the allocated request control message memory
requestComponentControlMessageDestroy(requestControl);
 

In order to determine if the control request was accepted, the commanding component usually implements a callback function for the confirm control message. An example of what this callback function might look like is given below:

// Callback function for the confirm control message
void confirmControlCallback(OjCmpt myCmpt, JausMessage message)
{
 // Declare the confirm control message variable
 ConfirmComponentControlMessage confirmComponentControl;
 
 // Create the message 
 confirmComponentControl = confirmComponentControlMessageFromJausMessage(message);
 
 // Test to confirm desired message source
 if(jausAddressEqual(confirmComponentControl->source, pdAddress))
 {
 // ... Code to confirm control of PD ...
 // User code to verify the control has been confirmed
 }
 
 // Free allocated memory
 confirmComponentControlMessageDestroy(confirmComponentControl);
}

 

0 Comments

Add Comment

Copyright © 2012 OpenJAUS. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.