xyControl  0.1
Quadrotor Flight Controller on AVR Basis
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
Files | Functions | Variables
Motor Speed Mixer

Takes the Base Speed and PID-Output and sets Motor Speed accordingly. More...

Files

file  set.h
 Motor Mixer Library Header.
 
file  set.c
 Motor Mixer Library Implementation.
 

Functions

void setTask (void)
 Read the PID Output and Set the Motor Speeds. More...
 
void setMotorSpeeds (uint8_t axis, uint8_t *vals)
 Set the Motor Speeds according to the SET_* Motor Position Constants. More...
 

Variables

uint8_t baseSpeed
 Motor Base Speed. More...
 
uint8_t baseSpeed = 0
 Motor Base Speed. More...
 

Detailed Description

Takes the Base Speed and PID-Output and sets Motor Speed accordingly.

Function Documentation

void setMotorSpeeds ( uint8_t  axis,
uint8_t *  vals 
)
inline

Set the Motor Speeds according to the SET_* Motor Position Constants.

Parameters
axisROLL or PITCH
valsSpeeds for the two Motors on this axis (+, -)

Definition at line 57 of file set.c.

References motorSet(), PITCH, ROLL, SET_PITCHMINUS, SET_PITCHPLUS, SET_ROLLMINUS, and SET_ROLLPLUS.

Referenced by setTask().

57  {
58  if (axis == ROLL) {
59  motorSet(SET_ROLLPLUS, vals[0]);
60  motorSet(SET_ROLLMINUS, vals[1]);
61  } else if (axis == PITCH) {
62  motorSet(SET_PITCHPLUS, vals[0]);
63  motorSet(SET_PITCHMINUS, vals[1]);
64  }
65 }
void setTask ( void  )

Read the PID Output and Set the Motor Speeds.

Examples:
uartFlight.c.

Definition at line 67 of file set.c.

References baseSpeed, pidOutput, and setMotorSpeeds().

67  {
68  if (baseSpeed != 0) {
69  for (uint8_t i = 0; i < 2; i++) {
70  int16_t diff = pidOutput[i];
71  // Base-Speed is always positive, diff could be negative
72  if (diff > 0) {
73  if (diff > baseSpeed) {
74  diff = baseSpeed; // Limit PID
75  }
76  } else {
77  if (diff < -baseSpeed) {
78  diff = -baseSpeed; // Limit PID
79  }
80  }
81  uint8_t v[2] = { baseSpeed + diff, baseSpeed - diff };
82  if (v[0] < 10)
83  v[0] = 10; // Keep Motors running
84  if (v[1] < 10)
85  v[1] = 10;
86  setMotorSpeeds(i, v);
87  }
88  } else {
89  // Motors stopped
90  uint8_t v[2] = {0, 0};
91  setMotorSpeeds(0, v);
92  setMotorSpeeds(1, v);
93  }
94 }

Variable Documentation

uint8_t baseSpeed

Motor Base Speed.

Examples:
uartFlight.c.

Definition at line 51 of file set.c.

Referenced by setTask().

uint8_t baseSpeed = 0

Motor Base Speed.

Definition at line 51 of file set.c.

Referenced by setTask().