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

Read sensor data #1

Merged
merged 10 commits into from
Feb 25, 2024
10 changes: 8 additions & 2 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "../../MSB/api/msb_main.h"
#include "../../MSB/api/monitor_msb.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -110,8 +111,11 @@ int main(void)
MX_FDCAN1_Init();
MX_I2C3_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */

/* USER CODE BEGIN 2 */
msb_temp_t *temp_data;
msb_knuckle_t *knuckle_data;
msb_central_t *central_data;
evanlombardo marked this conversation as resolved.
Show resolved Hide resolved
/* USER CODE END 2 */

/* Init scheduler */
Expand All @@ -138,7 +142,9 @@ int main(void)
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);

/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
osThreadId_t tempThread = osThreadNew(monitor_temp_msb, temp_data, NULL);
osThreadId_t imuThread = osThreadNew(monitor_knuckle_msb, knuckle_data, NULL);
osThreadId_t centralThread = osThreadNew(monitor_central_msb, central_data, NULL);
/* USER CODE END RTOS_THREADS */

/* USER CODE BEGIN RTOS_EVENTS */
Expand Down
12 changes: 12 additions & 0 deletions MSB/api/monitor_msb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef READ_MSB_DATA
#define READ_MSB_DATA

#include "msb_temp.h"
#include "msb_knuckle.h"
#include "msb_central.h"

void monitor_temp_msb(void* arg);
void monitor_knuckle_msb(void* arg);
void monitor_central_msb(void* arg);

#endif
15 changes: 11 additions & 4 deletions MSB/api/msb_central.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
#ifndef MSB_CENTRAL_H
#define MSB_CENTRAL_H

#include "api/msb_common.h"
#include "msb_common.h"

typedef struct msb_central {
const short id;
} msb_central_t;

void monitor_strain_gauge(msb_central_t* msb);
void monitor_potentiometer(msb_central_t* msb);
void monitor_tof(msb_central_t* msb);
typedef struct central_data {
const int strain;
const int potentiometer;
const int tof;
} central_data_t;


int measure_strain_gauge(central_data_t* out);
int measure_potentiometer(central_data_t* out);
int measure_tof(central_data_t* out);

#endif
11 changes: 9 additions & 2 deletions MSB/api/msb_knuckle.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
#ifndef MSB_KNUCKLE_H
#define MSB_KNUCKLE_H

#include "api/msb_common.h"
#include "msb_common.h"

typedef struct msb_knuckle {
const short id;
} msb_knuckle_t;

void monitor_imu(msb_knuckle_t* msb);
typedef struct msb_data {
int acceleration;
int x_angle;
int y_angle;
int z_angle;
} knuckle_data_t;

int measure_imu(knuckle_data_t* out);

#endif
10 changes: 8 additions & 2 deletions MSB/api/msb_temp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
#ifndef MSB_TEMP_H
#define MSB_TEMP_H

#include "api/msb_common.h"
#include "msb_common.h"

typedef struct msb_temp {
const short id;
} msb_temp_t;

void monitor_temp(msb_temp_t* msb);
typedef struct temp_data {
int data;
char unit;
} temp_data_t;

int measure_temp(temp_data_t* out);

#endif

24 changes: 24 additions & 0 deletions MSB/measure_msb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#include "api/msb_central.h"
#include "api/msb_knuckle.h"
#include "api/msb_temp.h"

int measure_strain_gauge(central_data_t* out) {
return 0; // TODO
}

int measure_potentiometer(central_data_t* out) {
return 0; // TODO
}

int measure_tof(central_data_t* out) {
return 0; // TODO
}

int measure_imu(knuckle_data_t* out) {
return 0; // TODO
}

int measure_temp(temp_data_t* out) {
return 0; // TODO
}
71 changes: 71 additions & 0 deletions MSB/monitor_msb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "cmsis_os.h"
#include <stdio.h>
#include <stdlib.h>

#include "api/monitor_msb.h"

void monitor_temp_msb(void* arg) {

msb_temp_t* msb = (msb_temp_t*) arg;

temp_data_t* out = malloc(sizeof(temp_data_t));

char status[100];
for (;;) {
int ret = measure_temp(out);
if (ret) {
return; //handle error
}
sprintf(status, "{\"id\": %d, \"data\": %d, \"unit\": \"%c\"}", msb->id, out->data, out->unit);
push_can_queue(status);
osDelay(500);
}
}

void monitor_knuckle_msb(void* arg) {

msb_knuckle_t* msb = (msb_knuckle_t*) arg;

knuckle_data_t* out = malloc(sizeof(knuckle_data_t));

char status[100];
for (;;) {
int ret = measure_imu(out);
if (ret) {
return; // handle error
}
sprintf(status, "{\"id\": %d, \"acceleration\": %d, \"x_angle\": %d, \"y-angle\": %d, \"z-angle\": %d}",
msb->id, out->acceleration, out->x_angle, out->y_angle, out->z_angle);
push_can_queue(status);
osDelay(500);
}
}

void monitor_central_msb(void* arg) {

msb_central_t* msb = (msb_central_t*) arg;

central_data_t* out = malloc(sizeof(msb_central_t));

char status[100];
for (;;) {
int potentiometer_ret = measure_potentiometer(out);
int strain_ret = measure_strain_gauge(out);
int tof_ret = measure_tof(out);
if (potentiometer_ret) {
return; //handle error
}
if (strain_ret) {
return; //handle error
}
if (tof_ret) {
return; //handle error
}
sprintf(status, "{\"id\": %d, \"potentiometer\": %d, \"strain\": %d, \"ToF\": %d}",
msb->id, out->potentiometer, out->strain, out->tof);
push_can_queue(status);
osDelay(500);
}
evanlombardo marked this conversation as resolved.
Show resolved Hide resolved
}


4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \
Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \
Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c \
MSB/msb_main.c \
MSB/msb_can.c
MSB/msb_can.c \
MSB/monitor_msb.c \
MSB/measure_msb.c

# ASM sources
ASM_SOURCES = \
Expand Down
Loading