hollywood/example_actors/one_dim_robot/
model.rs1use std::fmt::Debug;
2use std::fmt::Display;
3
4#[derive(Clone, Debug, Default)]
6pub struct Stamped<T: Clone + Debug> {
7 pub time: f64,
9 pub seq: u64,
11 pub value: T,
13}
14
15impl<T: Clone + Debug> Stamped<T> {
16 pub fn from_stamp_counter_and_value(time: f64, seq: u64, value: &T) -> Self {
18 Self {
19 time,
20 seq,
21 value: value.clone(),
22 }
23 }
24}
25
26impl<T: Display + Clone + Debug> Display for Stamped<T> {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 write!(f, "@{} {}", self.time, self.value)
29 }
30}
31
32#[derive(Clone, Debug, Default)]
34pub struct Robot {
35 pub position: f64,
37 pub velocity: f64,
39}
40
41impl Display for Robot {
42 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43 write!(
44 f,
45 "position: {}, velocity: {})",
46 self.position, self.velocity
47 )
48 }
49}
50
51pub struct WorldModel {}
53
54impl WorldModel {
55 pub const BOUNDARY_EAST: f64 = 45.0;
57}
58
59pub struct RangeMeasurementModel {}
61
62impl RangeMeasurementModel {
63 pub const RANGE_STD_DEV: f64 = 0.1;
65
66 pub fn range(&self, robot_position: f64) -> f64 {
68 if robot_position > WorldModel::BOUNDARY_EAST {
69 panic!("not implemented");
70 } else {
71 WorldModel::BOUNDARY_EAST - robot_position
72 }
73 }
74
75 pub fn dx_range(&self) -> f64 {
77 -1.0
78 }
79}