UAVTopologyComponent.java 5.94 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * 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/>.
 *
 */

21
package de.tud.kom.p2psim.impl.topology.component;
22

23
24
import java.util.HashSet;
import java.util.LinkedList;
25
26
27
import java.util.Set;

import de.tud.kom.p2psim.api.common.SimHost;
28
29
30
import de.tud.kom.p2psim.api.energy.Battery;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyModel;
31
32
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
33
import de.tud.kom.p2psim.api.topology.movement.SimUAVLocationActuator;
34
35
import de.tud.kom.p2psim.api.topology.movement.UAVMovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
36
import de.tud.kom.p2psim.impl.energy.components.ActuatorEnergyComponent;
37
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
38
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
Julian Zobel's avatar
Julian Zobel committed
39
import de.tudarmstadt.maki.simonstrator.api.component.overlay.OverlayComponent;
40
import de.tudarmstadt.maki.simonstrator.api.component.sensor.battery.BatterySensor;
41
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
42
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
43
import de.tudarmstadt.maki.simonstrator.api.uavsupport.callbacks.ReachedLocationCallback;
44

Julian Zobel's avatar
Julian Zobel committed
45
46
47
48
49
50
/**
 * Topology component used for UAVs.
 * 
 * @author Julian Zobel
 * @version 1.0, 06.09.2018
 */
51
public class UAVTopologyComponent extends AbstractTopologyComponent implements SimUAVLocationActuator {
52
	
53
	private UAVMovementModel movement;
54
	
55
56
57
58
	private OverlayComponent uavOverlayComponent;
	
	private ActuatorEnergyComponent actuator;
	public BatterySensor battery;
Julian Zobel's avatar
Julian Zobel committed
59
	
60
61
62
63
64
65
66
67
68
69
70
71
	/**
	 * Create a TopologyComponent for the current host.
	 *
	 * @param host
	 * @param topology
	 * @param movementModel
	 */
	public UAVTopologyComponent(SimHost host, Topology topology,
			MovementModel movementModel, PlacementModel placementModel, boolean registerAsInformationProviderInSiS) {
		super(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
	}

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
	@Override
	public void initialize() {		
		super.initialize();
		
		try {
			actuator = getHost().getComponent(EnergyModel.class)
					.getComponent(ComponentType.ACTUATOR, ActuatorEnergyComponent.class);
			
			actuator.turnOn();
		} catch (ComponentNotAvailableException e) {
			System.err.println("No Acutator Energy Component was found!");
		}
		
		try {
			battery = getHost().getComponent(BatterySensor.class);
				
		} catch (ComponentNotAvailableException e) {
			System.err.println("No Battery Component was found!");
		}
	}
92
			
93
94
95
	public void setUAVComponent(OverlayComponent uavOverlayComponent) {
		this.uavOverlayComponent = uavOverlayComponent;
	}
96
	
97
98
99
100
	public OverlayComponent getUAVComponent() {
		return uavOverlayComponent;
	}

101
102
	@Override
	public double getMinMovementSpeed() {
Julian Zobel's avatar
Julian Zobel committed
103
		return movement.getMinCruiseSpeed();
104
105
106
107
	}

	@Override
	public double getMaxMovementSpeed() {
Julian Zobel's avatar
Julian Zobel committed
108
		return movement.getMaxCruiseSpeed();
109
110
111
112
	}

	@Override
	public double getMovementSpeed() {
Julian Zobel's avatar
Julian Zobel committed
113
		return movement.getCurrentSpeed();
114
115
116
117
	}

	@Override
	public void setMovementSpeed(double speed) {
Julian Zobel's avatar
Julian Zobel committed
118
		movement.setPreferredCruiseSpeed(speed);
119
120
121
	}

	@Override
122
123
124
125
126
127
128
129
130
131
132
	public boolean isActive() {
		return actuator.isOn();
	}

	@Override
	public boolean activate() {
		return actuator.turnOn();
	}

	@Override
	public boolean deactivate() {
133
		// TODO Auto-generated method stub
134
		return false;
135
136
137
	}

	@Override
138
139
	public PositionVector getCurrentLocation() {
		return position.clone();
140
141
142
	}

	@Override
143
	public double getCurrentBatteryLevel() {
144
		return battery.getCurrentPercentage();
145
	}
146

147
	
148
149
150
151
152
	@Override
	public UAVMovementModel getUAVMovement() {
		return movement;
	}

Julian Zobel's avatar
Julian Zobel committed
153
154
	@Override
	public void setUAVMovement(UAVMovementModel uavMovement) {
155
		this.movement = uavMovement;		
Julian Zobel's avatar
Julian Zobel committed
156
	}
157
158
159
160

	@Override
	public ActuatorEnergyComponent getActuatorEnergyComponent() {
		return actuator;
Julian Zobel's avatar
Julian Zobel committed
161
	}
162
163
164
165
166


	public void updateCurrentLocation(Location location, double actuatorLoad) {
		super.updateCurrentLocation(location);
		actuator.useActuator(actuatorLoad);
Julian Zobel's avatar
Julian Zobel committed
167
	}
168

169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
	@Override
	public Set<AttractionPoint> getAllAttractionPoints() {
		throw new UnsupportedOperationException();
	}

	@Override
	public void setTargetLocation(PositionVector targetLocation,
			ReachedLocationCallback cb) {
		movement.setTargetLocation(new PositionVector(targetLocation), cb);		
	}

	@Override
	public void addTargetLocation(PositionVector targetLocation,
			ReachedLocationCallback cb) {
		movement.addTargetLocation(new PositionVector(targetLocation), cb);
	}

	@Override
	public void setTargetLocationRoute(LinkedList<PositionVector> route,
			ReachedLocationCallback cb) {
		LinkedList<PositionVector> positionvectorlist = new LinkedList<>();
		for (Location loc : route) {
			positionvectorlist.add(new PositionVector(loc));
		}
		movement.setTargetLocationRoute(positionvectorlist, cb);
	}

	@Override
	public void removeAllTargetLocations() {
		movement.removeTargetLocations();
	}

	@Override
	public void setTargetAttractionPoint(AttractionPoint targetAttractionPoint) {
		throw new UnsupportedOperationException();		
	}

	@Override
	public AttractionPoint getCurrentTargetAttractionPoint() {
		throw new UnsupportedOperationException();
	}

	@Override
	public LinkedList<PositionVector> getTargetLocations() {
		return movement.getTargetLocations();
	}



Julian Zobel's avatar
Julian Zobel committed
218
219
220
	


221
222
223
224
225
	
	


}