Generic RC_UP message for datalink RC (#3332)

This commit is contained in:
Tomaso Maria Luigi De Ponti
2024-07-31 10:19:00 +02:00
committed by GitHub
parent 7f13148139
commit ba6daccdc8
42 changed files with 167 additions and 965 deletions

1
.gitignore vendored
View File

@@ -140,7 +140,6 @@ Cargo.lock
/sw/logalizer/gtk_export.ml
/sw/logalizer/sd2log
/sw/logalizer/plotprofile
/sw/logalizer/ctrlstick
/sw/logalizer/ffjoystick
/sw/logalizer/tmclient
/sw/logalizer/openlog2tlm

View File

@@ -51,8 +51,8 @@
<!--Not dealing with these in the simulation-->
<define name="RADIO_TH_HOLD" value="0"/> <!-- Throttle hold in command laws -->
<define name="RADIO_FMODE" value="0"/> <!-- Throttle curve select -->
<define name="RADIO_FBW_MODE" value="0"/> <!-- Switch between AP and FBW control -->
<define name="RADIO_KILL_SWITCH" value="0"/>
<define name="RADIO_FBW_MODE" value="RADIO_AUX7"/> <!-- Switch between AP and FBW control -->
<define name="RADIO_KILL_SWITCH" value="RADIO_AUX1"/>
<define name="RADIO_CONTROL_THRUST_X" value="0"/>
<define name="PREFLIGHT_CHECK_BYPASS" value="TRUE"/>

View File

@@ -8,12 +8,8 @@
</input>
<messages period="0.025">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="Fit(mode,-108,108,0,2)"/>
<field name="throttle" value="Fit(throttle,-117,117,0,127)" />
<field name="roll" value="-roll" />
<field name="yaw" value="Fit(-yaw,-105,105,-127,127)" />
<field name="pitch" value="-pitch" />
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="-roll;-pitch;Fit(-yaw,-105,105,-127,127);Fit(throttle,-117,117,0,127);Fit(mode,-108,108,0,2)"/>
</message>
</messages>
</joystick>

View File

@@ -26,12 +26,8 @@
</variables>
<messages period="0.025">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode" />
<field name="throttle" value="127-Scale(throttle,0,128)" />
<field name="roll" value="roll" />
<field name="yaw" value="yaw" />
<field name="pitch" value="pitch" />
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="roll;pitch;yaw;127-Scale(throttle,0,128);mode"/>
</message>
</messages>

View File

@@ -9,14 +9,8 @@
</input>
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode + 1"/> <!-- only AUTO1 and AUTO2 available -->
<field name="throttle" value="Fit(throttle,-100,100,0,127)"/>
<field name="roll" value="Fit(-roll,-100,100,-127,127)"/>
<field name="pitch" value="Fit(pitch,-100,100,-127,127)"/>
<field name="yaw" value="Fit(yaw,-100,100,-127,127)"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="Fit(-roll,-100,100,-127,127);Fit(pitch,-100,100,-127,127);Fit(yaw,-100,100,-127,127);Fit(throttle,-100,100,0,127);mode + 1"/>
</message>
</messages>
</joystick>

View File

@@ -11,12 +11,9 @@
</input>
<messages period="0.025">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="throttle" value="127-Fit(throttle, -93, 107, 0, 127)" />
<field name="roll" value="127-Fit(roll, -75, 108, 0, 127)" />
<field name="yaw" value="yaw" />
<field name="pitch" value="pitch" />
</message>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="127-Fit(roll, -75, 108, 0, 127);pitch;yaw;127-Fit(throttle, -93, 107, 0, 127)"/>
</message>
</messages>
</joystick>

View File

@@ -11,12 +11,8 @@
</input>
<messages period="0.025">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="throttle" value="Fit(throttle,-120,120,0,127)" />
<field name="roll" value="Fit(-roll,-100,100,-127,127)" />
<field name="yaw" value="Fit(-yaw,-100,100,-127,127)" />
<field name="pitch" value="Fit(-pitch,-100,100,-127,127)" />
<field name="mode" value="Fit(dummy, -100, 100, 0, 127)" />
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="Fit(-roll,-100,100,-127,127);Fit(-pitch,-100,100,-127,127);Fit(-yaw,-100,100,-127,127);Fit(throttle,-120,120,0,127);Fit(dummy, -100, 100, 0, 127)"/>
</message>
</messages>

View File

@@ -26,12 +26,8 @@
</variables>
<messages period="0.025">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode" />
<field name="throttle" value="127-Scale(throttle,0,128)" />
<field name="roll" value="roll" />
<field name="yaw" value="yaw" />
<field name="pitch" value="pitch" />
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="roll;pitch;yaw;127-Scale(throttle,0,128);mode"/>
</message>
</messages>

View File

@@ -14,13 +14,8 @@ More extensive guide: https://bit.ly/3KbSugO
</input>
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<!-- The controller is sending from -97 to 97 so we have to scale to 127 -->
<field name="throttle" value="Fit(LeftStickVertical,-97,97,0,127)"/>
<field name="roll" value="Fit(RightStickHorizontal,-97,97,-127,127)"/>
<field name="pitch" value="-Fit(RightStickVertical,-97,97,-127,127)"/>
<field name="yaw" value="Fit(LeftStickHorizontal,-97,97,-127,127)"/>
<field name="mode" value="1*SWA"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="Fit(RightStickHorizontal,-97,97,-127,127);-Fit(RightStickVertical,-97,97,-127,127);Fit(LeftStickHorizontal,-97,97,-127,127);Fit(LeftStickVertical,-97,97,0,127);1*SWA"/>
</message>
</messages>

View File

@@ -29,12 +29,8 @@ The basis of steering is the standard signs of aerospace convention
</input>
<messages period="0.0333333">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="throttle" value="Fit(throttle,-127,127,0,127)" />
<field name="roll" value="roll" />
<field name="pitch" value="-pitch" />
<field name="yaw" value="yaw"/>
<field name="mode" value="Fit(mode,-127,126,0,2)"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="roll;-pitch;yaw;Fit(throttle,-127,127,0,127);Fit(mode,-127,126,0,2)"/>
</message>
<message class="ground" name="DL_SETTING" on_event="arm">
<field name="index" value="IndexOfSetting('autopilot.kill_throttle')"/>

View File

@@ -29,12 +29,8 @@ The basis of steering is the standard signs of aerospace convention
</input>
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="throttle" value="Fit(throttle,-127,127,0,127)" />
<field name="roll" value="roll" />
<field name="pitch" value="-pitch" />
<field name="yaw" value="yaw"/>
<field name="mode" value="Fit(mode,-127,126,0,2)"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="roll;-pitch;yaw;Fit(throttle,-127,127,0,127);Fit(mode,-127,126,0,2)"/>
</message>
</messages>
</joystick>

View File

@@ -8,12 +8,8 @@
</input>
<messages period="0.025">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="Fit(mode,-108,108,0,2)"/>
<field name="throttle" value="Fit(throttle,-117,117,0,127)" />
<field name="roll" value="-roll" />
<field name="yaw" value="Fit(-yaw,-105,105,-127,127)" />
<field name="pitch" value="-pitch" />
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="-roll;-pitch;Fit(-yaw,-105,105,-127,127);Fit(throttle,-117,117,0,127);Fit(mode,-108,108,0,2)"/>
</message>
</messages>
</joystick>

View File

@@ -8,14 +8,8 @@
</input>
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode + 1"/> <!-- only AUTO1 and AUTO2 available -->
<field name="throttle" value="Fit(-throttle,-75,75,0,127)"/>
<field name="roll" value="Fit(-roll,-90,90,-127,127)"/>
<field name="pitch" value="Fit(pitch,-90,90,-127,127)"/>
<field name="yaw" value="Fit(yaw,-90,90,-127,127)"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="Fit(-roll,-90,90,-127,127);Fit(pitch,-90,90,-127,127);Fit(yaw,-90,90,-127,127);Fit(-throttle,-75,75,0,127);mode + 1"/>
</message>
</messages>
</joystick>

View File

@@ -39,12 +39,8 @@ The basis of steering is the standard signs of aerospace convention
</input>
<messages period="0.0333333">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="throttle" value="Fit(-throttle,-124,126,0,127)" />
<field name="roll" value="roll" />
<field name="pitch" value="pitch" />
<field name="yaw" value="Fit(yaw,-125,125,-127,127)"/>
<field name="mode" value="Fit(mode,-127,126,0,2)"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="roll;pitch;Fit(yaw,-125,125,-127,127);Fit(-throttle,-124,126,0,127);Fit(mode,-127,126,0,2)"/>
</message>
</messages>
</joystick>

View File

@@ -7,14 +7,8 @@
</input>
<messages period="0.1">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="PprzMode(0-mode)"/>
<field name="throttle" value="127-throttle"/>
<field name="roll" value="roll"/>
<field name="pitch" value="pitch"/>
<field name="yaw" value="0"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="roll;pitch;0;127-throttle;PprzMode(0-mode)"/>
</message>
</messages>
</joystick>

View File

@@ -37,12 +37,8 @@ The "mode" button swaps the axes on the left stick and the d pad.
<messages period="0.017">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="throttle" value="Scale(0-ly,0,255)"/>
<field name="roll" value="rx"/>
<field name="yaw" value="lx"/>
<field name="pitch" value="ry"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="rx;ry;lx;Scale(0-ly,0,255)"/>
</message>

View File

@@ -60,12 +60,8 @@ The "mode" button swaps the axes on the left stick and the d pad.
<messages period="0.017">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode"/>
<field name="throttle" value="Fit(0-ry,-127,127,0,127)"/>
<field name="roll" value="rx"/>
<field name="yaw" value="Fit(lx,-127,127,-64,64)"/>
<field name="pitch" value="ly"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="rx;ly;Fit(lx,-127,127,-64,64);Fit(0-ry,-127,127,0,127);mode"/>
</message>
<!-- trim commands -->

View File

@@ -60,12 +60,8 @@ The "mode" button swaps the axes on the left stick and the d pad.
<messages period="0.017">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode"/>
<field name="throttle" value="Fit(0-ly,-127,127,0,127)"/>
<field name="roll" value="rx"/>
<field name="yaw" value="Fit(lx,-127,127,-64,64)"/>
<field name="pitch" value="ry"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="rx;ry;Fit(lx,-127,127,-64,64);Fit(0-ly,-127,127,0,127);mode"/>
</message>
<!-- trim commands -->

View File

@@ -57,12 +57,8 @@ It has 8 buttons.
<messages period="0.0333333333">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode"/>
<field name="throttle" value="Bound(0-ly,0,127)"/>
<field name="roll" value="rx"/>
<field name="yaw" value="lx"/>
<field name="pitch" value="ry"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="rx;ry;lx;Bound(0-ly,0,127);mode"/>
</message>

View File

@@ -51,12 +51,8 @@ so e.g. HatDown(hat)
<messages period="0.1">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode"/>
<field name="throttle" value="Fit(-throttle,-127,127,0,127)"/>
<field name="roll" value="roll"/>
<field name="pitch" value="pitch"/>
<field name="yaw" value="yaw"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="roll;pitch;yaw;Fit(-throttle,-127,127,0,127);mode"/>
</message>
<!-- go to "Start Engine" block if in AUTO2 and pressing shift + fire2 -->

View File

@@ -14,13 +14,9 @@ thomaspfeifer.net PPM2USB joystick adapter with Futaba transmitter
<axis index="5" name="kill"/>
</input>
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="PprzMode(mode)"/>
<field name="throttle" value="Fit(throttle,-100,100,0,127)" />
<field name="roll" value="Fit(-roll,-100,100,-127,127)" />
<field name="pitch" value="Fit(pitch,-100,100,-127,127)" />
<field name="yaw" value="Fit(yaw,-100,100,-127,127)"/>
<messages period="0.05">
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="Fit(-roll,-100,100,-127,127);Fit(pitch,-100,100,-127,127);Fit(yaw,-100,100,-127,127);Fit(throttle,-100,100,0,127);PprzMode(mode)"/>
</message>
</messages>
</joystick>

View File

@@ -65,12 +65,8 @@
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode"/>
<field name="throttle" value="Fit(-LeftStickVertical,-127,127,0,127)"/>
<field name="roll" value="RightStickHorizontal"/>
<field name="pitch" value="RightStickVertical"/>
<field name="yaw" value="LeftStickHorizontal"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="RightStickHorizontal;RightStickVertical;LeftStickHorizontal;Fit(-LeftStickVertical,-127,127,0,127);mode"/>
</message>
<!-- go to "Start Engine" block if in AUTO2 and pressing Options button -->

View File

@@ -65,12 +65,8 @@
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode"/>
<field name="throttle" value="Fit(-LeftStickVertical,-127,127,0,127)"/>
<field name="roll" value="RightStickHorizontal"/>
<field name="pitch" value="RightStickVertical"/>
<field name="yaw" value="Fit(R2-L2,-127,127,-127,127)"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="RightStickHorizontal;RightStickVertical;Fit(R2-L2,-127,127,-127,127);Fit(-LeftStickVertical,-127,127,0,127);mode"/>
</message>
<!-- go to "Start Engine" block if in AUTO2 and pressing Options button -->

View File

@@ -28,19 +28,13 @@ The basis of steering is the standard signs of aerospace convention
<axis index="2" name="RightStickVertical"/>
<axis index="4" name="VRA"/>
<axis index="5" name="arm"/>
<axis index="6" name="yellow"/>
</input>
<!-- Follow the order of rc_datalink.h -->
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="throttle" value="Fit(LeftStickVertical,-127,127,0,127)"/>
<field name="roll" value="RightStickHorizontal"/>
<field name="pitch" value="RightStickVertical"/>
<field name="yaw" value="LeftStickHorizontal"/>
<field name="mode" value="Fit(VRA,-108,108,0,2)"/>
</message>
<message class="ground" name="DL_SETTING" on_event="arm">
<field name="index" value="IndexOfSetting('autopilot.kill_throttle')"/>
<field name="value" value="Fit(-arm,-127,126,0,1)"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="RightStickHorizontal;RightStickVertical;LeftStickHorizontal;Fit(LeftStickVertical,-127,127,0,127);VRA;arm;yellow"/>
</message>
</messages>

View File

@@ -35,12 +35,8 @@ The basis of steering is the standard signs of aerospace convention
</input>
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="throttle" value="Fit(LeftStickVertical,0,127,0,127)"/>
<field name="roll" value="RightStickHorizontal"/>
<field name="pitch" value="-RightStickVertical"/>
<field name="yaw" value="LeftStickHorizontal"/>
<field name="mode" value="2-2*VRA"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="RightStickHorizontal;-RightStickVertical;LeftStickHorizontal;Fit(LeftStickVertical,0,127,0,127);2-2*VRA"/>
</message>
</messages>

View File

@@ -38,12 +38,8 @@ The basis of steering is the standard signs of aerospace convention
</input>
<messages period="0.0333333">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="throttle" value="Fit(throttle,-127,127,0,127)" />
<field name="roll" value="Fit(roll,-125,125,-127,127)" />
<field name="pitch" value="Fit(-pitch,-127,127,-127,127)" />
<field name="yaw" value="Fit(yaw,-127,127,-127,127)"/>
<field name="mode" value="Fit(mode,-126,126,0,127)"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="Fit(roll,-125,125,-127,127);Fit(-pitch,-127,127,-127,127);Fit(yaw,-127,127,-127,127);Fit(throttle,-127,127,0,127);Fit(mode,-126,126,0,127)"/>
</message>
</messages>
</joystick>

View File

@@ -64,12 +64,8 @@ so e.g. HatDown(dpad)
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode"/>
<field name="throttle" value="Fit(-throttle,-127,127,0,127)"/>
<field name="roll" value="roll"/>
<field name="pitch" value="pitch"/>
<field name="yaw" value="yaw"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="roll;pitch;yaw;Fit(-throttle,-127,127,0,127);mode"/>
</message>
<!-- go to "Start Engine" block if in AUTO2 and pressing start button -->

View File

@@ -64,12 +64,8 @@ so e.g. HatDown(dpad)
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode"/>
<field name="throttle" value="Fit(-throttle,-127,127,0,127)"/>
<field name="roll" value="roll"/>
<field name="pitch" value="pitch"/>
<field name="yaw" value="yaw"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="roll;pitch;yaw;Fit(-throttle,-127,127,0,127);mode"/>
</message>
<!-- go to "Start Engine" block if in AUTO2 and pressing start button -->

View File

@@ -68,12 +68,8 @@ so e.g. HatDown(dpad)
<messages period="0.05">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode"/>
<field name="throttle" value="Fit(-throttle,-127,127,0,127)"/> <!--To trimm for Parot Bebop set 0 to 47-->
<field name="roll" value="roll"/>
<field name="pitch" value="pitch"/>
<field name="yaw" value="Fit(RT-LT,-127,127,-127,127)"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="roll;pitch;Fit(RT-LT,-127,127,-127,127);Fit(-throttle,-127,127,0,127);mode"/>
</message>
<!-- go to "Start Engine" block if in AUTO2 and pressing start button -->

View File

@@ -16,8 +16,7 @@
</header>
<init fun="rc_datalink_init()"/>
<event fun="rc_datalink_event()"/>
<datalink message="RC_3CH" fun="rc_datalink_parse_RC_3CH(buf)"/>
<datalink message="RC_4CH" fun="rc_datalink_parse_RC_4CH(buf)"/>
<datalink message="RC_UP" fun="rc_datalink_parse_RC_UP(buf)"/>
<makefile target="ap|fbw|sim|nps">
<configure name="RADIO_CONTROL_DATALINK_LED" default="none"/>
<define name="RADIO_CONTROL_DATALINK_LED" value="$(RADIO_CONTROL_DATALINK_LED)" cond="ifneq ($(RADIO_CONTROL_DATALINK_LED),none)"/>

View File

@@ -8,9 +8,9 @@
<channel function="MODE" min="1100" neutral="1500" max="1900" average="1"/>
<channel function="AUX1" min="1100" neutral="1500" max="1900" average="1"/> <!-- TH_HOLD -->
<channel function="AUX2" min="1100" neutral="1500" max="1900" average="1"/> <!-- FMODE -->
<channel function="AUX3" min="1100" neutral="1500" max="1900" average="1"/> <!-- FBW_MODE -->
<channel function="AUX4" min="1100" neutral="1100" max="1900" average="1"/> <!-- PUSHER/FLAPS -->
<channel function="AUX5" min="1100" neutral="1500" max="1900" average="1"/>
<channel function="AUX3" min="1100" neutral="1500" max="1900" average="1"/> <!-- AP_MODE_SWITCH -->
<channel function="AUX4" min="1100" neutral="1100" max="1900" average="1"/> <!-- Pusher-->
<channel function="AUX5" min="1100" neutral="1100" max="1900" average="1"/> <!-- Overactuation-->
<channel function="AUX6" min="1100" neutral="1500" max="1900" average="1"/>
<channel function="AUX7" min="1100" neutral="1500" max="1900" average="1"/>
</radio>

View File

@@ -65,15 +65,10 @@ Create a new file for your joystick in the ``paparazzi/conf/joystick`` directory
<messages period="0.01">
<message class="datalink" name="RC_4CH" send_always="true">
<field name="mode" value="mode"/>
<field name="throttle" value="Fit(-thrust,-127,127,0,127)"/>
<field name="roll" value="roll"/>
<field name="yaw" value="yaw"/>
<field name="pitch" value="pitch"/>
<message class="datalink" name="RC_UP" send_always="true">
<field name="channels" value="roll;pitch;yaw;Fit(-thrust,-127,127,0,127);mode">
</message>
<!-- resurrect throttle on fire button -->
<message class="ground" name="DL_SETTING" on_event="fire">
<field name="index" value="IndexOfSetting('autopilot.kill_throttle')"/>

View File

@@ -84,6 +84,12 @@ static inline bool rc_mode_switch(uint8_t chan, uint8_t pos, uint8_t max)
#define RCMode2() rc_mode_switch(RADIO_MODE, 2, 3)
#endif
#ifdef AP_MODE_SWITCH
#define RCAP0() rc_mode_switch(AP_MODE_SWITCH, 0, 3)
#define RCAP1() rc_mode_switch(AP_MODE_SWITCH, 1, 3)
#define RCAP2() rc_mode_switch(AP_MODE_SWITCH, 2, 3)
#endif
static inline bool rc_attitude_sticks_centered(void)
{
return ROLL_STICK_CENTERED() && PITCH_STICK_CENTERED() && YAW_STICK_CENTERED();

View File

@@ -250,7 +250,8 @@ void mavlink_common_message_handler(const mavlink_message_t *msg)
int8_t roll = -(cmd.chan1_raw - 1500) * 255 / 1100 / 2;
int8_t pitch = -(cmd.chan2_raw - 1500) * 255 / 1100 / 2;
int8_t yaw = -(cmd.chan4_raw - 1500) * 255 / 1100;
parse_rc_4ch_datalink(0, thrust, roll, pitch, yaw);
int8_t temp_rc[4] = {roll, pitch, yaw, thrust};
parse_rc_up_datalink(4, temp_rc);
//printf("RECEIVED: RC Channel Override for: %d/%d: throttle: %d; roll: %d; pitch: %d; yaw: %d;\r\n",
// cmd.target_system, cmd.target_component, thrust, roll, pitch, yaw);
#endif

View File

@@ -39,58 +39,22 @@ void rc_datalink_init(void)
rc_dl_frame_available = false;
}
void rc_datalink_parse_RC_3CH(uint8_t *buf)
void rc_datalink_parse_RC_UP(uint8_t *buf)
{
#ifdef RADIO_CONTROL_DATALINK_LED
LED_TOGGLE(RADIO_CONTROL_DATALINK_LED);
#endif
parse_rc_3ch_datalink(
DL_RC_3CH_throttle_mode(buf),
DL_RC_3CH_roll(buf),
DL_RC_3CH_pitch(buf));
parse_rc_up_datalink(DL_RC_UP_channels_length(buf),
DL_RC_UP_channels(buf));
}
void rc_datalink_parse_RC_4CH(uint8_t *buf)
void parse_rc_up_datalink(
int8_t n,
int8_t *channels)
{
#ifdef RADIO_CONTROL_DATALINK_LED
LED_TOGGLE(RADIO_CONTROL_DATALINK_LED);
#endif
parse_rc_4ch_datalink(DL_RC_4CH_mode(buf),
DL_RC_4CH_throttle(buf),
DL_RC_4CH_roll(buf),
DL_RC_4CH_pitch(buf),
DL_RC_4CH_yaw(buf));
}
void parse_rc_3ch_datalink(uint8_t throttle_mode,
int8_t roll,
int8_t pitch)
{
uint8_t throttle = ((throttle_mode & 0xFC) >> 2) * (128 / 64);
uint8_t mode = throttle_mode & 0x03;
rc_dl_values[RADIO_ROLL] = roll;
rc_dl_values[RADIO_PITCH] = pitch;
rc_dl_values[RADIO_THROTTLE] = (int8_t)throttle;
rc_dl_values[RADIO_MODE] = (int8_t)mode;
rc_dl_values[RADIO_YAW] = 0;
rc_dl_frame_available = true;
}
void parse_rc_4ch_datalink(
uint8_t mode,
uint8_t throttle,
int8_t roll,
int8_t pitch,
int8_t yaw)
{
rc_dl_values[RADIO_MODE] = (int8_t)mode;
rc_dl_values[RADIO_THROTTLE] = (int8_t)throttle;
rc_dl_values[RADIO_ROLL] = roll;
rc_dl_values[RADIO_PITCH] = pitch;
rc_dl_values[RADIO_YAW] = yaw;
for (int i = 0; i < n; i++) {
rc_dl_values[i] = channels[i];
}
rc_dl_frame_available = true;
}
@@ -99,16 +63,14 @@ void parse_rc_4ch_datalink(
*/
static void rc_datalink_normalize(int8_t *in, int16_t *out)
{
out[RADIO_ROLL] = (MAX_PPRZ / 128) * in[RADIO_ROLL];
Bound(out[RADIO_ROLL], MIN_PPRZ, MAX_PPRZ);
out[RADIO_PITCH] = (MAX_PPRZ / 128) * in[RADIO_PITCH];
Bound(out[RADIO_PITCH], MIN_PPRZ, MAX_PPRZ);
out[RADIO_YAW] = (MAX_PPRZ / 128) * in[RADIO_YAW];
Bound(out[RADIO_YAW], MIN_PPRZ, MAX_PPRZ);
out[RADIO_THROTTLE] = ((MAX_PPRZ / 128) * in[RADIO_THROTTLE]);
Bound(out[RADIO_THROTTLE], 0, MAX_PPRZ);
out[RADIO_MODE] = MAX_PPRZ * (in[RADIO_MODE] - 1);
Bound(out[RADIO_MODE], MIN_PPRZ, MAX_PPRZ);
for (int i = 0; i < RC_DL_NB_CHANNEL; i++) {
out[i] = (MAX_PPRZ / 128) * in[i];
if (i == RADIO_THROTTLE) {
Bound(out[i], 0, MAX_PPRZ);
} else {
Bound(out[i], MIN_PPRZ, MAX_PPRZ);
}
}
}
void rc_datalink_event(void)

View File

@@ -29,48 +29,42 @@
#include "std.h"
#define RC_DL_NB_CHANNEL 5
#define RC_DL_NB_CHANNEL 11
/**
* Redefining RADIO_*
* Do not use with radio.h (ppm rc)
*/
#define RADIO_ROLL 0
#define RADIO_PITCH 1
#define RADIO_YAW 2
#define RADIO_THROTTLE 3
#define RADIO_MODE 4
#define RADIO_AUX1 5
#define RADIO_AUX2 6
#define RADIO_AUX4 7
#define RADIO_AUX6 8
#define RADIO_AUX5 9
#define RADIO_ROLL 0 // Default: Roll
#define RADIO_PITCH 1 // Default: Pitch
#define RADIO_YAW 2 // Default: Yaw
#define RADIO_THROTTLE 3 // Default: Thrust
#define RADIO_MODE 4 // Default: MODE (MANUAL / AUTO)
#define RADIO_AUX1 5 // Default: KILL
#define RADIO_AUX2 7 // Default: NA
#define RADIO_AUX4 8 // Default: NA
#define RADIO_AUX5 9 // Default: NA
#define RADIO_AUX6 10 // Default: NA
#define RADIO_AUX7 6 // Default: AP_MODE (EXTRA MODE SWITCH: e.g Switch NAV from INDI to ANDI to PID)
extern int8_t rc_dl_values[ RC_DL_NB_CHANNEL ];
#ifndef RADIO_KILL_SWITCH
#define RADIO_KILL_SWITCH RADIO_AUX1
#endif
#ifndef AP_MODE_SWITCH
#define AP_MODE_SWITCH RADIO_AUX7
#endif
extern int8_t rc_dl_values[RC_DL_NB_CHANNEL];
extern volatile bool rc_dl_frame_available;
/**
* Decode datalink message to get rc values with RC_3CH message
* Mode and throttle are merge in the same byte
* Decode datalink message to get rc values with RC_UP message
*/
extern void parse_rc_3ch_datalink(
uint8_t throttle_mode,
int8_t roll,
int8_t pitch);
/**
* Decode datalink message to get rc values with RC_4CH message
*/
extern void parse_rc_4ch_datalink(
uint8_t mode,
uint8_t throttle,
int8_t roll,
int8_t pitch,
int8_t yaw);
extern void rc_datalink_parse_RC_3CH(uint8_t *buf);
extern void rc_datalink_parse_RC_4CH(uint8_t *buf);
extern void parse_rc_up_datalink(
int8_t n, int8_t *channels);
extern void rc_datalink_parse_RC_UP(uint8_t *buf);
/**
* RC init function.
*/
@@ -82,4 +76,3 @@ extern void rc_datalink_init(void);
extern void rc_datalink_event(void);
#endif /* RC_DATALINK_H */

View File

@@ -148,28 +148,14 @@ void dl_parse_msg(struct link_device *dev __attribute__((unused)), struct transp
}
break;
#ifdef RADIO_CONTROL_TYPE_DATALINK
case DL_RC_3CH :
case DL_RC_UP :
#ifdef RADIO_CONTROL_DATALINK_LED
LED_TOGGLE(RADIO_CONTROL_DATALINK_LED);
#endif
parse_rc_3ch_datalink(
DL_RC_3CH_throttle_mode(buf),
DL_RC_3CH_roll(buf),
DL_RC_3CH_pitch(buf));
break;
case DL_RC_4CH :
#ifdef RADIO_CONTROL_DATALINK_LED
LED_TOGGLE(RADIO_CONTROL_DATALINK_LED);
#endif
parse_rc_4ch_datalink(
DL_RC_4CH_mode(buf),
DL_RC_4CH_throttle(buf),
DL_RC_4CH_roll(buf),
DL_RC_4CH_pitch(buf),
DL_RC_4CH_yaw(buf));
parse_rc_up_datalink(DL_RC_UP_channels_length(buf),
DL_RC_UP_channels(buf));
break;
#endif // RADIO_CONTROL_TYPE_DATALINK
default:
break;
}

View File

@@ -88,7 +88,7 @@ type input =
type msg = {
msg_name : string;
msg_class : string;
fields : (string * PprzLink._type * Syntax.expression) list;
fields : (string * PprzLink._type * Syntax.expression list) list;
on_event : Syntax.expression option;
send_always : bool;
has_ac_id : bool
@@ -219,9 +219,15 @@ let parse_input = fun input ->
(name, value))
(Xml.children input)
(** Parse a 'à la C' expression *)
let parse_value = fun s ->
Fp_proc.parse_expression s
(** Parse a '<EFBFBD> la C' expression *)
let parse_value s =
let substrings = String.split_on_char ';' s in
let parsed_exprs = List.map (fun sub ->
let trimmed_sub = String.trim sub in
let parsed_expr = Fp_proc.parse_expression trimmed_sub in
parsed_expr
) substrings in
parsed_exprs
(** Parse a message field and eval *)
let parse_msg_field = fun msg_descr field ->
@@ -229,9 +235,9 @@ let parse_msg_field = fun msg_descr field ->
let field_descr = try List.assoc name msg_descr.PprzLink.fields with _ ->
Printf.printf "parse_msg_field: field %s not found\n" name;
raise (Failure "field not found") in
let value = eval_settings_and_blocks field_descr (parse_value (Xml.attrib field "value")) in
(name, field_descr.PprzLink._type, value)
let value = List.map (eval_settings_and_blocks field_descr) (parse_value (Xml.attrib field "value")) in
let field_type = field_descr.PprzLink._type in
(name, field_type, value)
(** Parse a complete message and build its representation *)
let parse_msg = fun msg ->
@@ -251,18 +257,22 @@ let parse_msg = fun msg ->
failwith (sprintf "Couldn't parse message %s (%s)" msg_name e)
end
| "Trim" -> ([], false)
| _ -> failwith ("Unknown message class type") in
let on_event =
try Some (parse_value (Xml.attrib msg "on_event")) with _ -> None in
{ msg_name = msg_name;
msg_class = msg_class;
fields = fields;
on_event = on_event;
send_always = send_always;
has_ac_id = has_ac_id
}
| _ -> failwith ("Unknown message class type") in
let on_event =
try
match parse_value (Xml.attrib msg "on_event") with
| [] -> None
| expr :: _ -> Some expr
with _ -> None
in
{ msg_name = msg_name;
msg_class = msg_class;
fields = fields;
on_event = on_event;
send_always = send_always;
has_ac_id = has_ac_id
}
(** Parse an XML list of variables and set function *)
let parse_variables = fun variables ->
@@ -278,11 +288,17 @@ let parse_variables = fun variables ->
(ExtXml.tag_is vs "set") &&
(compare (ExtXml.attrib_or_default vs "var" "") name) = 0)
(Xml.children variables) in
let var_event = List.map (fun s ->
let var_event = List.fold_left (fun acc s ->
let value = ExtXml.int_attrib s "value"
and on_event = parse_value (Xml.attrib s "on_event") in
(value, on_event)
) set in
and on_event =
match parse_value (Xml.attrib s "on_event") with
| [] -> None
| expr :: _ -> Some expr
in
match on_event with
| Some expr -> (value, expr) :: acc
| None -> acc
) [] set in
l := (name, { value = default; var_event = var_event; }) :: !l;
()
| _ -> ()
@@ -496,9 +512,13 @@ let update_variables = fun inputs buttons hat axis variables ->
let execute_action = fun ac_id inputs buttons hat axis variables message ->
let values =
List.map
(fun (name, _type, expr) ->
let v = eval_expr buttons hat axis inputs variables expr in
(name, PprzLink.value _type (sprintf "%d" v))
(fun (name, _type, expr_list) ->
let v = List.fold_left (fun acc expr ->
let eval_result = eval_expr buttons hat axis inputs variables expr in
acc @ [eval_result]
) [] expr_list in
let v_string = String.concat "," (List.map string_of_int v) in
(name, PprzLink.value _type v_string)
)
message.fields

View File

@@ -147,12 +147,8 @@ tmclient: tmclient.c
ffjoystick: ffjoystick.c
$(CC) -g -O2 -Wall $(GLIBIVY_CFLAGS) -o $@ $^ $(IVY_C_LIBS) -lm
ctrlstick: ctrlstick.c
$(CC) -g -O2 -Wall $(GLIBIVY_CFLAGS) -o $@ $^ $(IVY_C_LIBS)
clean:
$(Q)rm -f *.opt *.out *~ core *.o *.bak .depend *.cm* play ahrs2fg logplotter plotter gtk_export.ml openlog2tlm disp3d plotprofile tmclient ffjoystick ctrlstick sd2log sdlogger_download
$(Q)rm -f *.opt *.out *~ core *.o *.bak .depend *.cm* play ahrs2fg logplotter plotter gtk_export.ml openlog2tlm disp3d plotprofile tmclient ffjoystick sd2log sdlogger_download
.PHONY: all clean

View File

@@ -1,374 +0,0 @@
/*
* ctrlstick.c
*
* send joystick control to paparazzi through ivy
*
* based on Force Feedback: Constant Force Stress Test
* Copyright (C) 2001 Oliver Hamann
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define DBG 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <math.h>
#include <glib.h>
#include <linux/input.h>
#include <sys/ioctl.h>
#include <Ivy/ivy.h>
#include <Ivy/ivyglibloop.h>
#ifdef DBG
#define dbgprintf fprintf
#else
#define dbgprintf(x ...)
#endif
#define Bound(_x, _min, _max) { if (_x > _max) _x = _max; else if (_x < _min) _x = _min; }
#define TIMEOUT_PERIOD 20
#define MB_ID 1
#define INPUT_DEV_MAX 15
#define AXIS_COUNT 4
#if 0
// rumblepad 2
#define AXIS_YAW ABS_X
#define AXIS_PITCH ABS_Y
#define AXIS_ROLL ABS_Z
#define AXIS_THROTTLE ABS_RZ
#endif
#if 1
// e-sky 0905A simulator fms
//#define AXIS_YAW ABS_X
//#define AXIS_ROLL ABS_Z
//#define AXIS_THROTTLE ABS_RY
//#define AXIS_PITCH ABS_Y
#define AXIS_YAW ABS_RY
#define AXIS_ROLL ABS_Y
#define AXIS_THROTTLE ABS_X
#define AXIS_PITCH ABS_Z
#define THROTTLE_MIN (-90)
#define THROTTLE_NEUTRAL (0)
#define THROTTLE_MAX (90)
#define ROLL_MIN (-122)
#define ROLL_NEUTRAL (-13)
#define ROLL_MAX (113)
#define PITCH_MIN (-109)
#define PITCH_NEUTRAL (-2)
#define PITCH_MAX (109)
#define YAW_MIN (125)
#define YAW_NEUTRAL (-13
#define YAW_MAX (115)
#endif
#if 0
// wingman force 3d
#define AXIS_YAW ABS_RZ
#define AXIS_PITCH ABS_Y
#define AXIS_ROLL ABS_X
#define AXIS_THROTTLE ABS_THROTTLE
#endif
/* Helper for testing large bit masks */
#define TEST_BIT(bit,bits) (((bits[bit>>5]>>(bit&0x1f))&1)!=0)
/* Default values for the options */
#define DEVICE_NAME "/dev/input/event"
#define DEFAULT_DEVICE_NAME "/dev/input/event4"
#define DEFAULT_AC_ID 1
/* Options */
const char * device_name_default = DEFAULT_DEVICE_NAME;
int aircraft_id = DEFAULT_AC_ID;
/* Global variables about the initialized device */
int device_handle;
int axis_code[AXIS_COUNT] = {AXIS_ROLL, AXIS_PITCH, AXIS_THROTTLE, AXIS_YAW};
int axis_min[AXIS_COUNT], axis_max[AXIS_COUNT];
int position[AXIS_COUNT] = {0, 0, 0};
struct ff_effect effect;
GMainLoop *ml;
void parse_args(int argc, char * argv[])
{
/* nothing to do any more */
}
int init_hid_device(char* device_name)
{
int cnt;
unsigned long key_bits[32],abs_bits[32];
int valbuf[16];
char name[256] = "Unknown";
#ifdef USE_FORCE_FEEDBACK
unsigned long ff_bits[32];
struct input_event event;
#endif
/* Open event device read only (with write permission for ff) */
device_handle = open(device_name,O_RDONLY|O_NONBLOCK);
if (device_handle<0) {
dbgprintf(stderr,"ERROR: can not open %s (%s) [%s:%d]\n",
device_name,strerror(errno),__FILE__,__LINE__);
return(1);
}
/* Which buttons has the device? */
memset(key_bits,0,32*sizeof(unsigned long));
if (ioctl(device_handle,EVIOCGBIT(EV_KEY,32*sizeof(unsigned long)),key_bits)<0) {
dbgprintf(stderr,"ERROR: can not get key bits (%s) [%s:%d]\n",
strerror(errno),__FILE__,__LINE__);
close(device_handle);
return(1);
}
/* Which axes has the device? */
memset(abs_bits,0,32*sizeof(unsigned long));
if (ioctl(device_handle,EVIOCGBIT(EV_ABS,32*sizeof(unsigned long)),abs_bits)<0) {
dbgprintf(stderr,"ERROR: can not get abs bits (%s) [%s:%d]\n",
strerror(errno),__FILE__,__LINE__);
close(device_handle);
return(1);
}
#if 0
printf("0x%08lX\n",abs_bits[0]);
printf("0x%08lX\n",abs_bits[1]);
printf("0x%08lX\n",abs_bits[2]);
printf("0x%08lX\n",abs_bits[3]);
#endif
/* Which axis? */
if (!TEST_BIT(AXIS_YAW ,abs_bits)) {
dbgprintf(stderr,"ERROR: no suitable yaw axis found [%s:%d]\n",
__FILE__,__LINE__);
close(device_handle);
return(1);
}
if (!TEST_BIT(AXIS_PITCH ,abs_bits)) {
dbgprintf(stderr,"ERROR: no suitable pitch axis found [%s:%d]\n",
__FILE__,__LINE__);
close(device_handle);
return(1);
}
if (!TEST_BIT(AXIS_ROLL ,abs_bits)) {
dbgprintf(stderr,"ERROR: no suitable roll axis found [%s:%d]\n",
__FILE__,__LINE__);
close(device_handle);
return(1);
}
if (!TEST_BIT(AXIS_THROTTLE ,abs_bits)) {
dbgprintf(stderr,"ERROR: no suitable throttle axis found [%s:%d]\n",
__FILE__,__LINE__);
close(device_handle);
return(1);
}
for (cnt=0; cnt<AXIS_COUNT; cnt++)
{
/* get axis value range */
if (ioctl(device_handle,EVIOCGABS(axis_code[cnt]),valbuf)<0) {
dbgprintf(stderr,"ERROR: can not get axis value range (%s) [%s:%d]\n",
strerror(errno),__FILE__,__LINE__);
close(device_handle);
return(1);
}
axis_min[cnt]=valbuf[1];
axis_max[cnt]=valbuf[2];
if (axis_min[cnt]>=axis_max[cnt]) {
dbgprintf(stderr,"ERROR: bad axis value range (%d,%d) [%s:%d]\n",
axis_min[cnt],axis_max[cnt],__FILE__,__LINE__);
close(device_handle);
return(1);
}
/* get last data */
position[cnt]=(((valbuf[0])-axis_min[cnt]))*254/(axis_max[cnt]-axis_min[cnt])-127;
}
#if 0
/* Now get some information about force feedback */
memset(ff_bits,0,32*sizeof(unsigned long));
if (ioctl(device_handle,EVIOCGBIT(EV_FF ,32*sizeof(unsigned long)),ff_bits)<0) {
dbgprintf(stderr,"ERROR: can not get ff bits (%s) [%s:%d]\n",
strerror(errno),__FILE__,__LINE__);
close(device_handle);
return(1);
}
/* force feedback supported? */
if (!TEST_BIT(FF_CONSTANT,ff_bits)) {
dbgprintf(stderr,"ERROR: device (or driver) has no force feedback support [%s:%d]\n",
__FILE__,__LINE__);
close(device_handle);
return(1);
}
/* Switch off auto centering */
memset(&event,0,sizeof(event));
event.type=EV_FF;
event.code=FF_AUTOCENTER;
event.value=0;
if (write(device_handle,&event,sizeof(event))!=sizeof(event)) {
dbgprintf(stderr,"ERROR: failed to disable auto centering (%s) [%s:%d]\n",
strerror(errno),__FILE__,__LINE__);
close(device_handle);
return(1);
}
#endif
#ifdef USE_FORCE_FEEDBACK // turn on for ff effect
/* Initialize constant force effect */
memset(&effect,0,sizeof(effect));
effect.type=FF_CONSTANT;
effect.id=-1;
effect.trigger.button=0;
effect.trigger.interval=0;
effect.replay.length=0xffff;
effect.replay.delay=0;
effect.u.constant.level=0;
effect.direction=0xC000;
effect.u.constant.envelope.attack_length=0;
effect.u.constant.envelope.attack_level=0;
effect.u.constant.envelope.fade_length=0;
effect.u.constant.envelope.fade_level=0;
/* Upload effect */
if (ioctl(device_handle,EVIOCSFF,&effect)==-1) {
dbgprintf(stderr,"ERROR: uploading effect failed (%s) [%s:%d]\n",
strerror(errno),__FILE__,__LINE__);
close(device_handle);
return(1);
}
/* Start effect */
memset(&event,0,sizeof(event));
event.type=EV_FF;
event.code=effect.id;
event.value=1;
if (write(device_handle,&event,sizeof(event))!=sizeof(event)) {
dbgprintf(stderr,"ERROR: starting effect failed (%s) [%s:%d]\n",
strerror(errno),__FILE__,__LINE__);
close(device_handle);
return(1);
}
#endif
ioctl(device_handle, EVIOCGNAME(sizeof(name)), name);
printf("Input device name: \"%s\"\n", name);
return(0);
}
static gboolean joystick_periodic(gpointer data __attribute__ ((unused))) {
int res, cnt, changed = 0, mode=0;
int throttle, pitch, roll;
int throttle_mode;
struct input_event event;
static struct timeval time_now;
/* Get events */
do {
res = read(device_handle,&event,sizeof(event));
if (res == sizeof(event))
{
for (cnt=0; cnt<AXIS_COUNT; cnt++) {
if (event.type==EV_ABS && event.code==axis_code[cnt]) {
position[cnt]=(((event.value)-axis_min[cnt]))*254/(axis_max[cnt]-axis_min[cnt])-127;
changed = 1;
}
}
}
} while (res == sizeof(event));
if (errno != EAGAIN)
{
printf("device removed\n");
g_main_loop_quit(ml);
return 0;
}
// if (changed)
{
dbgprintf(stdout, "pos %d %d %d %d\n", position[0], position[1], position[2], position[3]);
if (position[3] > 125) mode = 2;
else if (position[3] < -125) mode = 1;
else mode = 0;
throttle = ((position[0] - THROTTLE_NEUTRAL -THROTTLE_MIN) * 63) / (THROTTLE_MAX-THROTTLE_MIN);
Bound(throttle, 0, 63)
roll = position[2] - ROLL_NEUTRAL;
Bound(roll, -128, 127)
pitch = position[1] - PITCH_NEUTRAL;
Bound(pitch, -128, 127)
throttle_mode = (throttle << 2) | mode;
gettimeofday(&time_now, 0);
// if (mode != 2)
{
dbgprintf(stdout,"mode: %d, throttle: %d, roll: %d, pitch: %d\n", throttle_mode & 3, throttle_mode >> 2, roll, pitch);
IvySendMsg("dl RC_3CH %d %d %d", throttle_mode, roll, pitch);
}
}
return 1;
}
int main ( int argc, char** argv) {
char devname[256];
int cnt;
ml = g_main_loop_new(NULL, FALSE);
parse_args(argc, argv);
IvyInit ("IvyCtrlJoystick", "IvyCtrlJoystick READY", NULL, NULL, NULL, NULL);
IvyStart("127.255.255.255");
while(1)
{
for (cnt=0; cnt<INPUT_DEV_MAX; cnt++){
sprintf(devname, DEVICE_NAME "%d", cnt);
if (init_hid_device(devname) == 0) break;
}
if (cnt != INPUT_DEV_MAX)
{
g_timeout_add(TIMEOUT_PERIOD, joystick_periodic, NULL);
g_main_loop_run(ml);
}
sleep(1);
}
return 0;
}

View File

@@ -1,265 +0,0 @@
/*
- 0x101..0x10F reserved for rc transmitters
- rc transmitters broadcast their messages (dest = 0xFFFF)
- aircrafts are configured (conf.xml) to one rc transmitter (e.g. 0x102)
- md5 sum be broadcasted?
- rc tx receives md5 sum messages and displays that on LEDs
- rc tx is switchable in addresses by button
- XBee-message
ID is AC_ID for aircraft, 0x100 for ground station
1 A XBEE_START (0x7E)
2 B LENGTH_MSB (A->E)
3 C LENGTH_LSB
XBEE_PAYLOAD
4 0 XBEE_TX16 (0x01) / XBEE_RX16 (0x81)
5 1 FRAME_ID (0) / SRC_ID_MSB
6 2 DEST_ID_MSB / SRC_ID_LSB
7 3 DEST_ID_LSB / XBEE_RSSI
8 4 TX16_OPTIONS (0) / RX16_OPTIONS
PPRZ_DATA
9 0 SENDER_ID
10 1 MSG_ID
MSG_PAYLOAD
11 0 RCTX_MODE
12 1 THOTTLE_LSB
13 2 THOTTLE_MSB
14 3 ROLL_LSB
15 4 ROLL_MSB
16 5 PITCH_LSB
17 6 PITCH_MSB
18 E XBEE_CHECKSUM (sum[A->D])
- messages.xml
<message name="RC_3CH" ID="27">
<field name="mode" type="uint8" unit="byte_mask"></field>
<field name="throttle" type="int16" unit="pprz" format="%d"/>
<field name="roll" type="int16" unit="pprz" format="%d"/>
<field name="pitch" type="int16" unit="pprz" format="%d"/>
</message>
- xbee.h
#ifdef USE_DOWNLINK_BROADCAST
#define GROUND_STATION_ADDR 0xFFFF
#else
#define GROUND_STATION_ADDR 0x0100
#endif
- datalink.c
#ifdef USE_RC_TELEMETRY
if (msg_id == DL_RC_3CH && DL_RC_3CH_ac_id(dl_buffer) == TX_ID) {
LED_TOGGLE(3);
bla_throttle = DL_RC_3CH_throttle(dl_buffer);
bla_roll = DL_RC_3CH_roll(dl_buffer);
bla_pitch = DL_RC_3CH_pitch(dl_buffer);
} else
#endif // USE_RC_TELEMETRY
*/
#include <stdio.h>
#include "std.h"
#include "init_hw.h"
#include "sys_time.h"
#include "adc.h"
#include "led.h"
#include "interrupt_hw.h"
#include "uart_hw.h"
#include "uart.h"
#include "autopilot.h"
#include "modules/datalink/datalink.h"
#include "messages.h"
#include "modules/datalink/downlink.h"
#if ((AC_ID > 0x108) || (AC_ID < (0x101)))
//#error aircraft ID should be 0x101..0x108 for RC transmitter
#endif
/** Maximum time allowed for low battery level */
#define LOW_BATTERY_DELAY 5
#ifdef ADC
struct adc_buf vsupply_adc_buf;
#ifndef VoltageOfAdc
#define VoltageOfAdc(adc) DefaultVoltageOfAdc(adc)
#endif
#endif
#define LOW_BATTERY_DECIVOLT (CATASTROPHIC_BAT_LEVEL*10)
uint16_t rctx_vsupply_decivolt;
uint8_t rctx_under_voltage;
uint8_t rctx_mode;
void init_rctx( void );
void event_task_rctx( void);
void periodic_task_rctx( void );
// datalink.c
#define SenderIdOfMsg(x) (x[0])
#define IdOfMsg(x) (x[1])
uint8_t dl_buffer[MSG_SIZE] __attribute__ ((aligned));
bool dl_msg_available;
uint16_t datalink_time;
void dl_parse_msg(void) {
datalink_time = 0;
uint8_t msg_id = IdOfMsg(dl_buffer);
if (msg_id == DL_PING) {
DOWNLINK_SEND_PONG();
} else
{ /* Last else */ }
}
/********** MAIN *************************************************************/
int main( void ) {
init_rctx();
while(1) {
if (sys_time_periodic())
periodic_task_rctx();
event_task_rctx();
}
return 0;
}
/********** INIT *************************************************************/
void init_rctx( void ) {
hw_init();
sys_time_init();
#ifdef LED
led_init();
#endif
#ifdef USE_UART1
Uart1Init();
#endif
#ifdef ADC
adc_init();
adc_buf_channel(ADC_CHANNEL_VSUPPLY, &vsupply_adc_buf, DEFAULT_AV_NB_SAMPLE);
#endif
#ifdef RADIO_CONTROL
ppm_init();
#endif
int_enable();
/** - wait 0.5s (for modem init ?) */
uint8_t init_cpt = 30;
while (init_cpt) {
if (sys_time_periodic())
init_cpt--;
}
#if defined DATALINK
#if DATALINK == XBEE
xbee_init();
#endif
#endif /* DATALINK */
}
/********** EVENT ************************************************************/
void event_task_rctx( void) {
#ifdef RADIO_CONTROL
if (ppm_valid) {
ppm_valid = FALSE;
radio_control_event_task();
#ifdef USE_RCTX_MODE_SWITCH
// TODO: set rxtx_mode from GPIO connected switch (e.g. I2C pins)
#else
rctx_mode = AP_MODE_OF_PULSE(rc_values[RADIO_MODE], 0) & 3;
#endif
rctx_mode |= rctx_under_voltage << 2;
LED_TOGGLE(3);
if (1)
// TODO: check XBee busy pin
// TODO: send only if aircraft is listening
// TODO: send (here) only in auto1 and manual
{
DOWNLINK_SEND_RC_3CH(
&rctx_mode,
&rc_values[RADIO_THROTTLE],
&rc_values[RADIO_ROLL],
&rc_values[RADIO_PITCH]);
}
}
#endif
#if defined DATALINK
#if DATALINK == XBEE
if (XBeeBuffer()) {
ReadXBeeBuffer();
if (xbee_msg_received) {
xbee_parse_payload();
xbee_msg_received = FALSE;
}
}
#endif
if (dl_msg_available) {
dl_parse_msg();
dl_msg_available = FALSE;
}
#endif /* DATALINK */
}
/************* PERIODIC ******************************************************/
void periodic_task_rctx( void ) {
static uint8_t _10Hz = 0;
static uint8_t _1Hz = 0;
_10Hz++;
if (_10Hz >= 6) _10Hz = 0;
_1Hz++;
if (_1Hz>=60) _1Hz=0;
#ifdef RADIO_CONTROL
radio_control_periodic_task();
#endif
#ifdef DOWNLINK
// TODO: needed? fbw_downlink_periodic_task();
#endif
#ifdef ADC
if (!_10Hz)
rctx_vsupply_decivolt = VoltageOfAdc((10*(vsupply_adc_buf.sum/vsupply_adc_buf.av_nb_sample)));
if (!_1Hz) {
static uint8_t t = 0;
if (rctx_vsupply_decivolt < LOW_BATTERY_DECIVOLT) {
t++;
} else {
t = 0;
rctx_under_voltage = 0;
}
if (t >= LOW_BATTERY_DELAY) {
LED_TOGGLE(1);
rctx_under_voltage = 1;
}
if (0)
// TODO: send (here) only in auto2
{
DOWNLINK_SEND_RC_3CH(
&rctx_mode,
&rc_values[RADIO_THROTTLE],
&rc_values[RADIO_ROLL],
&rc_values[RADIO_PITCH]);
}
}
#endif
}