Merge remote-tracking branch 'refs/remotes/origin/master' into PID

This commit is contained in:
johan9107 2016-10-13 10:07:22 +02:00
commit de4348c385
4 changed files with 35 additions and 26 deletions

View File

@ -44,10 +44,10 @@ uint16_t motor_output[MOTOR_COUNT];
/* Default values for the mixerConfig */ /* Default values for the mixerConfig */
// TODO: Implement in EEPROM // TODO: Implement in EEPROM
mixerConfig_s mixerConfig = { mixerConfig_s mixerConfig = {
.minThrottle = 1000, .minThrottle = 1050,
.maxThrottle = 2000, .maxThrottle = 1950,
.minCommand = 1050, .minCommand = 1000,
.maxCommand = 1950, .maxCommand = 2000,
.minCheck = 1010, .minCheck = 1010,
.pid_at_min_throttle = true, .pid_at_min_throttle = true,
.motorstop = false, .motorstop = false,
@ -122,7 +122,7 @@ void mix()
} }
uint16_t throttleRange = mixerConfig.maxThrottle - mixerConfig.minThrottle; // The throttle range we have with current defines uint16_t throttleRange = mixerConfig.maxCommand - mixerConfig.minThrottle; // The throttle range we have with current defines
uint16_t RPY_MixRange = RPY_Mix_Max - RPY_Mix_Min; // Range of the desired mixer outputs uint16_t RPY_MixRange = RPY_Mix_Max - RPY_Mix_Min; // Range of the desired mixer outputs
uint16_t throttleMin = mixerConfig.minThrottle; // Import system variable uint16_t throttleMin = mixerConfig.minThrottle; // Import system variable
uint16_t throttleMax = mixerConfig.maxThrottle; // Import uint16_t throttleMax = mixerConfig.maxThrottle; // Import
@ -156,7 +156,7 @@ void mix()
for (int i = 0; i < MOTOR_COUNT; i++) for (int i = 0; i < MOTOR_COUNT; i++)
{ {
// Constrain in within the regulation of the mix // Constrain in within the regulation of the mix
motor_output[i] = RPY_Mix[i] + constrain(throttle * mixerUAV[i].throttle, throttleMin, throttleMax); motor_output[i] = RPY_Mix[i] + constrain(throttle * mixerUAV[i].throttle, throttleMin, mixerConfig.maxCommand);
motor_output[i] = constrain(motor_output[i], mixerConfig.minCommand, mixerConfig.maxCommand); motor_output[i] = constrain(motor_output[i], mixerConfig.minCommand, mixerConfig.maxCommand);
} }
} }
@ -185,7 +185,7 @@ void mix()
{ {
RPY_Mix[i] -= maxThrottleDifference; // We reduce the highest overflow on all motors RPY_Mix[i] -= maxThrottleDifference; // We reduce the highest overflow on all motors
RPY_Mix[i] = constrain(RPY_Mix[i], mixerConfig.minThrottle, mixerConfig.maxThrottle); RPY_Mix[i] = constrain(RPY_Mix[i], mixerConfig.minThrottle, mixerConfig.maxCommand);
if (throttle < mixerConfig.minCheck) if (throttle < mixerConfig.minCheck)
{ {
if (mixerConfig.motorstop) if (mixerConfig.motorstop)
@ -213,7 +213,7 @@ void mix()
motor_output[i] = constrain(motor_output[i], mixerConfig.minCommand, mixerConfig.maxCommand); motor_output[i] = constrain(motor_output[i], mixerConfig.minCommand, mixerConfig.maxCommand);
/* If not then stop motors */ /* If not then stop motors */
else else
motor_output[i] = mixerConfig.minThrottle; motor_output[i] = mixerConfig.minCommand;
/* Update actuators */ /* Update actuators */
pwmAdjustSpeedOfMotor( i + 1 /* Motors start from Motor 1 */,motor_output[i]); pwmAdjustSpeedOfMotor( i + 1 /* Motors start from Motor 1 */,motor_output[i]);

View File

@ -32,7 +32,7 @@ typedef struct
**************************************************************************/ **************************************************************************/
uint16_t checkPulse(uint16_t pulse) uint16_t checkPulse(uint16_t pulse)
{ {
return ((pulse/MotorPWMPeriode)*100 < 94)? pulse: MotorPWMPeriode*0.94; return ((pulse/MotorPWMPeriode)*100 < 98)? pulse: MotorPWMPeriode*0.98;
} }
/************************************************************************** /**************************************************************************
@ -126,13 +126,13 @@ uint32_t setMotorOutput(motorOutput motorOutput)
switch(motorOutput) switch(motorOutput)
{ {
case PWM: case PWM:
prescaler = 88; prescaler = 144;//88
break; break;
case Oneshot125: case Oneshot125:
prescaler = 11; prescaler = 17;
break; break;
default: default:
prescaler = 11; prescaler = 17;
break; break;
} }

View File

@ -26,6 +26,7 @@
#include "drivers/failsafe_toggles.h" #include "drivers/failsafe_toggles.h"
#include "drivers/sbus.h" #include "drivers/sbus.h"
#include "drivers/motormix.h" #include "drivers/motormix.h"
#include "drivers/motors.h"
/************************************************************************** /**************************************************************************
* BRIEF: Should contain all the initializations of the system, needs to * BRIEF: Should contain all the initializations of the system, needs to
@ -47,11 +48,14 @@ void init_system()
readEEPROM(); readEEPROM();
//initialize the CLI //initialize the CLI NOTE: Cant use the same usart as anything else or there will be some big trouble
cliInit(USART1); cliInit(USART3);
//init sbus //init sbus, using USART1
//sbus_init(); sbus_init();
//init motors to run with oneshot 125
pwmEnableAllMotors(Oneshot125);
#ifdef USE_LEDS #ifdef USE_LEDS
//Initialize the on board leds //Initialize the on board leds

View File

@ -39,21 +39,21 @@
#include "drivers/failsafe_toggles.h" #include "drivers/failsafe_toggles.h"
#include "drivers/I2C.h" #include "drivers/I2C.h"
#include "drivers/accel_gyro.h" #include "drivers/accel_gyro.h"
#include "drivers/motormix.h"
void systemTaskGyroPid(void) void systemTaskGyroPid(void)
{ {
//Read gyro and update PID and finally update the motors. The most important task in the system //Read gyro and update PID and finally update the motors. The most important task in the system
uint8_t c = 102; //call the motor mix
if (flags_IsSet_ID(systemFlags_Failsafe_noRcReceived_id)) mix();
usart_transmit(&cliUsart, &c, 1, 1000000000);
} }
void systemTaskAccelerometer(void) void systemTaskAccelerometer(void)
{ {
//update the accelerometer data //update the accelerometer data
uint8_t c = 97; // uint8_t c = 97;
usart_transmit(&cliUsart, &c, 1, 1000000000); // usart_transmit(&cliUsart, &c, 1, 1000000000);
} }
void systemTaskAttitude(void) void systemTaskAttitude(void)
@ -72,11 +72,16 @@ void systemTaskRx(void)
sbusFrame_s frame = sbusChannelData; sbusFrame_s frame = sbusChannelData;
/* Process channel data for switches and toggles on the controller, starts after "stick" channels */ /* Process channel data for switches and toggles on the controller, starts after "stick" channels */
for (int i = 1; i < STICK_CHANNEL_COUNT + AUX_CHANNEL_COUNT; i++) //ToDo: add define for the number of channels to process, /if not work change i to start at numb of stick channels for (int i = STICK_CHANNEL_COUNT; i < STICK_CHANNEL_COUNT + AUX_CHANNEL_COUNT; i++) //ToDo: add define for the number of channels to process, /if not work change i to start at numb of stick channels
{ {
flags_ProcessRcChannel(i+1, getChannelValue(frame, i+1)); flags_ProcessRcChannel(i+1, getChannelValue(frame, i+1));
} }
//temporary send data from the RC directly form the RC
PID_Out[0] = frame.chan1 - 1500;
PID_Out[1] = frame.chan2 - 1500;
PID_Out[2] = frame.chan4 - 1500;
} }
bool systemTaskRxCheck(uint32_t currentDeltaTime) bool systemTaskRxCheck(uint32_t currentDeltaTime)
@ -128,8 +133,8 @@ bool systemTaskRxCliCheck(uint32_t currentDeltaTime)
void systemTaskSerial(void) void systemTaskSerial(void)
{ {
uint8_t c = 118; // uint8_t c = 118;
usart_transmit(&cliUsart, &c, 1, 1000000000); // usart_transmit(&cliUsart, &c, 1, 1000000000);
if (flags_IsSet_ID(systemFlags_armed_id)) if (flags_IsSet_ID(systemFlags_armed_id))
ledOnInverted(Led0_PIN, Led0_GPIO_PORT); ledOnInverted(Led0_PIN, Led0_GPIO_PORT);
else else
@ -140,8 +145,8 @@ void systemTaskSerial(void)
void systemTaskBattery(void) void systemTaskBattery(void)
{ {
//Keep track of the battery level of the system //Keep track of the battery level of the system
uint8_t c = 98; // uint8_t c = 98;
usart_transmit(&cliUsart, &c, 1, 1000000000); // usart_transmit(&cliUsart, &c, 1, 1000000000);
if (flags_IsSet_MASK((systemFlags_flightmode_acceleromter_mask | systemFlags_armed_mask))) if (flags_IsSet_MASK((systemFlags_flightmode_acceleromter_mask | systemFlags_armed_mask)))
ledOnInverted(Led1, Led1_GPIO_PORT); ledOnInverted(Led1, Led1_GPIO_PORT);
else else