Skip to content
Snippets Groups Projects
Unverified Commit e7a2ea0a authored by Jake Drahos's avatar Jake Drahos
Browse files

Added frontend_setpid

parent f8cbdaa4
No related branches found
No related tags found
No related merge requests found
#include <err.h>
#include <stdio.h>
#include "frontend_setpid.h"
#include "pid_common.h"
#include "frontend_common.h"
int frontend_setpid(
struct backend_conn * conn,
struct frontend_pid_data * pid_data,
int mask)
{
if (conn == NULL) {
return -1;
}
char * controller;
switch (pid_data->controller) {
case PID_PITCH:
controller = "pitch";
break;
case PID_ROLL:
controller = "roll";
break;
case PID_YAW:
controller = "yaw";
break;
/* What is the "throttle" pid constant? */
default:
warnx("Unsupported PID variable");
return -1;
}
char buffer[2048];
/* Set the P, I, and D */
if (mask & SET_P) {
if (snprintf(buffer, 2048,
"set%sp %f\n",
controller,
pid_data->p) >= 2048) {
errx(0, "Buffer to small to format!");
}
ucart_backendWrite(conn, buffer);
}
if (mask & SET_I) {
if (snprintf(buffer, 2048,
"set%si %f\n",
controller,
pid_data->i) >= 2048) {
errx(0, "Buffer to small to format!");
}
ucart_backendWrite(conn, buffer);
}
if (mask & SET_D) {
if (snprintf(buffer, 2048,
"set%sd %f\n",
controller,
pid_data->d) >= 2048) {
errx(0, "Buffer to small to format!");
}
ucart_backendWrite(conn, buffer);
}
return 0;
}
#ifndef _FRONTEND_SETPID_H
#define _FRONTEND_SETPID_H
#include "pid_common.h"
#include "frontend_common.h"
int frontend_setpid(
struct backend_conn * conn,
struct frontend_pid_data * pid_data,
int mask);
#define SET_P 0x01
#define SET_I 0x02
#define SET_D 0x04
#define SET_ALL (SET_P | SET_I | SET_D)
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment