Aruna
Actuator.cpp
Go to the documentation of this file.
1 //
2 // Created by noeel on 22-10-20.
3 //
4 
6 
7 using namespace aruna;
8 using namespace aruna::movement;
9 
10 // TODO find a nice way to set speed to zero on destrion without calling a virtual function from destructor.
11 
12 Actuator::Actuator(axis_mask_t axis) : axis(axis){
13 
14 }
15 
17  return axis;
18 }
19 
20 err_t Actuator::set(axis_mask_t axisMask, int16_t speed) {
21  err_t err = err_t::OK;
22 // TODO check direction via axisMask with(uint8_t) axisMask & (uint8_t) axis_mask_t::DIRECTION_BOTH & (uint8_t) axis
23 // or check direction with the speed value, of just leave direction check to implementation.
24  if ((uint8_t) axisMask & (uint8_t) axis_mask_t::ALL_AXIS & (uint8_t) axis) {
25 
26  err = _set(axisMask, speed);
27  if (err == err_t::OK)
28  this->speed = speed;
29  }
30 // TODO return not avaliable error?
31  return err;
32 }
33 
34 uint16_t Actuator::get_speed() {
35 // TODO speed should be axis indipendent.
36  return speed;
37 }
38 
39 
41  axis = new_axis;
42  return err_t::OK;
43 }
44 
45 // TODO constexpr?
46 double Actuator::convert_range(uint16_t input, float range_max, float range_min) {
47 // TODO allow for other type then uint_16 (maybe use <template>? and sizeof()?)
48  return ((input * (range_max - range_min)) / 65535) + range_min;
49 }
50 
52 
53 }
Definition: comm.cpp:14
err_t set(axis_mask_t axisMask, int16_t speed)
Set the speed of the motors directly.
Definition: Actuator.cpp:20
static double convert_range(uint16_t input, float range_max=100.f, float range_min=0.f)
Convert uint16 to a new range.
Definition: Actuator.cpp:46
uint16_t get_speed()
Get the current speed of Actuator.
Definition: Actuator.cpp:34
err_t set_axis(axis_mask_t new_axis)
Set the axis that this Actuator is capable in moving in.
Definition: Actuator.cpp:40
Actuator(axis_mask_t axis=axis_mask_t::NONE)
Actuator object, used by the movement module for vehicle movement.
Definition: Actuator.cpp:12
axis_mask_t get_axis()
get the movement modes that this driver supports.
Definition: Actuator.cpp:16
virtual err_t _set(axis_mask_t axisMask, int16_t speed)=0
Implementation of axis movement, this function is called from set(...).