Repository navigation
Expand file tree
/
Copy pathSystemModels.cpp
More file actions
156 lines (127 loc) · 4.52 KB
/
Copy pathSystemModels.cpp
File metadata and controls
156 lines (127 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "camera_array/SystemModels.h"
#include <boost/foreach.hpp>
#define POSE_DIM (PoseSE3::TangentDimension)
namespace argus
{
InstantCameraTransitionFunction::InstantCameraTransitionFunction( unsigned int maxCams )
: maxActiveCams( maxCams ) {}
CameraArrayState InstantCameraTransitionFunction::Transition( const CameraArrayState& state,
const CameraArrayAction& action )
{
CameraArrayState next( state );
switch( action.type )
{
case CameraArrayAction::DO_NOTHING:
// Do as it says!
break;
case CameraArrayAction::ACTIVATE_CAMERA:
// If the target is not active and we have fewer than max, it activates
if( state.IsInactive( action.toActivate ) &&
state.activeCameras.size() < maxActiveCams )
{
next.Activate( action.toActivate );
}
// Else nothing happens
break;
case CameraArrayAction::DEACTIVATE_CAMERA:
// If the target is active, it deactivates
if( state.IsActive( action.toDeactivate ) )
{
next.Deactivate( action.toDeactivate );
}
// Else nothing happens
break;
case CameraArrayAction::SWITCH_CAMERAS:
// If the target cameras are in their valid states, switch them
if( state.IsActive( action.toDeactivate ) &&
state.IsInactive( action.toActivate ) )
{
next.Activate( action.toActivate );
next.Deactivate( action.toDeactivate );
}
// Else nothing happens
break;
}
return next;
}
SwitchingCameraActionGenerator::SwitchingCameraActionGenerator( unsigned int maxCams )
: maxActiveCams( maxCams ) {}
SwitchingCameraActionGenerator::ActionList
SwitchingCameraActionGenerator::GetActions( const CameraArrayState& state )
{
ActionList actions;
CameraArrayAction action;
// First activate all cameras if allowed
if( state.activeCameras.size() < maxActiveCams )
{
action.type = CameraArrayAction::ACTIVATE_CAMERA;
BOOST_FOREACH( const std::string& name, state.inactiveCameras )
{
action.toActivate = name;
actions.push_back( action );
}
}
// Otherwise allow null action
else
{
action.type = CameraArrayAction::DO_NOTHING;
actions.push_back( action );
}
// Now switch for all combinations
action.type = CameraArrayAction::SWITCH_CAMERAS;
BOOST_FOREACH( const std::string& active, state.activeCameras )
{
action.toDeactivate = active;
BOOST_FOREACH( const std::string& inactive, state.inactiveCameras )
{
action.toActivate = inactive;
actions.push_back( action );
}
}
return actions;
}
FixedStepTargetTransitionFunction::FixedStepTargetTransitionFunction( double timestep )
: dt( timestep )
{}
TargetState
FixedStepTargetTransitionFunction::Transition( const TargetState& state,
const AccelerationAction& action )
{
TargetState next( state );
PoseSE3::TangentDim velocity = state.derivatives.head<POSE_DIM>();
PoseSE3 displacement = PoseSE3::Exp( dt * velocity +
0.5 * dt * dt * action.acceleration );
next.pose = state.pose * displacement;
next.derivatives = velocity + dt * action.acceleration;
return next;
}
FixedTargetActionGenerator::FixedTargetActionGenerator( const AccelerationAction& o )
: output( o ) {}
std::vector<AccelerationAction> FixedTargetActionGenerator::GetActions( const TargetState& state )
{
std::vector<AccelerationAction> outputs;
outputs.push_back( output );
return outputs;
}
MixedTransitionFunction::MixedTransitionFunction( const TargetTransitionFunction::Ptr& tfunc,
const ArrayTransitionFunction::Ptr& afunc )
: targetTransition( tfunc ), arrayTransition( afunc ) {}
RobotTargetState MixedTransitionFunction::Transition( const RobotTargetState& state,
const CameraArrayAction& action )
{
RobotTargetState next( state );
next.array = arrayTransition->Transition( state.array, action );
AccelerationAction defaultAcceleration;
next.robot = targetTransition->Transition( state.robot, defaultAcceleration );
// BOOST_FOREACH( const RobotTargetAction::ActionMap::value_type& item, action.targetActions )
BOOST_FOREACH( const RobotTargetState::TargetMap::value_type& item, state.targets )
{
const std::string& targetName = item.first;
// const AccelerationAction& targetAction = item.second;
AccelerationAction targetAction;
next.targets[ targetName ] = targetTransition->Transition( state.targets.at( targetName ),
targetAction );
}
return next;
}
}