Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
75a053f5
Commit
75a053f5
authored
Nov 09, 2020
by
Julian Zobel
Browse files
Example scenario for ML
parent
125d6756
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/api/topology/component/ControllableLocationActuator.java
View file @
75a053f5
...
@@ -23,10 +23,11 @@ package de.tud.kom.p2psim.api.topology.component;
...
@@ -23,10 +23,11 @@ package de.tud.kom.p2psim.api.topology.component;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
de.tud.kom.p2psim.impl.topology.component.BaseTopologyComponent
;
import
de.tud.kom.p2psim.impl.topology.component.BaseTopologyComponent
;
import
de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent.UAVstate
;
import
de.tud.kom.p2psim.impl.topology.placement.UAVBasePlacement
;
import
de.tud.kom.p2psim.impl.topology.placement.UAVBasePlacement
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.Actuator
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.Actuator
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnect
ed
Callback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnect
ion
Callback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback
;
...
@@ -46,6 +47,8 @@ public interface ControllableLocationActuator extends Actuator {
...
@@ -46,6 +47,8 @@ public interface ControllableLocationActuator extends Actuator {
public
boolean
activate
();
public
boolean
activate
();
public
boolean
deactivate
();
public
boolean
deactivate
();
public
UAVstate
getState
();
public
PositionVector
getCurrentLocation
();
public
PositionVector
getCurrentLocation
();
...
@@ -70,16 +73,14 @@ public interface ControllableLocationActuator extends Actuator {
...
@@ -70,16 +73,14 @@ public interface ControllableLocationActuator extends Actuator {
public
void
setTargetLocationRoute
(
LinkedList
<
PositionVector
>
route
,
ReachedLocationCallback
cb
);
public
void
setTargetLocationRoute
(
LinkedList
<
PositionVector
>
route
,
ReachedLocationCallback
cb
);
public
void
removeAllTargetLocations
();
public
void
removeAllTargetLocations
();
public
void
batteryReplacement
(
BatteryReplacementCallback
cb
);
public
void
returnToBase
(
double
velocity
,
ReachedLocationCallback
cb
);
public
void
returnToBase
(
ReachedLocationCallback
cb
);
public
void
connectTo
Base
(
BaseConnect
ed
Callback
cb
);
public
boolean
landAt
Base
(
BaseConnect
ion
Callback
cb
);
public
void
disconnectFromBase
(
BaseDisconnected
Callback
cb
);
public
boolean
startFromBase
(
ReachedLocation
Callback
cb
);
public
void
setMovementSpeed
(
double
speed
);
public
void
setMovementSpeed
(
double
velocity
);
public
double
getMinMovementSpeed
();
public
double
getMinMovementSpeed
();
...
...
src/de/tud/kom/p2psim/impl/topology/component/AbstractTopologyComponent.java
View file @
75a053f5
...
@@ -58,7 +58,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.N
...
@@ -58,7 +58,7 @@ import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.N
* Abstract implementation of the topology component interface, to support basic
* Abstract implementation of the topology component interface, to support basic
* functionalities to all topology components.
* functionalities to all topology components.
*
*
* @author Julian Zobel
* @author Julian Zobel
, others before
* @version 1.0, 6 Sep 2018
* @version 1.0, 6 Sep 2018
*/
*/
public
abstract
class
AbstractTopologyComponent
implements
TopologyComponent
{
public
abstract
class
AbstractTopologyComponent
implements
TopologyComponent
{
...
...
src/de/tud/kom/p2psim/impl/topology/component/UAVTopologyComponent.java
View file @
75a053f5
...
@@ -43,21 +43,20 @@ import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableExcep
...
@@ -43,21 +43,20 @@ import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableExcep
import
de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnectedCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnectionCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.communication.UAVToBaseInterface
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.communication.UAVToBaseInterface
;
/**
/**
* Topology component extension pr
i
viding a broader topology functionality for UAVs
* Topology component extension pr
o
viding a broader topology functionality for UAVs
*
*
* @author Julian Zobel
* @author Julian Zobel
* @version 1.0, 06.09.2018
* @version 1.0, 06.09.2018
*/
*/
public
class
UAVTopologyComponent
extends
AbstractTopologyComponent
implements
SimUAVLocationActuator
{
public
class
UAVTopologyComponent
extends
AbstractTopologyComponent
implements
SimUAVLocationActuator
{
public
enum
UAVstate
{
OFFLINE
,
BASE_CONNECTION
,
ACTION
,
RETURN
,
CRASHED
}
public
enum
UAVstate
{
OFFLINE
,
BASE_CONNECTION
,
BASE_CONNECTION_READY
,
ACTION
,
RETURN
,
CRASHED
}
private
UAVMovementModel
movement
;
private
UAVMovementModel
movement
;
...
@@ -83,7 +82,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
...
@@ -83,7 +82,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
public
UAVTopologyComponent
(
SimHost
host
,
Topology
topology
,
public
UAVTopologyComponent
(
SimHost
host
,
Topology
topology
,
MovementModel
movementModel
,
PlacementModel
placementModel
,
boolean
registerAsInformationProviderInSiS
)
{
MovementModel
movementModel
,
PlacementModel
placementModel
,
boolean
registerAsInformationProviderInSiS
)
{
super
(
host
,
topology
,
movementModel
,
placementModel
,
registerAsInformationProviderInSiS
);
super
(
host
,
topology
,
movementModel
,
placementModel
,
registerAsInformationProviderInSiS
);
direction
=
new
PositionVector
(
0
,-
1
,
0
);
direction
=
new
PositionVector
(
0
,-
1
,
0
);
}
}
@Override
@Override
...
@@ -106,10 +105,11 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
...
@@ -106,10 +105,11 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
}
}
// retrieve base location
// retrieve base location
baseLocation
=
UAVBasePlacement
.
base
.
position
.
clone
();
baseLocation
=
UAVBasePlacement
.
base
.
position
.
clone
();
}
}
p
ublic
void
setState
(
UAVstate
newState
)
{
p
rivate
void
setState
(
UAVstate
newState
)
{
this
.
state
=
newState
;
this
.
state
=
newState
;
// TODO analyzer
// TODO analyzer
...
@@ -228,12 +228,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
...
@@ -228,12 +228,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@Override
@Override
public
void
setTargetLocation
(
PositionVector
targetLocation
,
public
void
setTargetLocation
(
PositionVector
targetLocation
,
ReachedLocationCallback
cb
)
{
ReachedLocationCallback
cb
)
{
if
(!
isActive
())
return
;
movement
.
setTargetLocation
(
new
PositionVector
(
targetLocation
),
cb
);
movement
.
setTargetLocation
(
new
PositionVector
(
targetLocation
),
cb
);
}
}
@Override
@Override
public
void
addTargetLocation
(
PositionVector
targetLocation
,
public
void
addTargetLocation
(
PositionVector
targetLocation
,
ReachedLocationCallback
cb
)
{
ReachedLocationCallback
cb
)
{
if
(!
isActive
())
return
;
movement
.
addTargetLocation
(
new
PositionVector
(
targetLocation
),
cb
);
movement
.
addTargetLocation
(
new
PositionVector
(
targetLocation
),
cb
);
}
}
...
@@ -271,59 +275,127 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
...
@@ -271,59 +275,127 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
return
state
;
return
state
;
}
}
private
PositionVector
getOverBaseLocation
()
{
PositionVector
locationOverBase
=
baseLocation
.
clone
();
locationOverBase
.
setAltitude
(
10
);
return
locationOverBase
;
}
@Override
public
void
returnToBase
(
double
velocity
,
ReachedLocationCallback
cb
)
{
movement
.
setTargetVelocity
(
velocity
);
movement
.
setTargetLocation
(
getOverBaseLocation
(),
cb
);
}
@Override
@Override
public
void
returnToBase
(
ReachedLocationCallback
cb
)
{
public
boolean
landAtBase
(
BaseConnectionCallback
cb
)
{
this
.
setState
(
UAVstate
.
RETURN
);
if
(
overBaseLocation
())
{
this
.
setState
(
UAVstate
.
RETURN
);
ReachedLocationCallback
landedCallback
=
new
ReachedLocationCallback
()
{
@Override
public
void
reachedLocation
()
{
deactivate
();
connectToBase
(
cb
);
}
};
movement
.
setTargetVelocity
(
5
);
movement
.
setTargetLocation
(
baseLocation
,
landedCallback
);
return
true
;
}
else
return
false
;
}
ReachedLocationCallback
returnCallback
=
new
ReachedLocationCallback
()
{
@Override
public
boolean
startFromBase
(
ReachedLocationCallback
cb
)
{
if
(
this
.
getCurrentLocation
().
equals
(
this
.
getBaseLocation
())
&&
state
==
UAVstate
.
BASE_CONNECTION_READY
&&
activate
())
{
disconnectFromBase
();
movement
.
setTargetVelocity
(
movement
.
getVerticalAscentMaxVelocity
());
movement
.
setTargetLocation
(
getOverBaseLocation
(),
cb
);
@Override
return
true
;
public
void
reachedLocation
()
{
}
deactivate
();
else
return
false
;
cb
.
reachedLocation
();
}
};
movement
.
setTargetVelocity
(
movement
.
getHorizontalMaxVelocity
());
movement
.
setTargetLocation
(
baseLocation
,
returnCallback
);
}
}
private
boolean
overBaseLocation
()
{
if
(
this
.
getCurrentLocation
().
getX
()
==
this
.
getBaseLocation
().
getX
()
&&
this
.
getCurrentLocation
().
getY
()
==
this
.
getBaseLocation
().
getY
())
{
return
true
;
}
else
return
false
;
}
p
ublic
void
batteryReplacement
(
BatteryReplacementCallback
cb
)
{
p
rivate
void
batteryReplacement
(
BatteryReplacementCallback
cb
)
{
if
(
state
!=
UAVstate
.
BASE_CONNECTION
)
{
if
(
state
!=
UAVstate
.
BASE_CONNECTION
)
{
throw
new
UnsupportedOperationException
(
"Cannot recharge if not connected to base!"
);
throw
new
UnsupportedOperationException
(
"Cannot recharge if not connected to base!"
);
}
}
this
.
setState
(
UAVstate
.
OFFLINE
);
BaseTopologyComponent
base
=
UAVBasePlacement
.
base
;
BaseTopologyComponent
base
=
UAVBasePlacement
.
base
;
base
.
getCharger
().
charge
(
this
,
cb
);
base
.
getCharger
().
charge
(
this
,
cb
);
}
}
public
void
setControllerInterface
(
UAVToBaseInterface
controllerInterface
)
{
public
void
setControllerInterface
(
UAVToBaseInterface
controllerInterface
)
{
this
.
controllerInterface
=
controllerInterface
;
this
.
controllerInterface
=
controllerInterface
;
this
.
controllerInterface
.
setDeploymentArea
(
topology
.
getWorldDimensions
());
connectToBase
(
null
);
}
}
@Override
/**
public
void
connectToBase
(
BaseConnectedCallback
cb
)
{
* Connect to the base and initiate a recharge
*
* @param cb
*/
private
void
connectToBase
(
BaseConnectionCallback
cb
)
{
BaseTopologyComponent
base
=
UAVBasePlacement
.
base
;
BaseTopologyComponent
base
=
UAVBasePlacement
.
base
;
base
.
connectUAVToBase
(
controllerInterface
);
base
.
connectUAVToBase
(
controllerInterface
);
if
(
cb
!=
null
)
if
(
cb
!=
null
)
{
cb
.
successfulConnection
();
cb
.
successfulConnection
();
}
this
.
setState
(
UAVstate
.
BASE_CONNECTION
);
this
.
setState
(
UAVstate
.
BASE_CONNECTION
);
shutdownCommunication
();
shutdownCommunication
();
// recharge
if
(
battery
.
getCurrentPercentage
()
<=
75
)
{
batteryReplacement
(
new
BatteryReplacementCallback
()
{
@Override
public
void
rechargeComplete
()
{
setState
(
UAVstate
.
BASE_CONNECTION_READY
);
if
(
cb
!=
null
)
{
cb
.
readyForTakeoff
();
}
}
});
}
else
{
this
.
setState
(
UAVstate
.
BASE_CONNECTION_READY
);
if
(
cb
!=
null
)
{
cb
.
readyForTakeoff
();
}
}
}
}
@Override
p
ublic
void
disconnectFromBase
(
BaseDisconnectedCallback
cb
)
{
p
rivate
void
disconnectFromBase
()
{
startCommunication
();
startCommunication
();
BaseTopologyComponent
base
=
UAVBasePlacement
.
base
;
BaseTopologyComponent
base
=
UAVBasePlacement
.
base
;
base
.
disconnectUAVFromBase
(
controllerInterface
);
base
.
disconnectUAVFromBase
(
controllerInterface
);
if
(
cb
!=
null
)
cb
.
successfulDisconnection
();
}
}
private
void
shutdownCommunication
()
{
private
void
shutdownCommunication
()
{
...
@@ -382,5 +454,21 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
...
@@ -382,5 +454,21 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
}
}
}
}
@Override
public
UAVstate
getState
()
{
return
state
;
}
@Override
public
void
updateCurrentLocation
(
Location
location
)
{
super
.
updateCurrentLocation
(
location
);
if
(!
actuator
.
isOn
()
&&
(
state
==
UAVstate
.
ACTION
||
state
==
UAVstate
.
RETURN
))
{
this
.
deactivate
();
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment