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
01a3ca94
Commit
01a3ca94
authored
Sep 24, 2018
by
Julian Zobel
Browse files
UAVs can now return to base and recharge
parent
0cdce77f
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/api/energy/Battery.java
View file @
01a3ca94
...
...
@@ -65,6 +65,13 @@ public interface Battery extends Cloneable {
default
public
void
reset
()
{
throw
new
UnsupportedOperationException
();
}
/**
* Resets the Battery to the maximum (full) Energy-Level
*/
default
public
void
setToMaximumLoad
()
{
throw
new
UnsupportedOperationException
();
}
/**
* Sets the battery to a given percentage.
...
...
src/de/tud/kom/p2psim/api/topology/component/ControllableLocationActuator.java
View file @
01a3ca94
...
...
@@ -56,5 +56,5 @@ public interface ControllableLocationActuator {
public
void
removeAllTargetLocations
();
public
void
returnToBase
(
ReachedLocationCallback
cb
);
}
src/de/tud/kom/p2psim/impl/energy/RechargeableBattery.java
View file @
01a3ca94
...
...
@@ -52,8 +52,8 @@ public class RechargeableBattery extends SimpleBattery {
}
@Override
public
void
re
set
()
{
currentEnergy
=
initialEnerg
y
;
public
void
set
ToMaximumLoad
()
{
currentEnergy
=
capacit
y
;
}
@Override
...
...
src/de/tud/kom/p2psim/impl/energy/UAVCharger.java
→
src/de/tud/kom/p2psim/impl/energy/UAV
Replacement
Charger.java
View file @
01a3ca94
...
...
@@ -20,38 +20,66 @@
package
de.tud.kom.p2psim.impl.energy
;
import
java.util.LinkedList
;
import
de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent
;
import
de.tudarmstadt.maki.simonstrator.api.Event
;
import
de.tudarmstadt.maki.simonstrator.api.EventHandler
;
import
de.tudarmstadt.maki.simonstrator.api.Host
;
import
de.tudarmstadt.maki.simonstrator.api.component.HostComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.HostComponentFactory
;
import
de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.BatteryReplacementCallback
;
/**
* Ground-based charger for UAVs
* Ground-based charger for UAVs. Replaces the battery completely, i.e.,
* sets battery capacity to full levels, but requires some time to do so.
*
*
* @author Julian Zobel
* @version 1.0, 21.09.2018
*/
public
class
UAVCharger
implements
HostComponent
{
public
class
UAV
Replacement
Charger
implements
HostComponent
{
private
Host
host
;
private
long
replacementDuration
;
private
int
chargerSize
;
private
LinkedList
<
UAVTopologyComponent
>
uavs
=
new
LinkedList
<>();
public
UAVCharger
(
Host
host
,
long
replacementDuration
,
int
chargerSize
)
{
public
UAVReplacementCharger
(
Host
host
,
long
replacementDuration
)
{
this
.
host
=
host
;
this
.
replacementDuration
=
replacementDuration
;
this
.
chargerSize
=
chargerSize
;
this
.
replacementDuration
=
replacementDuration
;
}
/**
* Charge a UAV by replacing the battery (i.e. reset to full battery levels). Replacement takes some time.
* The UAV is informed about the full replacement when it is finished by a callback.
*
* @param uav
* @param cb
*/
public
void
charge
(
UAVTopologyComponent
uav
,
BatteryReplacementCallback
cb
)
{
Event
.
scheduleWithDelay
(
replacementDuration
,
new
EventHandler
()
{
@Override
public
void
eventOccurred
(
Object
content
,
int
type
)
{
replacementComplete
(
uav
,
cb
);
}
},
null
,
0
);
}
/**
* When this is called (after the replacement duration) the UAV's battery is set
* to full level/max capacity.
*
* @param uav
* @param cb
*/
protected
void
replacementComplete
(
UAVTopologyComponent
uav
,
BatteryReplacementCallback
cb
)
{
uav
.
getBattery
().
setToMaximumLoad
();
cb
.
rechargeComplete
();
}
@Override
public
void
initialize
()
{
// TODO Auto-generated method stub
// TODO Auto-generated method stub
}
@Override
...
...
@@ -68,22 +96,19 @@ public class UAVCharger implements HostComponent {
public
static
class
Factory
implements
HostComponentFactory
{
private
long
replacementDuration
;
private
int
chargerSize
;
/**
* Duration of the battery replacement in SECONDS
* @param replacementDuration
*/
public
void
setReplacementDuration
(
long
replacementDuration
)
{
this
.
replacementDuration
=
replacementDuration
;
}
public
void
setChargerSize
(
int
chargerSize
)
{
this
.
chargerSize
=
chargerSize
;
}
@Override
public
HostComponent
createComponent
(
Host
host
)
{
return
new
UAVCharger
(
host
,
replacementDuration
,
chargerSize
);
return
new
UAV
Replacement
Charger
(
host
,
replacementDuration
);
}
}
}
src/de/tud/kom/p2psim/impl/topology/component/BaseTopologyComponent.java
View file @
01a3ca94
...
...
@@ -26,6 +26,8 @@ import de.tud.kom.p2psim.api.common.SimHost;
import
de.tud.kom.p2psim.api.topology.Topology
;
import
de.tud.kom.p2psim.api.topology.movement.MovementModel
;
import
de.tud.kom.p2psim.api.topology.placement.PlacementModel
;
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
;
...
...
@@ -33,6 +35,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
public
class
BaseTopologyComponent
extends
AbstractTopologyComponent
{
private
OverlayComponent
baseOverlayComponent
;
private
UAVReplacementCharger
charger
;
public
BaseTopologyComponent
(
SimHost
host
,
Topology
topology
,
MovementModel
movementModel
,
PlacementModel
placementModel
,
...
...
@@ -41,6 +45,17 @@ public class BaseTopologyComponent extends AbstractTopologyComponent {
registerAsInformationProviderInSiS
);
// TODO Auto-generated constructor stub
}
@Override
public
void
initialize
()
{
super
.
initialize
();
try
{
charger
=
getHost
().
getComponent
(
UAVReplacementCharger
.
class
);
}
catch
(
ComponentNotAvailableException
e
)
{
throw
new
AssertionError
(
"Unable to retrieve Replacement Charger for Base!"
);
}
}
@Override
public
double
getMinMovementSpeed
()
{
...
...
@@ -84,4 +99,9 @@ public class BaseTopologyComponent extends AbstractTopologyComponent {
public
OverlayComponent
getBaseComponent
()
{
return
baseOverlayComponent
;
}
public
UAVReplacementCharger
getCharger
()
{
return
charger
;
}
}
src/de/tud/kom/p2psim/impl/topology/component/UAVTopologyComponent.java
View file @
01a3ca94
...
...
@@ -41,6 +41,7 @@ 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.callbacks.ReachedLocationCallback
;
/**
...
...
@@ -176,6 +177,9 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
return
battery
.
getCurrentPercentage
();
}
public
RechargeableBattery
getBattery
()
{
return
battery
;
}
@Override
public
UAVMovementModel
getUAVMovement
()
{
...
...
@@ -257,9 +261,8 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
@Override
public
void
reachedLocation
()
{
cb
.
reachedLocation
();
deactivate
();
c
onnectToBaseCharger
();
c
b
.
reachedLocation
();
}
};
...
...
@@ -267,10 +270,16 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
}
pr
ivate
void
connectToBase
C
harge
r
()
{
pr
otected
void
connectToBase
AndRec
harge
()
{
BaseTopologyComponent
base
=
UAVBasePlacement
.
base
;
base
.
getCharger
().
charge
(
this
,
new
BatteryReplacementCallback
()
{
@Override
public
void
rechargeComplete
()
{
System
.
out
.
println
(
"Recharge completed!"
);
}
});
}
...
...
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