Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
setup_actuators.c
Go to the documentation of this file.
1 #include "generated/airframe.h"
2 
3 #include "std.h"
4 #include "mcu.h"
5 #include "mcu_periph/sys_time.h"
6 #include "led.h"
7 #include "subsystems/actuators.h"
8 
10 
11 #ifndef DOWNLINK_DEVICE
12 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
13 #endif
14 
15 #define DATALINK_C
18 #include "mcu_periph/uart.h"
20 
21 #include "generated/settings.h"
22 
23 #define IdOfMsg(x) (x[1])
24 
25 
26 void dl_parse_msg( void ) {
27  uint8_t msg_id = IdOfMsg(dl_buffer);
28  if (msg_id == DL_SET_ACTUATOR) {
29  uint8_t servo_no = DL_SET_ACTUATOR_no(dl_buffer);
30  uint16_t servo_value = DL_SET_ACTUATOR_value(dl_buffer);
31  LED_TOGGLE(2);
32  if (servo_no < ACTUATORS_NB)
33  //SetServo(servo_no, servo_value);
34  }
35 #ifdef DlSetting
36  else if (msg_id == DL_SETTING && DL_SETTING_ac_id(dl_buffer) == AC_ID) {
37  uint8_t i = DL_SETTING_index(dl_buffer);
38  float val = DL_SETTING_value(dl_buffer);
39  DlSetting(i, val);
40  LED_TOGGLE(2);
41  for (int j=0 ; j<8 ; j++) {
42  //SetServo(j,actuators[j]);
43  }
44  DOWNLINK_SEND_DL_VALUE(DefaultChannel, DefaultDevice, &i, &val);
45  } else if (msg_id == DL_GET_SETTING && DL_GET_SETTING_ac_id(dl_buffer) == AC_ID) {
46  uint8_t i = DL_GET_SETTING_index(dl_buffer);
47  float val = settings_get_value(i);
48  DOWNLINK_SEND_DL_VALUE(DefaultChannel, DefaultDevice, &i, &val);
49  }
50 #endif
51 }
52 
53 
54 void init_fbw( void ) {
55  mcu_init();
56 
58 
59  uint8_t i;
60  for(i = 0; i < ACTUATORS_NB; i++) {
61  //SetServo(i, 1500);
62  }
63 
64  // SetServo(SERVO_GAZ, SERVO_GAZ_MIN);
65 
67 
69 }
70 
72 
75 
76 }
77 
78 void periodic_task_fbw(void) {
79  /* static float t; */
80  /* t += 1./60.; */
81  /* uint16_t servo_value = 1500+ 500*sin(t); */
82  /* SetServo(SERVO_THROTTLE, servo_value); */
83 
84  RunOnceEvery(300, DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM));
85  RunOnceEvery(300, DOWNLINK_SEND_ACTUATORS(DefaultChannel, DefaultDevice, ACTUATORS_NB, actuators ));
86 }
87 
88 void event_task_fbw(void) {
89  DatalinkEvent();
90 }
FBW ( FlyByWire ) process API.
unsigned short uint16_t
Definition: types.h:16
void handle_periodic_tasks_fbw(void)
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void mcu_init(void)
Microcontroller peripherals initialization.
Definition: mcu.c:61
void event_task_fbw(void)
void periodic_task_fbw(void)
Extra datalink using PPRZ protocol.
#define actuators
#define mcu_int_enable()
Definition: mcu_arch.h:37
Architecture independent timing functions.
uint16_t val[TCOUPLE_NB]
Hardware independent API for actuators (servos, motor controllers).
int sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:37
#define LED_TOGGLE(i)
Definition: led_hw.h:30
static bool_t sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:111
Arch independent mcu ( Micro Controller Unit ) utilities.
unsigned char uint8_t
Definition: types.h:14
void init_fbw(void)
void dl_parse_msg(void)
#define IdOfMsg(x)
uint8_t dl_buffer[MSG_SIZE]
Definition: main_demo5.c:59
#define PERIODIC_FREQUENCY
Definition: imu_aspirin2.c:54
arch independent LED (Light Emitting Diodes) API
void actuators_init(void)
Definition: actuators_at.c:32