SWARM-Bot Firmware  v1.0
Mobile robot OS - Embedded C/C++
__dc_control__.h File Reference

Header file for dc_control.c. More...

#include <__swarm_wold__.h>
Include dependency graph for __dc_control__.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MA   1
 
#define MB   2
 
#define DEBUG_CONTROLLER   0
 
#define K_P   4.0
 
#define K_I   0.3
 
#define K_D   0.5
 

Functions

int16_t _ref (uint8_t motor)
 
void _command (uint8_t motor, int16_t inputValue)
 
float _sens (uint8_t motor)
 
int _set_speed (uint8_t motor, int value)
 
void _break_motor (uint8_t motor)
 
void _init_dc_control (void)
 
int16_t _update_controller (uint8_t motor)
 
int16_t _dc_controller_loop (void)
 

Detailed Description

Header file for dc_control.c.

  • File: dc_control.h
  • Compiler: GCC-AVR
  • Supported devices: Tested on 328p
  • AppNote: PID for DC motor control
Author
Swarm robot graduation project workgroub
Mechatronics Program for the Distinguished
$Name$
Revision
1

$RCSfile$

Date
/26/2021 9:18:13 PM

Definition in file __dc_control__.h.

Function Documentation

◆ _break_motor()

void _break_motor ( uint8_t  motor)

breaks the

Parameters
motor
Parameters
[in]motormotor MA or MB.
95 {
96  if (motor == MA)
97  {
98  _set_pwm_0A(0);
99  _set_pwm_1A(0);
100  }
101  else if (motor == MB)
102  {
103  _set_pwm_0B(0);
104  _set_pwm_1B(0);
105  }
106 }
void _set_pwm_0B(int input)
Definition: __pwm__.c:22
void _set_pwm_1B(int input)
Definition: __pwm__.c:51
void _set_pwm_0A(int input)
Definition: __pwm__.c:8
void _set_pwm_1A(int input)
Definition: __pwm__.c:36

Referenced by _set_speed().

Here is the caller graph for this function:

◆ _command()

void _command ( uint8_t  motor,
int16_t  inputValue 
)

Output command module for

Parameters
motorof value
inputValue
Parameters
[in]motormotor MA or MB.
[in]inputValueinput value
37 {
38  _set_speed(motor,inputValue);
39 }
int _set_speed(uint8_t motor, int value)
Definition: __dc_control__.c:58

References _set_speed().

Here is the call graph for this function:

◆ _dc_controller_loop()

int16_t _dc_controller_loop ( void  )

PID DC controller loop

129 {
130  if(_controler_flag_A)
131  {
132  _update_controller(MA);
133  _controler_flag_A = 0;
134  }
135  if(_controler_flag_B)
136  {
137  _update_controller(MB);
138  _controler_flag_B = 0;
139  }
140  return 0;
141 }
int16_t _update_controller(uint8_t motor)
Definition: __dc_control__.c:114

◆ _init_dc_control()

void _init_dc_control ( void  )

Initialize the DC PID control module

109 {
110  pid_Init(K_P * SCALING_FACTOR, K_I * SCALING_FACTOR , K_D * SCALING_FACTOR , &pidData);
111  sei();
112 }
void pid_Init(int16_t p_factor, int16_t i_factor, int16_t d_factor, struct PID_DATA *pid)
Initialisation of PID controller parameters.
Definition: _pid_.c:34

References pid_Init().

Here is the call graph for this function:

◆ _ref()

int16_t _ref ( uint8_t  motor)

Reference for

Parameters
motor
Parameters
[in]motormotor MA or MB.
24 {
25  if(motor == MA)
26  {
27  return 20;
28  }
29  else if (motor == MB)
30  {
31  return 30;
32  }
33  return 0;
34 }

Referenced by _update_controller().

Here is the caller graph for this function:

◆ _sens()

float _sens ( uint8_t  motor)

sensor module for

Parameters
motor
Parameters
[in]motormotor MA or MB.
42 {
43  if(motor == MA)
44  {
45  return (_omega_from_encA()*9.55);
46  }
47  else if (motor == MB)
48  {
49 
50  return (_omega_from_encB()*9.55);
51  }
52  else
53  {
54  return -1;
55  }
56 }

Referenced by _update_controller().

Here is the caller graph for this function:

◆ _set_speed()

int _set_speed ( uint8_t  motor,
int  value 
)

L298 driver module using PWM signals and motor orientation

Parameters
valuecan be negative or positive for direction
Parameters
[in]motormotor MA or MB.
[in]valuespeed value
59 {
60  if(value == 0)
61  {
62  _break_motor(motor);
63  return value;
64  }
65  if(value < 0)
66  {
67  if (motor == MA)
68  {
69  _set_pwm_0A(-1*value);
70  _set_pwm_1A(0);
71  }
72  else if (motor == MB)
73  {
74  _set_pwm_0B(0);
75  _set_pwm_1B(-1*value);
76  }
77  }
78  else if(value > 0)
79  {
80  if (motor == MA)
81  {
82  _set_pwm_0A(0);
83  _set_pwm_1A(value);
84  }
85  else if (motor == MB)
86  {
87  _set_pwm_0B(value);
88  _set_pwm_1B(0);
89  }
90  }
91  return value;
92 }
void _break_motor(uint8_t motor)
Definition: __dc_control__.c:94

References _break_motor().

Referenced by _command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _update_controller()

int16_t _update_controller ( uint8_t  motor)

Update a control iteration for a discrete PID controller for the DC motor

Parameters
[in]motormotor MA or MB.
115 {
116  int16_t ref, sen,u;
117  ref = _ref(motor);
118  sen = (int16_t) _sens(motor);
119  u = pid_Controller(ref,sen, &pidData);
120  _command(motor, u);
121  if (DEBUG_CONTROLLER)
122  {
123  printf("%d - %d - %d\n",ref, sen, u);
124  }
125  return u;
126 }
int16_t _ref(uint8_t motor)
Definition: __dc_control__.c:23
void _command(uint8_t motor, int16_t inputValue)
Definition: __dc_control__.c:36
float _sens(uint8_t motor)
Definition: __dc_control__.c:41
int16_t pid_Controller(int16_t setPoint, int16_t processValue, struct PID_DATA *pid_st)
PID control algorithm.
Definition: _pid_.c:58

References _ref(), _sens(), and pid_Controller().

Here is the call graph for this function: