aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2014-12-07 13:59:50 +0100
committerJakob Odersky <jodersky@gmail.com>2014-12-07 13:59:50 +0100
commit99cb784ba8d2af17a4920bd37fd1c781aae73141 (patch)
tree7177f65a09427a765efb99d63027ac852f916ccf
parentfe210f522d7a7e69419fb1a9ffdb946455fc7bc3 (diff)
downloadmaverick-99cb784ba8d2af17a4920bd37fd1c781aae73141.tar.gz
maverick-99cb784ba8d2af17a4920bd37fd1c781aae73141.tar.bz2
maverick-99cb784ba8d2af17a4920bd37fd1c781aae73141.zip
cleanup
-rw-r--r--Makefile2
-rw-r--r--src/generic.c41
-rw-r--r--src/include/controller.h (renamed from include/controller.h)0
-rw-r--r--src/main.c13
4 files changed, 30 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index 6e19cc3..c532dd3 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,7 @@ LDFLAGS=-O2
SOURCEDIRS=src
INCLUDEDIRS=\
- include\
+ src/include\
ext/mavlink/include
SOURCES=$(foreach dir,$(SOURCEDIRS),$(wildcard $(dir)/*.c))
diff --git a/src/generic.c b/src/generic.c
index bf01e79..f81d86a 100644
--- a/src/generic.c
+++ b/src/generic.c
@@ -2,16 +2,24 @@
#include <stdio.h>
#define CHANNEL_THROTTLE 0
+#define CHANNEL_ATTITUDE_OFFSET 1
-#define THROTTLE_MIN 1000
+#define THROTTLE_MIN 500
#define THROTTLE_MAX 2000
+#define THROTTLE_STEP_SMALL 10
+#define THROTTLE_STEP_LARGE 100
-//convert the value from an axis to an appropriate ppm value
-//between 1000 and 2000
-inline channel_t axis_to_channel(int value) {
+#define ATTITUDE_MIN 1000
+#define ATTITUDE_MAX 2000
+
+/*
+ * convert the value from an axis to an appropriate ppm value
+ * between 1000 and 2000
+ */
+inline channel_t axis_to_attitude(int value) {
long centered = (long) value - AXIS_MIN;
- long proportional = centered * 1000 / (AXIS_MAX - AXIS_MIN);
- return (channel_t) 1000 + proportional;
+ long proportional = centered * ATTITUDE_MIN / (AXIS_MAX - AXIS_MIN);
+ return (channel_t) ATTITUDE_MAX - ATTITUDE_MIN + proportional;
}
void channel_reset(channel_t* channels) {
@@ -19,14 +27,16 @@ void channel_reset(channel_t* channels) {
channels[i] = CHANNEL_UNUSED;
}
channels[0] = THROTTLE_MIN;
- channels[1] = 1500;
- channels[2] = 1500;
- channels[3] = 1500;
- channels[4] = 1500;
+ channels[1] = ATTITUDE_MIN;
+ channels[2] = ATTITUDE_MIN;
+ channels[3] = ATTITUDE_MIN;
+ channels[4] = ATTITUDE_MIN;
}
+
void event_axis(channel_t* channels, int axis, int value) {
- channels[axis+1] = axis_to_channel(value);
+ channels[CHANNEL_ATTITUDE_OFFSET+axis] = axis_to_attitude(value);
}
+
void event_button(channel_t* channels, int button, bool value) {
if (value) {
switch(button) {
@@ -34,18 +44,19 @@ void event_button(channel_t* channels, int button, bool value) {
channel_reset(channels);
break;
case 4:
- channel_step(channels, CHANNEL_THROTTLE, -10, THROTTLE_MIN, THROTTLE_MAX);
+ channel_step(channels, CHANNEL_THROTTLE, -THROTTLE_STEP_SMALL, THROTTLE_MIN, THROTTLE_MAX);
break;
case 5:
- channel_step(channels, CHANNEL_THROTTLE, 10, THROTTLE_MIN, THROTTLE_MAX);
+ channel_step(channels, CHANNEL_THROTTLE, THROTTLE_STEP_SMALL, THROTTLE_MIN, THROTTLE_MAX);
break;
case 6:
- channel_step(channels, CHANNEL_THROTTLE, -100, THROTTLE_MIN, THROTTLE_MAX);
+ channel_step(channels, CHANNEL_THROTTLE, -THROTTLE_STEP_LARGE, THROTTLE_MIN, THROTTLE_MAX);
break;
case 7:
- channel_step(channels, CHANNEL_THROTTLE, 100, THROTTLE_MIN, THROTTLE_MAX);
+ channel_step(channels, CHANNEL_THROTTLE, THROTTLE_STEP_LARGE, THROTTLE_MIN, THROTTLE_MAX);
break;
default:
+ printf("button unsupported %d\n", button);
break;
}
}
diff --git a/include/controller.h b/src/include/controller.h
index a74d035..a74d035 100644
--- a/include/controller.h
+++ b/src/include/controller.h
diff --git a/src/main.c b/src/main.c
index 6b281cf..7514645 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,7 +28,7 @@ static void mav_out(uint8_t system_id, uint8_t component_id, uint8_t rsystem_id,
int main(int argc, char *argv[]) {
- //initialize joystick libraryz
+ //initialize joystick library
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0) {
fprintf(stderr, "Couldn't initialize SDL joystick subsystem: %s\n", SDL_GetError());
exit(1);
@@ -126,7 +126,8 @@ static void mav_out(uint8_t system_id, uint8_t component_id, uint8_t rsystem_id,
uint8_t buf[MAVLINK_MAX_PACKET_LEN];
mavlink_msg_rc_channels_override_pack(
- system_id, component_id,
+ system_id,
+ component_id,
&msg,
rsystem_id,
MAV_COMP_ID_ALL,
@@ -152,12 +153,4 @@ static void mav_out(uint8_t system_id, uint8_t component_id, uint8_t rsystem_id,
fprintf(stderr, "channel %zu: \t\t%u\n", i, channels[i]);
}
fprintf(stderr, "\n");
-
-
- /*
- mavlink_msg_rc_channels_override_pack(ALL)
- fprintf(stdout, "%u\n", channels[0]);
- fprintf(stderr, "channel 0: %u\n", channels[0]);
- fflush(stdout);
- fflush(stderr);*/
} \ No newline at end of file