SHARE
TWEET

Untitled

a guest Mar 17th, 2016 298 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. typedef struct{
  2.     /* NO_CONTROL = 0
  3.      * MODE_SPEED = 1
  4.      * MODE_ANGLE = 2
  5.      * MODE_SPEED_ANGLE = 3
  6.      * MODE_RC = 4
  7.      * MODE_ANGLE_REL_FRAME = 5
  8.      * -----------------
  9.      * Speed of rotation.
  10.      * If acceleration limiter is enabled in the settings, given speed may be limited.
  11.      * Units: 0,1220740379 degree/sec
  12.      * -----------------
  13.      * Target angle. Ignored in the MODE_SPEED mode.
  14.      * If mode=MODE_RC, it specifies RC data in range-500..500
  15.      * Units: 0,02197265625 degree.
  16.      * */
  17.     uint8_t control_mode;
  18.     int16_t speed_roll;
  19.     int16_t angle_roll;
  20.     int16_t speed_pitch;
  21.     int16_t angle_pitch;
  22.     int16_t speed_yaw;
  23.     int16_t angle_yaw;
  24.  
  25. }CMD_CONTROL_t;
  26.  
  27. typedef struct{
  28.     int8_t start;
  29.     int8_t command_id;
  30.     int8_t data_size;
  31.     int8_t header_checksum;
  32.     /***********/
  33.     CMD_CONTROL_t data;
  34.     /**********/
  35.     int8_t body_checksum;
  36.  
  37. }SimpleBGC_MSG_t;
  38. int8_t header_checksum(SimpleBGC_MSG_t msg){
  39.     return (msg.command_id + msg.data_size)%256 - 1u;
  40. }
  41. int8_t body_checksum(SimpleBGC_MSG_t msg){
  42.     int32_t sum = msg.data.control_mode +
  43.             msg.data.angle_pitch +
  44.             msg.data.angle_roll +
  45.             msg.data.angle_yaw +
  46.             msg.data.speed_pitch +
  47.             msg.data.speed_roll +
  48.             msg.data.speed_yaw;
  49.     return (sum % 256 - 1u);
  50. }
  51. void loop()
  52. {
  53. CMD_CONTROL_t data;
  54.     data.control_mode = 4; // no control
  55.     data.angle_pitch = 20;
  56.     data.angle_roll = 20;
  57.  
  58.     SimpleBGC_MSG_t msg;
  59.     msg.start = 0x3E;
  60.     msg.command_id = CMD_CONTROL;
  61.     msg.data_size = sizeof(data);
  62.     msg.header_checksum =header_checksum(msg);
  63.     msg.data = data;
  64.     msg.body_checksum = body_checksum(msg);
  65.  
  66.  
  67.     while(1)
  68.     {
  69.         UART_write(UART_1,&msg, sizeof(msg));
  70.         sleep(1000);
  71.     }
  72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top