Aruna
aruna::driver::Pwm Class Referenceabstract

#include <Pwm.h>

Inheritance diagram for aruna::driver::Pwm:
Collaboration diagram for aruna::driver::Pwm:

Public Member Functions

err_t set_frequency (uint32_t frequency_hz)
 Set frequency of PWM in hertz. More...
 
uint32_t get_frequency () const
 Get the frequency used in hertz. More...
 
err_t set_duty (float duty_percentage)
 Set the duty cycle on time in percentage. More...
 
err_t set_duty (uint16_t duty)
 Set the duty cycle on time (16bit). More...
 
float get_duty_per () const
 Get the duty cycle on time in percentage. More...
 
uint16_t get_duty () const
 Get the duty cycle on time (16bit) More...
 
- Public Member Functions inherited from aruna::movement::Actuator
 Actuator (axis_mask_t axis=axis_mask_t::NONE)
 Actuator object, used by the movement module for vehicle movement. More...
 
virtual ~Actuator ()
 
err_t set_axis (axis_mask_t new_axis)
 Set the axis that this Actuator is capable in moving in. More...
 
axis_mask_t get_axis ()
 get the movement modes that this driver supports. More...
 
err_t set (axis_mask_t axisMask, int16_t speed)
 Set the speed of the motors directly. More...
 
uint16_t get_speed ()
 Get the current speed of Actuator. More...
 

Private Member Functions

virtual err_t _set_frequency (uint32_t frequency_hz)=0
 
virtual err_t _set_duty (uint16_t duty)=0
 
err_t _set (movement::axis_mask_t axisMask, int16_t speed) override
 Implementation of axis movement, this function is called from set(...). More...
 

Private Attributes

uint32_t frequency_hz
 
uint16_t duty
 

Additional Inherited Members

- Public Attributes inherited from aruna::movement::Actuator
err_t startup_error = err_t::NOT_STARTED
 error when constructing gets put here, read before usage. More...
 
- Static Protected Member Functions inherited from aruna::movement::Actuator
static double convert_range (uint16_t input, float range_max=100.f, float range_min=0.f)
 Convert uint16 to a new range. More...
 

Detailed Description

Definition at line 13 of file Pwm.h.

Member Function Documentation

◆ _set()

err_t Pwm::_set ( movement::axis_mask_t  axisMask,
int16_t  speed 
)
overrideprivatevirtual

Implementation of axis movement, this function is called from set(...).

Only gets called when axisMask match axis of Actuator.

Parameters
axisMaskaxis (can be multiple) to set speed to.
speeddesired speed.
Returns
err_t::OK if successful, others when not...

Implements aruna::movement::Actuator.

Definition at line 44 of file Pwm.cpp.

44  {
45 // TODO allow for min and max duty_cycle
46 // TODO multi directional pwm
47 // TODO startup_error is not set to OK. Set to standard to OK, remove all together or standalize.
48  return set_duty((uint16_t)speed);
49 }
err_t set_duty(float duty_percentage)
Set the duty cycle on time in percentage.
Definition: Pwm.cpp:23

◆ _set_duty()

virtual err_t aruna::driver::Pwm::_set_duty ( uint16_t  duty)
privatepure virtual

◆ _set_frequency()

virtual err_t aruna::driver::Pwm::_set_frequency ( uint32_t  frequency_hz)
privatepure virtual

◆ get_duty()

uint16_t Pwm::get_duty ( ) const

Get the duty cycle on time (16bit)

Returns
on time (16bit)

Definition at line 11 of file Pwm.cpp.

11  {
12  return duty;
13 }
uint16_t duty
Definition: Pwm.h:16

◆ get_duty_per()

float Pwm::get_duty_per ( ) const

Get the duty cycle on time in percentage.

Returns
on time (0-100)

Definition at line 19 of file Pwm.cpp.

19  {
20  return duty / 65535 * 100;
21 }
uint16_t duty
Definition: Pwm.h:16

◆ get_frequency()

uint32_t Pwm::get_frequency ( ) const

Get the frequency used in hertz.

Returns
frequency in hertz

Definition at line 15 of file Pwm.cpp.

15  {
16  return frequency_hz;
17 }
uint32_t frequency_hz
Definition: Pwm.h:15

◆ set_duty() [1/2]

err_t Pwm::set_duty ( float  duty_percentage)

Set the duty cycle on time in percentage.

Parameters
duty_percentagevalue from 0 to 100
Returns
err_t::OK if it whent well.

Definition at line 23 of file Pwm.cpp.

23  {
24  uint16_t duty = round(duty_percentage / 100 * 65535);
25  return set_duty(duty);
26 }
uint16_t duty
Definition: Pwm.h:16
err_t set_duty(float duty_percentage)
Set the duty cycle on time in percentage.
Definition: Pwm.cpp:23
Here is the caller graph for this function:

◆ set_duty() [2/2]

err_t Pwm::set_duty ( uint16_t  duty)

Set the duty cycle on time (16bit).

Parameters
dutypwm on time
Returns
err_t::OK if successfull.

Definition at line 36 of file Pwm.cpp.

36  {
37  err_t err = _set_duty(duty);
38  if (err == err_t::OK) {
39  this->duty = duty;
40  }
41  return err;
42 }
virtual err_t _set_duty(uint16_t duty)=0
uint16_t duty
Definition: Pwm.h:16

◆ set_frequency()

err_t Pwm::set_frequency ( uint32_t  frequency_hz)

Set frequency of PWM in hertz.

Parameters
frequency_hzfrequency for pwm (might be set on multiple pwm objects)
Returns
unspecified aruna error

Definition at line 28 of file Pwm.cpp.

28  {
30  if (err == err_t::OK) {
31  this->frequency_hz = frequency_hz;
32  }
33  return err;
34 }
virtual err_t _set_frequency(uint32_t frequency_hz)=0
uint32_t frequency_hz
Definition: Pwm.h:15

Member Data Documentation

◆ duty

uint16_t aruna::driver::Pwm::duty
private

Definition at line 16 of file Pwm.h.

◆ frequency_hz

uint32_t aruna::driver::Pwm::frequency_hz
private

Definition at line 15 of file Pwm.h.


The documentation for this class was generated from the following files: