EE445M RTOS
Taken at the University of Texas Spring 2015
motor Class Reference

#include <motorpp.hpp>

Inheritance diagram for motor:
Inheritance graph
Collaboration diagram for motor:
Collaboration graph

Public Member Functions

 motor ()
 
 motor (memory_address_t ctrl_base, memory_address_t ctrl_pin, memory_address_t pwm_base, memory_address_t pwm_gen, memory_address_t pwm_out, bool motor_installed_backwards=false)
 
void set_motor_installed_backwards (bool)
 
void stop (void)
 
void start (void)
 
void set (percent_t speed)
 
void set (percent_t percent_full_speed, Direction dir)
 
percent_t get (void)
 
void reverse (void)
 
- Public Member Functions inherited from critical
uint32_t StartCritical (void)
 
void EndCritical (uint32_t primask)
 

Static Public Attributes

static const uint16_t pwm_max_period = 10000
 

Private Member Functions

void motor_init (void)
 
void pwm_init (void)
 
Direction adjusted_direction (void)
 

Private Attributes

blinker ctrl
 
blinker pwm
 
memory_address_t ctrl_base
 
memory_address_t ctrl_pin
 
memory_address_t pwm_base
 
memory_address_t pwm_pin
 
memory_address_t pwm_gen
 
memory_address_t pwm_out
 
bool motor_installed_backwards
 
uint32_t pwm_period
 
uint32_t duty_period
 
Direction direction
 
percent_t current_speed
 
bool enabled
 

Additional Inherited Members

- Static Public Member Functions inherited from critical
static uint32_t static_StartCritical (void)
 
static void static_EndCritical (uint32_t primask)
 

Detailed Description

Definition at line 19 of file motorpp.hpp.

Constructor & Destructor Documentation

motor::motor ( )

Definition at line 11 of file motorpp.cpp.

11 {}
motor::motor ( memory_address_t  ctrl_base,
memory_address_t  ctrl_pin,
memory_address_t  pwm_base,
memory_address_t  pwm_gen,
memory_address_t  pwm_out,
bool  motor_installed_backwards = false 
)

Definition at line 13 of file motorpp.cpp.

References ctrl, ctrl_base, ctrl_pin, ctlsys::enable_periph(), enabled, motor_init(), motor_installed_backwards, pwm_base, pwm_gen, and pwm_out.

15  {
16 
17  this->ctrl = blinker(ctrl_base, ctrl_pin);
18  this->ctrl_base = ctrl_base;
19  this->ctrl_pin = ctrl_pin;
20  this->pwm_base = pwm_base;
21  this->pwm_gen = pwm_gen;
22  this->pwm_out = pwm_out;
23 
26 
28 
29  enabled = false;
30 
31  motor_init();
32 }
memory_address_t ctrl_base
Definition: motorpp.hpp:23
void motor_init(void)
Definition: motorpp.cpp:89
memory_address_t pwm_gen
Definition: motorpp.hpp:27
blinker ctrl
Definition: motorpp.hpp:21
bool motor_installed_backwards
Definition: motorpp.hpp:29
memory_address_t pwm_out
Definition: motorpp.hpp:28
bool enabled
Definition: motorpp.hpp:45
memory_address_t ctrl_pin
Definition: motorpp.hpp:24
memory_address_t pwm_base
Definition: motorpp.hpp:25
static void enable_periph(uint32_t sys_periph)
Definition: ctlsysctl.hpp:24

Here is the call graph for this function:

Member Function Documentation

Direction motor::adjusted_direction ( void  )
private

Return direction adjusted for motor position on the robot – Direction refers to the robot's orientation, not the motor's

Definition at line 39 of file motorpp.cpp.

References direction, motor_installed_backwards, and nav::opposite().

Referenced by set().

39  {
40 
42  direction;
43 }
bool motor_installed_backwards
Definition: motorpp.hpp:29
static Direction opposite(Direction d)
Definition: direction.hpp:12
Direction direction
Definition: motorpp.hpp:33

Here is the call graph for this function:

Here is the caller graph for this function:

percent_t motor::get ( void  )

Definition at line 141 of file motorpp.cpp.

References current_speed.

141  {
142 
143  return current_speed;
144 }
percent_t current_speed
Definition: motorpp.hpp:34
void motor::motor_init ( void  )
private

Initializes pins PE0-3 for output

Definition at line 89 of file motorpp.cpp.

References BACKWARD, direction, FORWARD, motor_installed_backwards, and pwm_init().

Referenced by motor().

89  {
90 
92 
93  pwm_init();
94 }
bool motor_installed_backwards
Definition: motorpp.hpp:29
void pwm_init(void)
Definition: motorpp.cpp:102
Direction direction
Definition: motorpp.hpp:33

Here is the call graph for this function:

Here is the caller graph for this function:

void motor::pwm_init ( void  )
private

Definition at line 102 of file motorpp.cpp.

References ctrl_base, DEFAULT_PWM_PERIOD, ctlsys::enable_periph(), critical::EndCritical(), FORWARD, pwm_base, pwm_gen, pwm_out, set(), start(), and critical::StartCritical().

Referenced by motor_init().

102  {
103 
104  uint32_t status = StartCritical();
105  /* nucleo: abstract */
106  ctlsys::enable_periph(GPIO_PORTB_BASE);
108 
109  SysCtlPWMClockSet(SYSCTL_PWMDIV_1);
110  PWMGenConfigure(pwm_base, pwm_gen, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
111  PWMGenPeriodSet(pwm_base, pwm_gen, DEFAULT_PWM_PERIOD);
112  PWMGenEnable(pwm_base, pwm_gen);
113 
114  switch(pwm_out) {
115  case PWM_OUT_0:
116  GPIOPinConfigure(GPIO_PB6_M0PWM0);
117  GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_6);
118  break;
119  case PWM_OUT_1:
120  GPIOPinConfigure(GPIO_PB7_M0PWM1);
121  GPIOPinTypePWM(GPIO_PORTB_BASE, GPIO_PIN_7);
122  break;
123  default:
124  while(1) {}
125  }
126 
127  /* Enable the outputs. */
128  PWMOutputState(pwm_base, (PWM_OUT_0_BIT | PWM_OUT_1_BIT), true);
129 
130  set(50, FORWARD);
131  start();
132  EndCritical(status);
133 }
void EndCritical(uint32_t primask)
Definition: criticalpp.hpp:14
memory_address_t ctrl_base
Definition: motorpp.hpp:23
uint32_t StartCritical(void)
Definition: criticalpp.hpp:9
memory_address_t pwm_gen
Definition: motorpp.hpp:27
void start(void)
Definition: motorpp.cpp:96
#define DEFAULT_PWM_PERIOD
Definition: motorpp.hpp:17
memory_address_t pwm_out
Definition: motorpp.hpp:28
void set(percent_t speed)
Definition: motorpp.cpp:67
memory_address_t pwm_base
Definition: motorpp.hpp:25
static void enable_periph(uint32_t sys_periph)
Definition: ctlsysctl.hpp:24

Here is the call graph for this function:

Here is the caller graph for this function:

void motor::reverse ( void  )

Reverse motor direction.

note maintains current speed

Definition at line 136 of file motorpp.cpp.

References current_speed, direction, nav::opposite(), and set().

Referenced by switch_responder().

136  {
137 
139 }
percent_t current_speed
Definition: motorpp.hpp:34
void set(percent_t speed)
Definition: motorpp.cpp:67
static Direction opposite(Direction d)
Definition: direction.hpp:12
Direction direction
Definition: motorpp.hpp:33

Here is the call graph for this function:

Here is the caller graph for this function:

void motor::set ( percent_t  speed)

Set the motor speed.

Definition at line 67 of file motorpp.cpp.

References adjusted_direction(), BACKWARD, clamp(), current_speed, enabled, FORWARD, pwm_base, pwm_max_period, and pwm_out.

Referenced by drive::backward(), drive::forward(), pwm_init(), reverse(), drive::set(), set(), drive::steer(), and stop().

67  {
68 
69  speed = clamp(speed, 1, pwm_max_period);
70 
71  current_speed = speed;
72 
73  uint16_t adjusted_duty;
74  switch(adjusted_direction()) {
75  case FORWARD:
76  adjusted_duty = speed;
77  break;
78  case BACKWARD:
79  adjusted_duty = pwm_max_period - speed;
80  break;
81  default: while(1) {}
82  }
83 
84  if (enabled == true) {
85  PWMPulseWidthSet(pwm_base, pwm_out, speed);
86  }
87 }
percent_t current_speed
Definition: motorpp.hpp:34
int32_t clamp(int32_t value, int32_t min, int32_t max)
Definition: math.cpp:5
Direction adjusted_direction(void)
Definition: motorpp.cpp:39
static const uint16_t pwm_max_period
Definition: motorpp.hpp:75
memory_address_t pwm_out
Definition: motorpp.hpp:28
bool enabled
Definition: motorpp.hpp:45
memory_address_t pwm_base
Definition: motorpp.hpp:25

Here is the call graph for this function:

Here is the caller graph for this function:

void motor::set ( percent_t  percent_full_speed,
Direction  dir 
)

Set motor speed and direction.

Definition at line 56 of file motorpp.cpp.

References adjusted_direction(), BACKWARD, ctrl, ctrl_pin, direction, FORWARD, set(), blinker::turn_off(), and blinker::turn_on().

56  {
57 
58  this->direction = dir;
59  switch(adjusted_direction()) {
60  case FORWARD: ctrl.turn_off(ctrl_pin); break;
61  case BACKWARD: ctrl.turn_on(ctrl_pin); break;
62  default: while(1) {}
63  }
64  set(speed);
65 }
Direction adjusted_direction(void)
Definition: motorpp.cpp:39
blinker ctrl
Definition: motorpp.hpp:21
virtual void turn_off(pin_t pin)
Definition: blinker.cpp:30
memory_address_t ctrl_pin
Definition: motorpp.hpp:24
void set(percent_t speed)
Definition: motorpp.cpp:67
virtual void turn_on(pin_t pin)
Definition: blinker.cpp:26
Direction direction
Definition: motorpp.hpp:33

Here is the call graph for this function:

void motor::set_motor_installed_backwards ( bool  backwards)

Denote that this motor is fastened to the robot in such a way that it requires reversed (directionally) control signals.

Definition at line 34 of file motorpp.cpp.

References motor_installed_backwards.

34  {
35 
36  this->motor_installed_backwards = backwards;
37 }
bool motor_installed_backwards
Definition: motorpp.hpp:29
void motor::start ( void  )

Enable power to the motor.

Definition at line 96 of file motorpp.cpp.

References enabled, pwm_base, and pwm_gen.

Referenced by pwm_init(), and drive::start().

96  {
97 
98  enabled = true;
99  PWMGenEnable(pwm_base, pwm_gen);
100 }
memory_address_t pwm_gen
Definition: motorpp.hpp:27
bool enabled
Definition: motorpp.hpp:45
memory_address_t pwm_base
Definition: motorpp.hpp:25

Here is the caller graph for this function:

void motor::stop ( void  )

Cut all power to the motor.

Definition at line 45 of file motorpp.cpp.

References BACKWARD, direction, enabled, and set().

Referenced by drive::stop().

45  {
46 
47  if (direction == BACKWARD) {
48  set(100);
49  } else {
50  set(0);
51  }
52  enabled = false;
53  /* PWMGenDisable(pwm_base, pwm_gen); */
54 }
bool enabled
Definition: motorpp.hpp:45
void set(percent_t speed)
Definition: motorpp.cpp:67
Direction direction
Definition: motorpp.hpp:33

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

blinker motor::ctrl
private

Definition at line 21 of file motorpp.hpp.

Referenced by motor(), and set().

memory_address_t motor::ctrl_base
private

Definition at line 23 of file motorpp.hpp.

Referenced by motor(), and pwm_init().

memory_address_t motor::ctrl_pin
private

Definition at line 24 of file motorpp.hpp.

Referenced by motor(), and set().

percent_t motor::current_speed
private

Definition at line 34 of file motorpp.hpp.

Referenced by get(), reverse(), and set().

Direction motor::direction
private

Definition at line 33 of file motorpp.hpp.

Referenced by adjusted_direction(), motor_init(), reverse(), set(), and stop().

uint32_t motor::duty_period
private

Definition at line 32 of file motorpp.hpp.

bool motor::enabled
private

Definition at line 45 of file motorpp.hpp.

Referenced by motor(), set(), start(), and stop().

bool motor::motor_installed_backwards
private

Definition at line 29 of file motorpp.hpp.

Referenced by adjusted_direction(), motor(), motor_init(), and set_motor_installed_backwards().

blinker motor::pwm
private

Definition at line 22 of file motorpp.hpp.

memory_address_t motor::pwm_base
private

Definition at line 25 of file motorpp.hpp.

Referenced by motor(), pwm_init(), set(), and start().

memory_address_t motor::pwm_gen
private

Definition at line 27 of file motorpp.hpp.

Referenced by motor(), pwm_init(), and start().

const uint16_t motor::pwm_max_period = 10000
static

Definition at line 75 of file motorpp.hpp.

Referenced by set(), and drive::steer().

memory_address_t motor::pwm_out
private

Definition at line 28 of file motorpp.hpp.

Referenced by motor(), pwm_init(), and set().

uint32_t motor::pwm_period
private

Definition at line 31 of file motorpp.hpp.

memory_address_t motor::pwm_pin
private

Definition at line 26 of file motorpp.hpp.


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