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
d3e62a60
Commit
d3e62a60
authored
Sep 24, 2018
by
Julian Zobel
Browse files
Basiuc Strategy with Callbacks
parent
01a3ca94
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/api/topology/component/ControllableLocationActuator.java
View file @
d3e62a60
...
...
@@ -22,7 +22,12 @@ package de.tud.kom.p2psim.api.topology.component;
import
java.util.LinkedList
;
import
de.tud.kom.p2psim.impl.topology.component.BaseTopologyComponent
;
import
de.tud.kom.p2psim.impl.topology.placement.UAVBasePlacement
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.Actuator
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnectedCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback
;
/**
...
...
@@ -33,7 +38,7 @@ import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocation
* @author Julian Zobel
*
*/
public
interface
ControllableLocationActuator
{
public
interface
ControllableLocationActuator
extends
Actuator
{
public
boolean
isActive
();
...
...
@@ -56,5 +61,8 @@ public interface ControllableLocationActuator {
public
void
removeAllTargetLocations
();
public
void
returnToBase
(
ReachedLocationCallback
cb
);
public
void
connectToBase
(
BaseConnectedCallback
cb
);
public
void
disconnectFromBase
(
BaseDisconnectedCallback
cb
);
}
src/de/tud/kom/p2psim/impl/energy/components/ActuatorEnergyComponent.java
View file @
d3e62a60
...
...
@@ -77,8 +77,7 @@ public class ActuatorEnergyComponent implements EnergyComponent {
@Override
public
double
calculateEnergyConsumation
(
EnergyState
state
,
long
timeInState
)
{
if
(
state
.
equals
(
FLY
))
{
double
consumationDelta
=
MAX
.
getEnergyConsumption
()
-
FLY
.
getEnergyConsumption
();
double
consumationDelta
=
MAX
.
getEnergyConsumption
()
-
FLY
.
getEnergyConsumption
();
double
consumation
=
FLY
.
getEnergyConsumption
()
+
consumationDelta
*
actuatorLoad
;
return
consumation
*
(
(
double
)
timeInState
/
(
double
)
Time
.
SECOND
);
}
...
...
src/de/tud/kom/p2psim/impl/topology/component/BaseTopologyComponent.java
View file @
d3e62a60
...
...
@@ -30,13 +30,15 @@ import de.tud.kom.p2psim.impl.energy.UAVReplacementCharger;
import
de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.BaseToUAVInterface
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.UAVToBaseInterface
;
public
class
BaseTopologyComponent
extends
AbstractTopologyComponent
{
private
OverlayComponent
baseOverlayComponent
;
private
UAVReplacementCharger
charger
;
private
BaseToUAVInterface
controllerInterface
;
public
BaseTopologyComponent
(
SimHost
host
,
Topology
topology
,
MovementModel
movementModel
,
PlacementModel
placementModel
,
...
...
@@ -104,4 +106,15 @@ public class BaseTopologyComponent extends AbstractTopologyComponent {
return
charger
;
}
public
void
setControllerInterface
(
BaseToUAVInterface
controllerInterface
)
{
this
.
controllerInterface
=
controllerInterface
;
}
public
void
connectUAVToBase
(
UAVToBaseInterface
uav
)
{
this
.
controllerInterface
.
connectUAVtoBase
(
uav
);
}
public
void
disconnectUAVFromBase
(
UAVToBaseInterface
uav
)
{
this
.
controllerInterface
.
disconnectUAV
(
uav
);
}
}
src/de/tud/kom/p2psim/impl/topology/component/UAVTopologyComponent.java
View file @
d3e62a60
...
...
@@ -41,7 +41,9 @@ import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableExcep
import
de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.UAVToBaseInterface
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseConnectedCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BaseDisconnectedCallback
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback
;
/**
...
...
@@ -61,9 +63,11 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
private
ActuatorEnergyComponent
actuator
;
private
RechargeableBattery
battery
;
private
UAVstate
state
=
UAVstate
.
OFFLINE
;
private
UAVstate
state
;
private
PositionVector
baseLocation
;
private
UAVToBaseInterface
controllerInterface
;
/**
* Create a TopologyComponent for the current host.
*
...
...
@@ -94,7 +98,8 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
System
.
err
.
println
(
"No Battery Component was found!"
);
}
baseLocation
=
position
.
clone
();
// retrieve base location
baseLocation
=
UAVBasePlacement
.
base
.
position
.
clone
();
}
public
void
setState
(
UAVstate
newState
)
{
...
...
@@ -196,12 +201,6 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
return
actuator
;
}
public
void
updateCurrentLocation
(
Location
location
,
double
actuatorLoad
)
{
super
.
updateCurrentLocation
(
location
);
actuator
.
useActuator
(
actuatorLoad
);
}
@Override
public
Set
<
AttractionPoint
>
getAllAttractionPoints
()
{
throw
new
UnsupportedOperationException
();
...
...
@@ -261,7 +260,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@Override
public
void
reachedLocation
()
{
deactivate
();
deactivate
();
cb
.
reachedLocation
();
}
};
...
...
@@ -269,18 +268,36 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
movement
.
setTargetLocation
(
baseLocation
,
returnCallback
);
}
protected
void
connectToBaseAndRecharge
()
{
protected
void
batteryReplacement
()
{
BaseTopologyComponent
base
=
UAVBasePlacement
.
base
;
base
.
getCharger
().
charge
(
this
,
new
BatteryReplacementCallback
()
{
@Override
public
void
rechargeComplete
()
{
System
.
out
.
println
(
"Recharge completed!"
);
}
});
base
.
getCharger
().
charge
(
this
,
null
);
}
public
void
setControllerInterface
(
UAVToBaseInterface
controllerInterface
)
{
this
.
controllerInterface
=
controllerInterface
;
UAVBasePlacement
.
base
.
connectUAVToBase
(
this
.
controllerInterface
);
state
=
UAVstate
.
OFFLINE
;
}
@Override
public
void
connectToBase
(
BaseConnectedCallback
cb
)
{
BaseTopologyComponent
base
=
UAVBasePlacement
.
base
;
base
.
connectUAVToBase
(
controllerInterface
);
if
(
cb
!=
null
)
cb
.
successfulConnection
();
}
@Override
public
void
disconnectFromBase
(
BaseDisconnectedCallback
cb
)
{
BaseTopologyComponent
base
=
UAVBasePlacement
.
base
;
base
.
disconnectUAVFromBase
(
controllerInterface
);
if
(
cb
!=
null
)
cb
.
successfulDisconnection
();
}
}
src/de/tud/kom/p2psim/impl/topology/movement/aerial/SimpleMutlicopterMovement.java
View file @
d3e62a60
...
...
@@ -23,6 +23,9 @@ package de.tud.kom.p2psim.impl.topology.movement.aerial;
import
java.util.HashMap
;
import
java.util.LinkedList
;
import
java.util.Map
;
import
org.joda.time.tz.ZoneInfoProvider
;
import
de.tud.kom.p2psim.api.topology.movement.UAVMovementModel
;
import
de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent
;
import
de.tud.kom.p2psim.impl.topology.util.PositionVector
;
...
...
@@ -92,7 +95,8 @@ public class SimpleMutlicopterMovement implements UAVMovementModel {
if
(
distanceToTargetPosition
<
0.1
||
distanceToTargetPosition
<
currentSpeed
)
{
route
.
removeFirst
();
topologyComponent
.
updateCurrentLocation
(
targetPosition
,
0.5
);
// triggers energy consumption for last distance
topologyComponent
.
getActuatorEnergyComponent
().
useActuator
(
0.5
);
topologyComponent
.
updateCurrentLocation
(
targetPosition
);
// triggers energy consumption for last distance
currentSpeed
=
0
;
topologyComponent
.
getActuatorEnergyComponent
().
useActuator
(
0
);
// now hover
locationReached
(
targetPosition
);
...
...
@@ -111,7 +115,8 @@ public class SimpleMutlicopterMovement implements UAVMovementModel {
PositionVector
newPosition
=
new
PositionVector
(
currentPosition
);
newPosition
.
add
(
direction
);
topologyComponent
.
updateCurrentLocation
(
newPosition
,
1
);
topologyComponent
.
getActuatorEnergyComponent
().
useActuator
(
1
);
topologyComponent
.
updateCurrentLocation
(
newPosition
);
}
...
...
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/IAttractionGenerator.java
View file @
d3e62a60
...
...
@@ -25,15 +25,13 @@ import java.util.List;
import
de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint
;
/**
* This is the interface for the generator of the {@link AttractionPoint}s. It
* gets the set number of AttractionPoints back. This mean, it will be generate
* them and set the Position of them.
* Interface for {@link AttractionPoint} generators. Will generate a given amount of attraction points.
*
* @author Christoph Muenker
* @version 1.
0
, 0
2.07.
201
3
* @author Christoph Muenker
, Julian Zobel
* @version 1.
1
, 0
9
201
8
*/
public
interface
IAttractionGenerator
{
public
List
<
AttractionPoint
>
getAttractionPoints
();
}
src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/RandomAttractionGenerator.java
View file @
d3e62a60
...
...
@@ -20,9 +20,9 @@
package
de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Random
;
import
java.util.Vector
;
import
de.tud.kom.p2psim.api.scenario.ConfigurationException
;
import
de.tud.kom.p2psim.api.topology.Topology
;
...
...
@@ -35,11 +35,11 @@ import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* Implementation of the interface {@link AttractionGenerator}.
*
*
It g
enerates the given number of {@link AttractionPoint}s and sets the
*
P
osition randomly.
*
G
enerates the given number of {@link AttractionPoint}s and sets the
*
p
osition randomly
within the world dimensions
.
*
* @author Christoph Muenker
* @version 1.
0
, 0
2.07.
201
3
* @author Christoph Muenker
, Julian Zobel
* @version 1.
1
, 0
9
201
8
*/
public
class
RandomAttractionGenerator
implements
IAttractionGenerator
{
...
...
@@ -50,6 +50,8 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
private
int
numberOfAttractionPoints
;
private
boolean
numberOfAPsSet
=
false
;
private
List
<
AttractionPoint
>
attractionPoints
;
@XMLConfigurableConstructor
({
"numberOfAttractionPoints"
})
public
RandomAttractionGenerator
(
int
numberOfAttractionPoints
)
{
...
...
@@ -62,6 +64,8 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
}
this
.
numberOfAPsSet
=
true
;
this
.
numberOfAttractionPoints
=
numberOfAttractionPoints
;
this
.
attractionPoints
=
new
LinkedList
<
AttractionPoint
>();
createAttractionPoints
();
}
@Override
...
...
@@ -71,13 +75,22 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
"Number of Attraction Points is not set in RandomAttractionGenerator!"
);
}
List
<
AttractionPoint
>
result
=
new
Vector
<
AttractionPoint
>();
if
(
attractionPoints
.
isEmpty
())
createAttractionPoints
();
return
attractionPoints
;
}
private
void
createAttractionPoints
()
{
List
<
AttractionPoint
>
result
=
new
LinkedList
<
AttractionPoint
>();
for
(
int
i
=
0
;
i
<
numberOfAttractionPoints
;
i
++)
{
PositionVector
posVec
=
createPosVec
();
AttractionPoint
aPoint
=
new
AttractionPointImpl
(
"AP"
+
i
,
posVec
);
AttractionPoint
aPoint
=
new
AttractionPointImpl
(
"AP"
+
i
,
posVec
);
result
.
add
(
aPoint
);
}
return
result
;
attractionPoints
.
clear
();
attractionPoints
.
addAll
(
result
);
}
private
PositionVector
createPosVec
()
{
...
...
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