arci/clients/
dummy_motor_drive.rs1use std::sync::Mutex;
2
3use crate::{
4 error::Error,
5 traits::{MotorDriveEffort, MotorDrivePosition, MotorDriveVelocity},
6};
7
8#[derive(Debug)]
9pub struct DummyMotorDrivePosition {
10 pub current_position: Mutex<f64>,
11}
12
13impl DummyMotorDrivePosition {
14 pub fn new() -> Self {
15 Self {
16 current_position: Mutex::new(0f64),
17 }
18 }
19}
20
21impl Default for DummyMotorDrivePosition {
22 fn default() -> Self {
23 Self::new()
24 }
25}
26
27impl MotorDrivePosition for DummyMotorDrivePosition {
28 fn set_motor_position(&self, position: f64) -> Result<(), Error> {
29 *self.current_position.lock().unwrap() = position;
30 Ok(())
31 }
32
33 fn get_motor_position(&self) -> Result<f64, Error> {
34 Ok(*self.current_position.lock().unwrap())
35 }
36}
37
38#[derive(Debug)]
39pub struct DummyMotorDriveVelocity {
40 pub current_velocity: Mutex<f64>,
41}
42
43impl DummyMotorDriveVelocity {
44 pub fn new() -> Self {
45 Self {
46 current_velocity: Mutex::new(0f64),
47 }
48 }
49}
50
51impl Default for DummyMotorDriveVelocity {
52 fn default() -> Self {
53 Self::new()
54 }
55}
56
57impl MotorDriveVelocity for DummyMotorDriveVelocity {
58 fn set_motor_velocity(&self, velocity: f64) -> Result<(), Error> {
59 *self.current_velocity.lock().unwrap() = velocity;
60 Ok(())
61 }
62
63 fn get_motor_velocity(&self) -> Result<f64, Error> {
64 Ok(*self.current_velocity.lock().unwrap())
65 }
66}
67
68#[derive(Debug)]
69pub struct DummyMotorDriveEffort {
70 pub current_effort: Mutex<f64>,
71}
72
73impl DummyMotorDriveEffort {
74 pub fn new() -> Self {
75 Self {
76 current_effort: Mutex::new(0f64),
77 }
78 }
79}
80
81impl Default for DummyMotorDriveEffort {
82 fn default() -> Self {
83 Self::new()
84 }
85}
86
87impl MotorDriveEffort for DummyMotorDriveEffort {
88 fn set_motor_effort(&self, effort: f64) -> Result<(), Error> {
89 *self.current_effort.lock().unwrap() = effort;
90 Ok(())
91 }
92
93 fn get_motor_effort(&self) -> Result<f64, Error> {
94 Ok(*self.current_effort.lock().unwrap())
95 }
96}