1 package cz.cuni.amis.pogamut.usar2004.communication.messages.usarinfomessages;
2
3 import java.util.*;
4 import javax.vecmath.*;
5 import cz.cuni.amis.pogamut.base.communication.worldview.event.*;
6 import cz.cuni.amis.pogamut.base.communication.translator.event.*;
7 import cz.cuni.amis.pogamut.base3d.worldview.object.*;
8 import cz.cuni.amis.pogamut.usar2004.communication.messages.*;
9 import cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes.CustomTypes.*;
10 import cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes.*;
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public class SensorMessage extends GBEvent implements IWorldEvent, IWorldChangeEvent
26 {
27 public SensorMessage(String Type, double Time, String Name, double Duration, double FOV, int Fix, double Loudness, double Prob, double Resolution, int Satellites, String Status, String Gas, double Density, boolean Visible, double Dist, double Radius, double Corona)
28 {
29 this.Type = Type;
30 this.Time = Time;
31 this.Name = Name;
32 this.Duration = Duration;
33 this.FOV = FOV;
34 this.Fix = Fix;
35 this.Loudness = Loudness;
36 this.Prob = Prob;
37 this.Resolution = Resolution;
38 this.Satellites = Satellites;
39 this.Status = Status;
40 this.Gas = Gas;
41 this.Density = Density;
42 this.Visible = Visible;
43 this.Radius = Radius;
44 this.Dist = Dist;
45 this.Corona = Corona;
46
47
48
49
50
51
52
53
54
55
56
57
58 }
59
60
61
62 public static final String PROTOTYPE = "SEN {Type text} {Time 0} {Name text} {Duration 0} {FOV 0} {Fix 0} {Loudness 0} {Prob 0} {Resolution 0} {Satellites 0} {Status text}";
63
64 protected String Type = null;
65
66
67
68
69
70
71
72
73
74 public String getType()
75 {
76 return Type;
77 }
78 protected double Time = 0;
79
80
81
82
83
84
85
86 public double getTime()
87 {
88 return Time;
89 }
90 protected String Name = null;
91
92
93
94
95
96
97 public String getName()
98 {
99 return Name;
100 }
101
102
103 protected Map<String, Double> RangeRanges = new HashMap<String, Double>();
104
105
106
107
108
109
110
111 public Map<String, Double> getRangeRanges()
112 {
113 return RangeRanges;
114 }
115
116
117
118
119
120
121
122 public void addRange(String Name, Double Range)
123 {
124 RangeRanges.put(Name, Range);
125 }
126
127 protected double Resolution = 0;
128
129
130
131
132
133
134
135 public double getResolution()
136 {
137 return Resolution;
138 }
139
140 protected double FOV = 0;
141
142
143
144
145
146
147 public double getFOV()
148 {
149 return FOV;
150 }
151 protected List<Double> LaserRanges = new ArrayList<Double>();
152
153
154
155
156
157
158 public List<Double> getLaserRanges()
159 {
160 return LaserRanges;
161 }
162
163
164 protected OdometryPose OdoPose = new OdometryPose();
165
166
167
168
169
170
171
172
173 public OdometryPose getOdoPose()
174 {
175 return OdoPose;
176 }
177
178 protected Latitude Latitude = new Latitude();
179
180
181
182
183
184
185
186
187
188 public Latitude getLatitude()
189 {
190 return Latitude;
191 }
192 protected Longitude Longitude = new Longitude();
193
194
195
196
197
198
199
200
201
202 public Longitude getLongitude()
203 {
204 return Longitude;
205 }
206 protected int Fix = 0;
207
208
209
210
211
212
213
214
215
216 public int getFix()
217 {
218 return Fix;
219 }
220
221 protected int Satellites = 0;
222
223
224
225
226
227
228
229
230 public int getSatellites()
231 {
232 return Satellites;
233 }
234
235
236
237 protected List<Location> Locations = new ArrayList<Location>();
238
239
240
241
242
243
244
245
246 public List<Location> getLocations()
247 {
248 return Locations;
249 }
250 protected List<Rotation> Orientations = new ArrayList<Rotation>();
251
252
253
254
255
256
257
258
259
260 public List<Rotation> getOrientations()
261 {
262 return Orientations;
263 }
264
265
266 protected Map<String, Integer> EncoderTicks = new HashMap<String, Integer>();
267
268
269
270
271
272
273
274
275
276 public Map<String, Integer> getEncoderTicks()
277 {
278 return EncoderTicks;
279 }
280
281
282 protected Map<String, Boolean> Touches = new HashMap<String, Boolean>();
283
284
285
286
287
288
289
290 public Map<String, Boolean> getTouches()
291 {
292 return Touches;
293 }
294
295
296
297
298
299
300 protected List<Integer> IDs = new ArrayList<Integer>();
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315 public List<Integer> getIDs()
316 {
317 return IDs;
318 }
319
320 protected List<String> PartNames = new ArrayList<String>();
321
322
323
324
325
326
327
328
329
330
331 public List<String> getPartNames()
332 {
333 return PartNames;
334
335 }
336
337 protected String Status = null;
338
339
340
341
342
343
344
345 public String getStatus()
346 {
347 return Status;
348 }
349
350
351 protected double Prob = 0;
352
353
354
355
356
357
358 public double getProb()
359 {
360 return Prob;
361 }
362
363 protected double Loudness = 0;
364
365
366
367
368
369
370 public double getLoudness()
371 {
372 return Loudness;
373 }
374 protected double Duration = 0;
375
376
377
378
379
380
381 public double getDuration()
382 {
383 return Duration;
384 }
385
386 protected Point4d Velocity = null;
387
388
389
390
391
392
393
394 public Point4d getVelocity()
395 {
396 return Velocity;
397 }
398 protected Point4d Position = null;
399
400
401
402
403
404
405
406 public Point4d getPosition()
407 {
408 return Position;
409 }
410
411 protected Velocity Acceleration = null;
412
413
414
415
416
417
418 public Velocity getAcceleration()
419 {
420 return Acceleration;
421 }
422
423 protected String Gas = null;
424
425
426
427
428
429
430
431
432 public String getGas()
433 {
434 return Gas;
435 }
436 protected double Density = 0;
437
438
439
440
441
442
443
444 public double getDensity()
445 {
446 return Density;
447 }
448
449 protected boolean Visible = false;
450
451
452
453
454
455
456
457 public boolean isVisible()
458 {
459 return Visible;
460 }
461 protected Point2d Pos2D = null;
462
463
464
465
466
467
468
469 public Point2d getPos2D()
470 {
471 return Pos2D;
472 }
473 protected Location Pos3D = null;
474
475
476
477
478
479
480
481 public Location getPos3D()
482 {
483 return Pos3D;
484 }
485 protected double Radius = 0;
486
487
488
489
490
491
492
493 public double getRadius()
494 {
495 return Radius;
496 }
497 protected double Dist = 0;
498
499
500
501
502
503
504
505 public double getDistance()
506 {
507 return Dist;
508 }
509 protected double Corona = 0;
510
511
512
513
514
515
516
517 public double getCorona()
518 {
519 return Corona;
520 }
521
522
523
524
525 public SensorMessage(SensorMessage original)
526 {
527 this.EncoderTicks.putAll(original.EncoderTicks);
528 this.Type = original.Type;
529 this.Time = original.Time;
530 this.Name = original.Name;
531 this.Duration = original.Duration;
532 this.FOV = original.FOV;
533 this.Fix = original.Fix;
534 this.Loudness = original.Loudness;
535 this.Prob = original.Prob;
536 this.Resolution = original.Resolution;
537 this.Satellites = original.Satellites;
538 this.IDs.addAll(original.IDs);
539 this.LaserRanges.addAll(original.LaserRanges);
540 this.Locations.addAll(original.Locations);
541 this.Longitude = original.Longitude;
542 this.Latitude = original.Latitude;
543 this.OdoPose = original.OdoPose;
544 this.Orientations.addAll(original.Orientations);
545 this.PartNames.addAll(original.PartNames);
546 this.Position = original.Position;
547 this.RangeRanges.putAll(original.RangeRanges);
548 this.Touches.putAll(original.Touches);
549 this.Velocity = original.Velocity;
550 this.Acceleration = original.Acceleration;
551 this.Status = original.Status;
552 this.Density = original.Density;
553 this.Gas = original.Gas;
554 this.Visible = original.Visible;
555 this.Pos2D = original.Pos2D;
556 this.Pos3D = original.Pos3D;
557 this.Radius = original.Radius;
558 this.Dist = original.Dist;
559 this.Corona = original.Corona;
560 }
561
562
563
564
565
566 public SensorMessage()
567 {
568 }
569
570 @Override
571 public String toString()
572 {
573 StringBuilder buf = new StringBuilder();
574
575 buf.append(super.toString() + " | "
576 + "Type = "
577 + String.valueOf(Type) + " | "
578 + "Time = "
579 + String.valueOf(Time) + " | "
580 + "Name = "
581 + String.valueOf(Name) + " | "
582 + "Duration = "
583 + String.valueOf(Duration) + " | "
584 + "FOV = "
585 + String.valueOf(FOV) + " | "
586 + "Fix = "
587 + String.valueOf(Fix) + " | "
588 + "Loudness = "
589 + String.valueOf(Loudness) + " | "
590 + "Prob = "
591 + String.valueOf(Prob) + " | "
592 + "Resolution = "
593 + String.valueOf(Resolution) + " | "
594 + "Satellites = "
595 + String.valueOf(Satellites) + " | "
596 + "Status = "
597 + String.valueOf(Status) + " | "
598 + "Gas = "
599 + String.valueOf(Gas) + " | "
600 + "Density = "
601 + String.valueOf(Density) + " | "
602 + "Radius = "
603 + String.valueOf(Radius) + " | "
604 + "Corona = "
605 + String.valueOf(Corona) + " | "
606 + "Visible = "
607 + String.valueOf(Visible) + " | "
608 + "Dist = "
609 + String.valueOf(Dist) + " | ");
610
611 if(!RangeRanges.isEmpty())
612 {
613 Iterator it = RangeRanges.entrySet().iterator();
614 while(it.hasNext())
615 {
616 Map.Entry en = (Map.Entry) it.next();
617 buf.append(" ").append(en.getKey()).append(" ").append(en.getValue()).append(",");
618 }
619 buf.append(" | ");
620 }
621
622
623 if(!Touches.isEmpty())
624 {
625 Iterator it = Touches.entrySet().iterator();
626 while(it.hasNext())
627 {
628 Map.Entry en = (Map.Entry) it.next();
629 buf.append(" ").append(en.getKey()).append(" = ").append(en.getValue()).append(" ");
630 }
631 buf.append(" | ");
632 }
633
634
635 if(Velocity != null)
636 {
637 buf.append("Velocity = ").append(String.valueOf(Velocity.w)).append(String.valueOf(Velocity.x)).append(String.valueOf(Velocity.y)).append(String.valueOf(Velocity.z)).append(" | ");
638 }
639
640 if(Acceleration != null)
641 {
642 buf.append("Acceleration = ").append(String.valueOf(Acceleration.x)).append(String.valueOf(Acceleration.y)).append(String.valueOf(Acceleration.z)).append(" | ");
643 }
644
645 if(!IDs.isEmpty())
646 {
647 for(Integer i : IDs)
648 {
649 buf.append("ID = ").append(i.toString()).append(" ");
650 }
651 buf.append(" | ");
652 }
653
654
655 if(!LaserRanges.isEmpty())
656 {
657 buf.append("LaserRange = ");
658 for(Double i : LaserRanges)
659 {
660 buf.append(i.toString()).append(" ");
661 }
662 buf.append(" | ");
663 }
664
665
666 if(!Locations.isEmpty())
667 {
668 for(Location i : Locations)
669 {
670 buf.append("Location = ").append(i.x).append(" ").append(i.y).append(" ").append(i.z).append(" ");
671 }
672 buf.append(" | ");
673 }
674
675
676 if(!Orientations.isEmpty())
677 {
678 for(Rotation i : Orientations)
679 {
680 buf.append("Orientation = ").append(i.yaw).append(" ").append(i.roll).append(" ").append(i.pitch).append(" ");
681 }
682 buf.append(" | ");
683 }
684
685
686 if(Longitude != null)
687 {
688 buf.append("Longitude = ").append(String.valueOf(Longitude.getDegree())).append(" ").append(String.valueOf(Longitude.getMinute())).append(" ").append(String.valueOf(Longitude.getCardinal() + " | "));
689 }
690
691 if(Latitude != null)
692 {
693 buf.append("Latitude = ").append(String.valueOf(Latitude.getDegree())).append(" ").append(String.valueOf(Latitude.getMinute())).append(" ").append(String.valueOf(Latitude.getCardinal() + " | "));
694 }
695
696 if(OdoPose != null)
697 {
698 buf.append("OdoPose = ").append(String.valueOf(OdoPose.getX())).append(" ").append(String.valueOf(OdoPose.getY())).append(" ").append(String.valueOf(OdoPose.getTheta() + " | "));
699 }
700
701 if(!PartNames.isEmpty())
702 {
703 for(String i : PartNames)
704 {
705 buf.append("PartNames = ").append(i).append(" ");
706 }
707 buf.append(" | ");
708 }
709
710
711 if(Position != null)
712 {
713 buf.append("Position = ").append(String.valueOf(Position.w)).append(String.valueOf(Position.x)).append(String.valueOf(Position.y)).append(String.valueOf(Position.z)).append(" | ");
714 }
715
716 if(Pos3D != null)
717 {
718 buf.append("Pos3D = ").append(String.valueOf(Pos3D.x)).append(String.valueOf(Pos3D.y)).append(String.valueOf(Pos3D.z)).append(" | ");
719 }
720 if(Pos2D != null)
721 {
722 buf.append("Pos2D = ").append(String.valueOf(Pos2D.x)).append(String.valueOf(Pos2D.y)).append(" | ");
723 }
724
725 return buf.toString();
726
727 }
728
729
730
731
732
733
734 public String toHtmlString()
735 {
736 StringBuilder buf = new StringBuilder();
737 buf.append(super.toString()
738 + "<b>Type</b> : "
739 + String.valueOf(Type)
740 + " <br/> "
741 + "<b>Time</b> : "
742 + String.valueOf(Time)
743 + " <br/> "
744 + "<b>Name</b> : "
745 + String.valueOf(Name)
746 + " <br/> "
747 + "<b>Duration</b> : "
748 + String.valueOf(Duration)
749 + " <br/> "
750 + "<b>FOV</b> : "
751 + String.valueOf(FOV)
752 + " <br/> "
753 + "<b>Fix</b> : "
754 + String.valueOf(Fix)
755 + " <br/> "
756 + "<b>Loudness</b> : "
757 + String.valueOf(Loudness)
758 + " <br/> "
759 + "<b>Prob</b> : "
760 + String.valueOf(Prob)
761 + " <br/> "
762 + "<b>Resolution</b> : "
763 + String.valueOf(Resolution)
764 + " <br/> "
765 + "<b>Satellites</b> : "
766 + String.valueOf(Satellites)
767 + " <br/> "
768 + "<b>Status</b> : "
769 + String.valueOf(Status)
770 + " <br/> "
771 + "<b>Gas</b> : "
772 + String.valueOf(Gas)
773 + " <br/> "
774 + "<b>Density</b> : "
775 + String.valueOf(Density)
776 + " <br/> "
777 + "<b>Dist</b> : "
778 + String.valueOf(Dist)
779 + " <br/> "
780 + "<b>Radius</b> : "
781 + String.valueOf(Radius)
782 + " <br/> "
783 + "<b>Corona</b> : "
784 + String.valueOf(Corona)
785 + " <br/> "
786 + "<b>Visible</b> : "
787 + String.valueOf(Visible)
788 + " <br/> ");
789
790 if(!RangeRanges.isEmpty())
791 {
792 Iterator it = RangeRanges.entrySet().iterator();
793 while(it.hasNext())
794 {
795 Map.Entry en = (Map.Entry) it.next();
796 buf.append(" ").append(en.getKey()).append(" ").append(en.getValue()).append(" <br/> ");
797 }
798 }
799
800 if(!Touches.isEmpty())
801 {
802 Iterator it = Touches.entrySet().iterator();
803 while(it.hasNext())
804 {
805 Map.Entry en = (Map.Entry) it.next();
806 buf.append(" ").append(en.getKey()).append(" = ").append(en.getValue()).append(" <br/> ");
807 }
808 }
809
810 if(Velocity != null)
811 {
812 buf.append("<b>Velocity</b> : ").append(String.valueOf(Velocity.w)).append(String.valueOf(Velocity.x)).append(String.valueOf(Velocity.y)).append(String.valueOf(Velocity.z)).append(" <br/> ");
813 }
814
815 if(Acceleration != null)
816 {
817 buf.append("<b>Acceleration</b> : ").append(String.valueOf(Acceleration.x)).append(String.valueOf(Acceleration.y)).append(String.valueOf(Acceleration.z)).append(" <br/> ");
818 }
819
820 if(!IDs.isEmpty())
821 {
822 for(Integer i : IDs)
823 {
824 buf.append("<b>ID</b> : ").append(i.toString()).append(" <br/> ");
825 }
826 }
827
828 if(!LaserRanges.isEmpty())
829 {
830 buf.append("<b>LaserRange</b> : ");
831 for(Double i : LaserRanges)
832 {
833 buf.append(i.toString()).append(" <br/> ");
834 }
835 }
836
837 if(!Locations.isEmpty())
838 {
839 for(Location i : Locations)
840 {
841 buf.append("<b>Location</b> : ").append(i.x).append(" ").append(i.y).append(" ").append(i.z).append(" <br/> ");
842 }
843 }
844
845 if(!Orientations.isEmpty())
846 {
847 for(Rotation i : Orientations)
848 {
849 buf.append("<b>Orientation</b> : ").append(i.yaw).append(" ").append(i.roll).append(" ").append(i.pitch).append(" <br/> ");
850 }
851 }
852 if(Longitude != null)
853 {
854 buf.append("<b>Longitude</b> : ").append(String.valueOf(Longitude.getDegree())).append(" ").append(String.valueOf(Longitude.getMinute())).append(" ").append(String.valueOf(Longitude.getCardinal() + " <br/> "));
855 }
856
857 if(Latitude != null)
858 {
859 buf.append("<b>Latitude</b> : ").append(String.valueOf(Latitude.getDegree())).append(" ").append(String.valueOf(Latitude.getMinute())).append(" ").append(String.valueOf(Latitude.getCardinal() + " <br/> "));
860 }
861
862 if(OdoPose != null)
863 {
864 buf.append("<b>OdoPose</b> : ").append(String.valueOf(OdoPose.getX())).append(" ").append(String.valueOf(OdoPose.getY())).append(" ").append(String.valueOf(OdoPose.getTheta() + " <br/> "));
865 }
866
867 if(!PartNames.isEmpty())
868 {
869 for(String i : PartNames)
870 {
871 buf.append("<b>PartNames</b> : ").append(i).append(" <br/> ");
872 }
873 }
874
875 if(Position != null)
876 {
877 buf.append("<b>Position</b> : ").append(String.valueOf(Position.w)).append(String.valueOf(Position.x)).append(String.valueOf(Position.y)).append(String.valueOf(Position.z)).append(" <br/> ");
878 }
879 if(Pos3D != null)
880 {
881 buf.append("<b>Pos3D</b> : ").append(String.valueOf(Pos3D.x)).append(String.valueOf(Pos3D.y)).append(String.valueOf(Pos3D.z)).append(" <br/> ");
882 }
883 if(Pos2D != null)
884 {
885 buf.append("<b>Pos2D</b> : ").append(String.valueOf(Pos2D.x)).append(String.valueOf(Pos2D.y)).append(" <br/> ");
886 }
887
888 return buf.toString();
889 }
890 }