Skip to content
Snippets Groups Projects
Commit 7d20d803 authored by Oleksandr Husak's avatar Oleksandr Husak
Browse files

way points from new topic

parent a7f0291d
No related branches found
No related tags found
No related merge requests found
...@@ -30,49 +30,98 @@ Connection settings ...@@ -30,49 +30,98 @@ Connection settings
- 2. Send messages to a `hivemq` public broker - 2. Send messages to a `hivemq` public broker
- topic `ipos/client/position` - topic `ipos/client/position`
- new positions - new positions
- ```json - ```json
{
"objects": [
{ {
"id": "Employee1", "objects": [
"sensorId": "UWB_1",
"type": "HUMAN",
"sensorType": "UWB",
"position": {
"refSystemId": "ROOT",
"point": {
"x": 28,
"y": -12,
"z": 20
},
"accuracy": 1
},
"orientation": {
"x": 0,
"y": 0,
"z": -0.7071,
"w": 0.7071
},
"extractedAttributes": {
"batteryChargeLevel": 70,
"loadedItems": [23, 1, 25, 17],
"errors": [2, 1, 6],
"theta": -0.9
},
"lastPosUpdate": "2021-09-14T09:41:20+00:00",
"zoneDescriptors": [
{ {
"zoneId": "door_zone", "id": "Employee1",
"notificationType": "EntryNotification" "sensorId": "UWB_1",
"type": "HUMAN",
"sensorType": "UWB",
"position": {
"refSystemId": "ROOT",
"point": {
"x": 28,
"y": -12,
"z": 20
},
"accuracy": 1
},
"orientation": {
"x": 0,
"y": 0,
"z": -0.7071,
"w": 0.7071
},
"extractedAttributes": {
"batteryChargeLevel": 70,
"loadedItems": [23, 1, 25, 17],
"errors": [2, 1, 6],
"theta": -0.9
},
"lastPosUpdate": "2021-09-14T09:41:20+00:00",
"zoneDescriptors": [
{
"zoneId": "door_zone",
"notificationType": "EntryNotification"
}
]
} }
] ],
"type": "EntryNotification"
} }
], ```
"type": "EntryNotification"
}
```
- More objects can be added to the `"object": []` - More objects can be added to the `"object": []`
- There are special colours for objects with id `"Employee1"` - `"Employee4"`. Config: [MarkerColorMap](src/environments/environment.ts) - There are special colours for objects. Config: [MarkerColorList](src/environments/environment.ts)
- topic `ipos/client/way`
- new way points
- ```json
[
{
"agentId":"Employee1",
"agentType":"HUMAN",
"publisher":"main",
"position":{
"refSystemId":"ROOT",
"point":{
"x":58,
"y":42,
"z":20
}
},
"time":"2022-04-14T09:41:20+00:00"
},
{
"agentId":"Employee1",
"agentType":"HUMAN",
"publisher":"main",
"position":{
"refSystemId":"ROOT",
"point":{
"x":18,
"y":12,
"z":50
}
},
"time":"2022-04-14T09:41:20+00:00"
},
{
"agentId":"Employee2",
"agentType":"ROBOT",
"publisher":"Employee2",
"position":{
"refSystemId":"ROOT",
"point":{
"x":-18,
"y":-52,
"z":33
}
},
"time":"2022-04-14T10:41:20+00:00"
}
]
```
- topic `ipos/client/root` - topic `ipos/client/root`
- ```json - ```json
{ {
......
...@@ -6,7 +6,16 @@ import 'leaflet-arrowheads'; ...@@ -6,7 +6,16 @@ import 'leaflet-arrowheads';
import { IMqttMessage, MqttService } from 'ngx-mqtt'; import { IMqttMessage, MqttService } from 'ngx-mqtt';
import { environment, getMarkerConfig} from 'src/environments/environment'; import { environment, getMarkerConfig} from 'src/environments/environment';
import {Position, PositionUpdate, RelativePos, WGS84, validateTypePosition, validateTypeAgent} from 'src/app/model/base-model'; import {
Position,
PositionUpdate,
RelativePos,
WGS84,
validateTypePosition,
validateTypeAgent,
WayPoint,
isWayPoint
} from 'src/app/model/base-model';
@Component({ @Component({
...@@ -18,17 +27,20 @@ export class MapComponent implements OnInit { ...@@ -18,17 +27,20 @@ export class MapComponent implements OnInit {
private subsPosition: Subscription; private subsPosition: Subscription;
private subsRoot: Subscription; private subsRoot: Subscription;
private subsWayPoint: Subscription;
private map!: L.Map; private map!: L.Map;
private root!: Position; private root!: Position;
agentsInfo: { [key: string]: {} } = {}; agentsInfo: { [key: string]: {} } = {};
markOverlays: { [key: string]: L.LayerGroup<any> } = {}; markOverlays: { [key: string]: L.LayerGroup<any> } = {};
wayPointsOverlays: { [key: string]: L.LayerGroup<any> } = {};
posOverlays: { [key: string]: L.LayerGroup<any> } = {}; posOverlays: { [key: string]: L.LayerGroup<any> } = {};
constructor(private _mqttService: MqttService) { constructor(private _mqttService: MqttService) {
this.root = {"refSystemId": "ROOT", "point": {"latitude": 51.02545, "longitude": 13.72295}} this.root = {"refSystemId": "ROOT", "point": {"latitude": 51.02545, "longitude": 13.72295}}
// --- Root
this.subsRoot = this._mqttService.observe('ipos/client/root').subscribe((message: IMqttMessage) => { this.subsRoot = this._mqttService.observe('ipos/client/root').subscribe((message: IMqttMessage) => {
try { try {
let root = <Position>JSON.parse(message.payload.toString()) let root = <Position>JSON.parse(message.payload.toString())
...@@ -41,6 +53,7 @@ export class MapComponent implements OnInit { ...@@ -41,6 +53,7 @@ export class MapComponent implements OnInit {
} }
}); });
// --- Agent position
this.subsPosition = this._mqttService.observe('ipos/client/position').subscribe((message: IMqttMessage) => { this.subsPosition = this._mqttService.observe('ipos/client/position').subscribe((message: IMqttMessage) => {
try { try {
let upd: PositionUpdate = <PositionUpdate>JSON.parse(message.payload.toString()) let upd: PositionUpdate = <PositionUpdate>JSON.parse(message.payload.toString())
...@@ -53,6 +66,24 @@ export class MapComponent implements OnInit { ...@@ -53,6 +66,24 @@ export class MapComponent implements OnInit {
console.log(e) console.log(e)
} }
}); });
// --- Agent way points
this.subsWayPoint = this._mqttService.observe('ipos/client/way').subscribe((message: IMqttMessage) => {
try {
let points: WayPoint[] = <WayPoint[]>JSON.parse(message.payload.toString())
console.log(points)
points.forEach(wayPoint => {
if (isWayPoint(wayPoint)) {
this.registerWayPoint(wayPoint)
}
});
} catch(e) {
console.log(e)
}
});
} }
ngOnInit(): void { } ngOnInit(): void { }
...@@ -86,8 +117,6 @@ export class MapComponent implements OnInit { ...@@ -86,8 +117,6 @@ export class MapComponent implements OnInit {
// } // }
// }); // });
} else { } else {
this.markOverlays[key] = L.layerGroup().addTo(<L.Map>this.map) this.markOverlays[key] = L.layerGroup().addTo(<L.Map>this.map)
} }
...@@ -111,6 +140,50 @@ export class MapComponent implements OnInit { ...@@ -111,6 +140,50 @@ export class MapComponent implements OnInit {
this.addMarker(key, pos, props, desc.extractedAttributes?.theta) this.addMarker(key, pos, props, desc.extractedAttributes?.theta)
} }
registerWayPoint(wayPoint: WayPoint) {
// empty position
if (wayPoint.position==undefined) {
console.log("Error: empty position.")
return
}
// empty position
if (Object.values(wayPoint.position).every((e)=>{e==undefined})) {
console.log("Error: empty point.")
return;
}
let key = wayPoint.agentId
// --- Marker config
let serialNum = Object.keys(this.markOverlays).indexOf(key)
var markerConf = getMarkerConfig(serialNum)
// --- Layer on the map
if (!(key in this.wayPointsOverlays)) {
this.wayPointsOverlays[key] = L.layerGroup().addTo(<L.Map>this.map)
}
let point = wayPoint.position.point
if ('x' in point) {
var globPos = this.ref2root(point)
} else {
var globPos = L.latLng([point.latitude, point.longitude]);
}
// --- Marker
let markerDesc = `<p> \
<h4>Way point</h4>
<strong>Agent</strong>: ${wayPoint.agentId} <br>\
<strong>Time</strong>: ${wayPoint.time} <br>
</p>`
let marker = L.circleMarker(globPos, {radius: 5, color: markerConf.color}).bindPopup(markerDesc).openPopup();
marker.addTo(this.wayPointsOverlays[key])
}
addMarker(key: string, pos: Position, popup: string, theta: number) { addMarker(key: string, pos: Position, popup: string, theta: number) {
// empty position // empty position
......
...@@ -7,7 +7,7 @@ export interface PositionUpdate { ...@@ -7,7 +7,7 @@ export interface PositionUpdate {
export interface Agent { export interface Agent {
id: string id: string
sensorId: string sensorId: string
type: ObjectType type: AgentType
sensorType: SensorType sensorType: SensorType
position: Position position: Position
orientation?: Quaternion orientation?: Quaternion
...@@ -53,7 +53,7 @@ export enum NotificationType { ...@@ -53,7 +53,7 @@ export enum NotificationType {
"Unknown" "Unknown"
} }
enum ObjectType { enum AgentType {
"HUMAN", "HUMAN",
"BOX", "BOX",
"ROBOT" "ROBOT"
...@@ -108,4 +108,23 @@ export function isAgent(obj: any): obj is Agent { ...@@ -108,4 +108,23 @@ export function isAgent(obj: any): obj is Agent {
&& "id" in obj && "id" in obj
&& "position" in obj && "position" in obj
&& isPosition(obj.position) && isPosition(obj.position)
} }
\ No newline at end of file
// --- Way points
export interface WayPoint {
"agentId": string
"agentType"?: AgentType
"publisher"?: string
"position": Position
"time": string
}
export function isWayPoint(obj: any): obj is WayPoint {
return obj
&& "agentId" in obj
&& "time" in obj
&& isPosition(obj.position)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment