Commit 25e1ab23 authored by Julian Zobel's avatar Julian Zobel
Browse files

Placement class for base stations and UAVs topology placement

parent 9ffd41f2
......@@ -36,6 +36,7 @@ import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.network.modular.DBHostListManager;
import de.tud.kom.p2psim.impl.network.modular.db.NetMeasurementDB;
import de.tud.kom.p2psim.impl.topology.component.BaseTopologyComponent;
import de.tud.kom.p2psim.impl.topology.component.DefaultTopologyComponent;
import de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent;
import de.tud.kom.p2psim.impl.topology.movement.AbstractWaypointMovementModel;
......@@ -90,6 +91,8 @@ public class TopologyFactory implements HostComponentFactory {
private boolean alreadyAddedMovement = false;
private boolean isUAVComponent = false;
private boolean isBaseStationComponent = false;
/**
*
......@@ -140,6 +143,9 @@ public class TopologyFactory implements HostComponentFactory {
if(isUAVComponent) {
toCo = new UAVTopologyComponent(host, topo, movement, placement, registerAsInformationProviderInSiS);
}
else if(isBaseStationComponent) {
toCo = new BaseTopologyComponent(host, topo, movement, placement, registerAsInformationProviderInSiS);
}
else {
toCo = new DefaultTopologyComponent(host, topo, movement, placement, registerAsInformationProviderInSiS);
}
......@@ -291,4 +297,8 @@ public class TopologyFactory implements HostComponentFactory {
public void setIsUAVComponent(boolean uav) {
this.isUAVComponent = uav;
}
public void setIsBaseStationComponent(boolean uav) {
this.isBaseStationComponent = uav;
}
}
......@@ -101,7 +101,7 @@ public abstract class AbstractTopologyComponent implements TopologyComponent {
if (placementModel != null) {
// retrieve the initial position of this topology component
position.set(placementModel.place(this));
position.set(placementModel.place(this));
}
if (registerAsInformationProviderInSiS) {
......
......@@ -20,12 +20,10 @@
package de.tud.kom.p2psim.impl.topology.component;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.Battery;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyModel;
import de.tud.kom.p2psim.api.topology.Topology;
......@@ -75,9 +73,7 @@ public class UAVTopologyComponent extends AbstractTopologyComponent implements S
try {
actuator = getHost().getComponent(EnergyModel.class)
.getComponent(ComponentType.ACTUATOR, ActuatorEnergyComponent.class);
actuator.turnOn();
.getComponent(ComponentType.ACTUATOR, ActuatorEnergyComponent.class);
} catch (ComponentNotAvailableException e) {
System.err.println("No Acutator Energy Component was found!");
}
......
......@@ -109,6 +109,7 @@ public class SimpleMutlicopterMovement implements UAVMovementModel {
PositionVector newPosition = new PositionVector(currentPosition);
newPosition.add(direction);
topologyComponent.updateCurrentLocation(newPosition, 1);
}
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.placement;
import java.util.LinkedList;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.topology.component.BaseTopologyComponent;
import de.tud.kom.p2psim.impl.topology.component.UAVTopologyComponent;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
public class UAVBasePlacement implements PlacementModel {
private static LinkedList<UAVTopologyComponent> uavs = new LinkedList<>();
private static BaseTopologyComponent base;
private static double baseX, baseY;
private void addComponent(BaseTopologyComponent comp) {
if(base == null) {
base = comp;
}
else throw new UnsupportedOperationException("Received second base topology, only one supported!");
}
private void addComponent(UAVTopologyComponent comp) {
uavs.add(comp);
}
@Override
public PositionVector place(TopologyComponent comp) {
PositionVector pos = new PositionVector(baseX, baseY, 0);
return pos;
}
@Override
public void addComponent(TopologyComponent comp) {
if(comp instanceof BaseTopologyComponent) {
this.addComponent((BaseTopologyComponent)comp);
}
else if(comp instanceof UAVTopologyComponent) {
this.addComponent((UAVTopologyComponent)comp);
}
else {
throw new UnsupportedOperationException("UAVBasePlacement received wrong type of topology component!");
}
}
public void setBaseX(double X) {
this.baseX = X;
}
public void setBaseY(double Y) {
this.baseY = Y;
}
}
......@@ -567,12 +567,19 @@ public class PositionVector implements Location {
@Override
public float bearingTo(Location dest) {
if (dest instanceof PositionVector) {
// This will be the angle between the difference vector (vec to dest) and the x-axis!
PositionVector t = (PositionVector) dest;
/*
* Calculates the angle using atan2 - this implies that the first
* two dimensions in your vector are the plane you are interested
* in.
*/
System.out.println("dest is " + t);
System.out.println("y vec dif " + (t.getEntry(1) - this.getEntry(1)));
System.out.println("x vec dif " + (t.getEntry(0) - this.getEntry(0)));
return (float) Math.atan2(t.getEntry(1) - this.getEntry(1),
t.getEntry(0) - this.getEntry(0));
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment