VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Temperature Monitor Actuator

The DtTemperatureMonitorActuator is a new class that implements an actuator that updates the internal temperature of an entity in the state component. Additionally it will periodically print out the current temperature to the object console.


Header file:

/*******************************************************************************
** Copyright (c) 2021 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//
//class DtTemperatureMonitorActuator
//
//This is a component which simply keeps track of the entity's internal temperature.
//Factors that affect temperature will be external temperature and if entity is moving.
//
#pragma once
//String which uniquely identifies this controller
const char DtTemperatureMonitorActuatorType[] = "temperature-monitor-actuator";
{
public:
//constructor
DtSimulationServices * simManager, DtComponentDescriptor* desc = NULL,
DtReaderWriterRegistry * parentRegistry = 0);
//destructor
//copy constructor
//assignment operator
//Returns the string type for this component.
virtual const char* type() const;
//Overridden from the base class to call createPSR().
virtual bool init();
//Update control values
//For this actuator, we apply some simple constraints to internal temperature and we print out the value every 10 seconds of
//simulation time.
virtual void tick();
const double getTemperature() const;
//This is called by the factory
static DtSimComponent* creator(const DtString & name, DtLocalObject* owner,
DtReaderWriterRegistry * parentRegistry);
protected:
};
#pragma once

Implementation:

/*******************************************************************************
** Copyright (c) 2021 MAK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
//
//class DtTemperatureMonitorActuator
//
using namespace makVrf;
//constructor
DtReaderWriterRegistry * parentRegistry) :
DtActuatorComponent(name, owner, simManager, desc,
parentRegistry)
{
myNextPrintTime = 0.0;
}
//destructor
//Since this class created the process state repository, it must also
//delete it when it is through.
{
}
{
}
//First call down to the base class init.
//Call createPSR() to create a process state repository.
{
{
return false;
}
return true;
}
//calculate new control values
{
DtPROFILE("DtManualRotaryWingEncumberedFlightActuator::tick");
if (dT() > 0)
{
//access parameter in custom descriptor
//check to make sure component is using custom descriptor, otherwise use hardcoded default
int interval = 10;
//Print to the object console every 10 seconds to provide feedback that
//the controller is working.
//Member variables of this component will not be saved in a checkpoint.
//Use simulation services to get current time( Yes we can just call parent classes computeCurrentTime
//But good to see use of simulationServices
double currentTime = simulationServices()->simTime();
if ( myNextPrintTime <= currentTime)
{
double temperature = getTemperature();
objectConsoleInfo() << "addStateComponent Example - " <<
"Current Internal Temperature is : " << temperature << std::endl;
myNextPrintTime += interval;
}
}
}
{
//Get current internal temperature from current frame
double currentTemp = getTemperature();
//Make any modifications as needed
//Access weather to get external temperature
environmentalStateManager();
double externalTemp = env->airTemperature(entity()->localPosition());
//Set internal temperature based on external temperature
if ( externalTemp < 0.0 )
{
//Brrrr its cold, body temp drops
currentTemp = 36.5;
}
else if (externalTemp > 40.0)
{
//Phew it's hot, body temp rises
currentTemp = 38.0;
}
//Set in next frame
entity()->getNextFrameStateComponent<DtInternalTemperatureStateComponent>()->setInternalCoreTemperature(currentTemp);
}
{
//Access the internal temperature component to get current internal temperature
return entity()->getStateComponent<DtInternalTemperatureStateComponent>()->internalCoreTemperature();
}
DtReaderWriterRegistry* parentRegistry)
{
return
new DtTemperatureMonitorActuator(name, owner, simManager, desc, parentRegistry);
}

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)