Skip to content

Commit

Permalink
added vis of current draw from powerpacks
Browse files Browse the repository at this point in the history
  • Loading branch information
rtv committed Aug 28, 2009
1 parent df1fcf2 commit 5ab3af7
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 146 deletions.
4 changes: 1 addition & 3 deletions libstage/model.cc
Expand Up @@ -110,7 +110,6 @@ using namespace Stg;
// static members
uint32_t Model::count = 0;
std::map<stg_id_t,Model*> Model::modelsbyid;

std::map<std::string, creator_t> Model::name_map;

void Size::Load( Worldfile* wf, int section, const char* keyword )
Expand Down Expand Up @@ -957,7 +956,7 @@ PowerPack* Model::FindPowerPack() const
{
if( power_pack )
return power_pack;

if( parent )
return parent->FindPowerPack();

Expand Down Expand Up @@ -1120,4 +1119,3 @@ void Model::RasterVis::ClearPts()
{
pts.clear();
}

38 changes: 16 additions & 22 deletions libstage/model_actuator.cc
Expand Up @@ -56,8 +56,8 @@ actuator
if a linear actuator the axis that the actuator will move along
*/

static const double STG_ACTUATOR_WATTS_KGMS = 5.0; // cost per kg per meter per second
static const double STG_ACTUATOR_WATTS = 2.0; // base cost of position device
static const double WATTS_KGMS = 5.0; // cost per kg per meter per second
static const double WATTS_BASE = 2.0; // base cost of position device

ModelActuator::ModelActuator( World* world,
Model* parent,
Expand All @@ -68,12 +68,11 @@ ModelActuator::ModelActuator( World* world,
max_speed(1),
min_position(0),
max_position(1),
control_mode( STG_ACTUATOR_CONTROL_VELOCITY ),
actuator_type( STG_ACTUATOR_TYPE_LINEAR ),
control_mode( CONTROL_VELOCITY ),
actuator_type( TYPE_LINEAR ),
axis(0,0,0)
{
// no power consumed until we're subscribed
this->SetWatts( 0 );
this->SetWatts( WATTS_BASE );

// sensible position defaults
this->SetVelocity( Velocity(0,0,0,0) );
Expand All @@ -100,17 +99,17 @@ void ModelActuator::Load( void )
if( type_str )
{
if( strcmp( type_str, "linear" ) == 0 )
actuator_type = STG_ACTUATOR_TYPE_LINEAR;
actuator_type = TYPE_LINEAR;
else if( strcmp( type_str, "rotational" ) == 0 )
actuator_type = STG_ACTUATOR_TYPE_ROTATIONAL;
actuator_type = TYPE_ROTATIONAL;
else
{
PRINT_ERR1( "invalid actuator type specified: \"%s\" - should be one of: \"linear\" or \"rotational\". Using \"linear\" as default.", type_str );
}
}
}

if (actuator_type == STG_ACTUATOR_TYPE_LINEAR)
if (actuator_type == TYPE_LINEAR)
{
// if we are a linear actuator find the axis we operate in
if( wf->PropertyExists( wf_entity, "axis" ) )
Expand Down Expand Up @@ -169,11 +168,11 @@ void ModelActuator::Update( void )

switch (actuator_type)
{
case STG_ACTUATOR_TYPE_LINEAR:
case TYPE_LINEAR:
{
pos = PoseDiff.x * axis.x + PoseDiff.y * axis.y + PoseDiff.z * axis.z; // Dot product to find distance along axis
} break;
case STG_ACTUATOR_TYPE_ROTATIONAL:
case TYPE_ROTATIONAL:
{
pos = PoseDiff.a;
} break;
Expand All @@ -186,7 +185,7 @@ void ModelActuator::Update( void )
{
switch( control_mode )
{
case STG_ACTUATOR_CONTROL_VELOCITY :
case CONTROL_VELOCITY :
{
PRINT_DEBUG( "actuator velocity control mode" );
PRINT_DEBUG2( "model %s command(%.2f)",
Expand All @@ -198,7 +197,7 @@ void ModelActuator::Update( void )
velocity = goal;
} break;

case STG_ACTUATOR_CONTROL_POSITION:
case CONTROL_POSITION:
{
PRINT_DEBUG( "actuator position control mode" );

Expand Down Expand Up @@ -233,14 +232,14 @@ void ModelActuator::Update( void )
Velocity outvel;
switch (actuator_type)
{
case STG_ACTUATOR_TYPE_LINEAR:
case TYPE_LINEAR:
{
outvel.x = axis.x * velocity;
outvel.y = axis.y * velocity;
outvel.z = axis.z * velocity;
outvel.a = 0;
} break;
case STG_ACTUATOR_TYPE_ROTATIONAL:
case TYPE_ROTATIONAL:
{
outvel.x = outvel.y = outvel.z = 0;
outvel.a = velocity;
Expand All @@ -263,9 +262,6 @@ void ModelActuator::Startup( void )
Model::Startup();

PRINT_DEBUG( "position startup" );

this->SetWatts( STG_ACTUATOR_WATTS );

}

void ModelActuator::Shutdown( void )
Expand All @@ -277,20 +273,18 @@ void ModelActuator::Shutdown( void )

velocity.Zero();

this->SetWatts( 0 );

Model::Shutdown();
}

void ModelActuator::SetSpeed( double speed)
{
control_mode = STG_ACTUATOR_CONTROL_VELOCITY;
control_mode = CONTROL_VELOCITY;
goal = speed;
}


void ModelActuator::GoTo( double pos)
{
control_mode = STG_ACTUATOR_CONTROL_POSITION;
control_mode = CONTROL_POSITION;
goal = pos;
}
2 changes: 1 addition & 1 deletion libstage/model_getset.cc
Expand Up @@ -116,7 +116,7 @@ void Model::SetGuiOutline( int val )
CallCallbacks( &gui.outline );
}

void Model::SetWatts( stg_watts_t val )
void Model::SetWatts( stg_watts_t val )
{
watts = val;
CallCallbacks( &watts );
Expand Down
11 changes: 3 additions & 8 deletions libstage/model_laser.cc
Expand Up @@ -96,6 +96,9 @@ ModelLaser::ModelLaser( World* world,
// set up our data buffers and raytracing
SampleConfig();

// start consuming power
watts = DEFAULT_WATTS;

AddVisualizer( &vis, true );
}

Expand All @@ -111,9 +114,6 @@ void ModelLaser::Load( void )
fov = wf->ReadAngle( wf_entity, "fov", fov );
resolution = wf->ReadInt( wf_entity, "resolution", resolution );

//showLaserData.Load( wf, wf_entity );
//showLaserStrikes.Load( wf, wf_entity );

if( resolution < 1 )
{
PRINT_WARN( "laser resolution set < 1. Forcing to 1" );
Expand Down Expand Up @@ -228,17 +228,12 @@ void ModelLaser::Update( void )
void ModelLaser::Startup( void )
{
Model::Startup();

PRINT_DEBUG( "laser startup" );

// start consuming power
SetWatts( DEFAULT_WATTS );
}

void ModelLaser::Shutdown( void )
{
PRINT_DEBUG( "laser shutdown" );
SetWatts( 0 ); // stop consuming power
Model::Shutdown();
}

Expand Down
32 changes: 10 additions & 22 deletions libstage/model_load.cc
Expand Up @@ -47,40 +47,28 @@ void Model::Load()
power_pack->GetCapacity() ) );
}

// use my own pack or an ancestor's for the other energy properties
PowerPack* pp = FindPowerPack();

watts = wf->ReadFloat( wf_entity, "watts", watts );
if( (watts > 0) && !pp )
PRINT_WARN1( "Model %s: Setting \"watts\" has no effect unless \"joules\" is specified for this model or a parent", token );

watts_give = wf->ReadFloat( wf_entity, "give_watts", watts_give );
if( (watts_give > 0.0) && !pp)
PRINT_WARN1( "Model %s: Setting \"watts_give\" has no effect unless \"joules\" is specified for this model or a parent", token );

watts = wf->ReadFloat( wf_entity, "watts", watts );
watts_give = wf->ReadFloat( wf_entity, "give_watts", watts_give );
watts_take = wf->ReadFloat( wf_entity, "take_watts", watts_take );
if( (watts_take > 0.0) & !pp )
PRINT_WARN1( "Model %s: Setting \"watts_take\" has no effect unless \"joules\" is specified for this model or a parent", token );


if( wf->PropertyExists( wf_entity, "debug" ) )
{
PRINT_WARN2( "debug property specified for model %d %s\n",
wf_entity, this->token );
wf_entity, this->token );
this->debug = wf->ReadInt( wf_entity, "debug", this->debug );
}

if( wf->PropertyExists( wf_entity, "name" ) )
{
char *name = (char*)wf->ReadString(wf_entity, "name", NULL );
if( name )
{
//printf( "adding name %s to %s\n", name, this->token );
this->token = strdup( name );
world->AddModel( this ); // add this name to the world's table
}
{
//printf( "adding name %s to %s\n", name, this->token );
this->token = strdup( name );
world->AddModel( this ); // add this name to the world's table
}
else
PRINT_ERR1( "Name blank for model %s. Check your worldfile\n", this->token );
PRINT_ERR1( "Name blank for model %s. Check your worldfile\n", this->token );
}

//PRINT_WARN1( "%s::Load", token );
Expand Down

0 comments on commit 5ab3af7

Please sign in to comment.