Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flight_ctrl: set stop state once so debugging is possible #13

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 0 additions & 128 deletions Attic/attitude.c

This file was deleted.

32 changes: 0 additions & 32 deletions Attic/attitude.h

This file was deleted.

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ CFLAGS += -ffunction-sections
CFLAGS += -fdata-sections
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wsign-compare
#CFLAGS += -Wextra
#CFLAGS += -Wpointer-arith
#CFLAGS += -Winline
Expand Down
14 changes: 9 additions & 5 deletions Source/attitude.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "attitude.h"
#include "util.h"
#include "sensors.h"
#include <stdio.h>

struct dcm dcm = {
Expand Down Expand Up @@ -63,13 +64,13 @@ static mat3f dcm_integrate(mat3f A, vec3f w, float dt)
}


extern void dcm_update(vec3f gyro, vec3f acc, float dt)
extern void dcm_update(struct sensor_data *sensor, float dt)
{
dcm.offset_p = vec3f_zero;

// Apply accelerometer correction
//
vec3f down = vec3f_matmul(dcm.matrix, vec3f_norm(acc));
vec3f down = vec3f_matmul(dcm.matrix, vec3f_norm(sensor->acc));
vec3f error = vec3f_cross(down, dcm.down_ref);

dcm.debug = error;
Expand All @@ -81,7 +82,7 @@ extern void dcm_update(vec3f gyro, vec3f acc, float dt)

// Calculate drift-corrected roll, pitch and yaw angles
//
dcm.omega = gyro;
dcm.omega = sensor->gyro;
dcm.omega = vec3f_add(dcm.omega, dcm.offset_p);
dcm.omega = vec3f_add(dcm.omega, dcm.offset_i);

Expand All @@ -103,12 +104,13 @@ void dcm_reset(void)

// -----
#include <string.h>
#include "command.h"


void cmd_dcm_show(void)
static void cmd_dcm_show(void)
{
struct dcm d;
ATOMIC_COPY(&d, &dcm, sizeof(d));
memcpy(&d, &dcm, sizeof(d));

printf(" x/roll y/pitch z/yaw\n");
printf("down_ref : %10.4f %10.4f %10.4f\n", d.down_ref.x, d.down_ref.y, d.down_ref.z);
Expand All @@ -126,3 +128,5 @@ void cmd_dcm_show(void)
printf("\n");
printf("debug : %10.4f %10.4f %10.4f\n", d.debug.x, d.debug.y, d.debug.z);
}

SHELL_CMD(dcm_show, (cmdfunc_t)cmd_dcm_show, "show dcm values")
6 changes: 2 additions & 4 deletions Source/attitude.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "matrix3f.h"
#include "sensors.h"

struct dcm {
mat3f matrix; ///< current direction cosine matrix
Expand All @@ -23,8 +24,5 @@ struct dcm {

extern struct dcm dcm;

extern void dcm_update(vec3f gyro, vec3f acc, float dt);
extern void dcm_update(struct sensor_data *sensor, float dt);
extern void dcm_reset(void);

extern void cmd_dcm_show(void);

2 changes: 1 addition & 1 deletion Source/dma_io_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void DMA2_Stream7_IRQHandler(void)
uint16_t tim7_cnt = TIM7->CNT;
uint32_t hisr = DMA2->HISR;

const int len_2 = DMA_IO_RX_SIZE / 2;
const unsigned int len_2 = DMA_IO_RX_SIZE / 2;
const uint8_t mask = ~dma_tx_ws2812_bits;

if (hisr & DMA_HISR_HTIF7) {
Expand Down
6 changes: 3 additions & 3 deletions Source/dma_io_servo_in.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void edge(uint32_t t, int ch, int rising)
}


void dma_io_decode_servo(const void *dma_buf, int dma_len, uint8_t mask)
void dma_io_decode_servo(const void *dma_buf, unsigned int dma_len, uint8_t mask)
{
// TODO: filter edges
// TODO: detect timeouts
Expand All @@ -31,12 +31,12 @@ void dma_io_decode_servo(const void *dma_buf, int dma_len, uint8_t mask)
const uint32_t *src = dma_buf;
uint32_t mask32 = (mask<<24) | (mask<<16) | (mask<<8) | mask;

for (int i=0; i < dma_len / 4; i++) {
for (unsigned int i=0; i < dma_len / 4; i++) {
uint32_t state = *src++ & mask32;
uint32_t diff = last_state ^ state;

if (diff) {
for (int j=0; j<32; j++) {
for (unsigned int j=0; j<32; j++) {
if (diff & (1UL << j))
edge(t + (j>>3), j & 7, state & (1UL << j));
}
Expand Down
3 changes: 1 addition & 2 deletions Source/dma_io_servo_in.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ extern struct dma_io_servo_in dma_io_servo_in[8];


void dma_io_decode_servo(
const void *dma_buf, int dma_len, uint8_t mask
const void *dma_buf, unsigned int dma_len, uint8_t mask

);

3 changes: 1 addition & 2 deletions Source/dma_io_servo_out.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <stdint.h>

void dma_io_set_servo(
void *dma_buf, int dma_len, uint8_t mask,
void *dma_buf, unsigned int dma_len, uint8_t mask,
int t_pulse
);

2 changes: 1 addition & 1 deletion Source/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void avg_reset(struct avg_filter *f, int32_t x)
{
f->index = 0;
f->acc = x * f->size;
for (int i=0; i<f->size; i++)
for (uint32_t i=0; i<f->size; i++)
f->buf[i] = x;
}

Loading