SHARE
TWEET

Untitled

a guest Mar 17th, 2016 288 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. typedef struct{
  3.     /* NO_CONTROL = 0
  4.      * MODE_SPEED = 1
  5.      * MODE_ANGLE = 2
  6.      * MODE_SPEED_ANGLE = 3
  7.      * MODE_RC = 4
  8.      * MODE_ANGLE_REL_FRAME = 5
  9.      * -----------------
  10.      * Speed of rotation.
  11.      * If acceleration limiter is enabled in the settings, given speed may be limited.
  12.      * Units: 0,1220740379 degree/sec
  13.      * -----------------
  14.      * Target angle. Ignored in the MODE_SPEED mode.
  15.      * If mode=MODE_RC, it specifies RC data in range-500..500
  16.      * Units: 0,02197265625 degree.
  17.      * */
  18.     uint8_t control_mode;
  19.     int16_t speed_roll;
  20.     int16_t angle_roll;
  21.     int16_t speed_pitch;
  22.     int16_t angle_pitch;
  23.     int16_t speed_yaw;
  24.     int16_t angle_yaw;
  25.  
  26. }CMD_CONTROL_t;
  27.  
  28. typedef struct{
  29.     int8_t start;
  30.     int8_t command_id;
  31.     int8_t data_size;
  32.     int8_t header_checksum;
  33.     CMD_CONTROL_t data;
  34.     int8_t body_checksum;
  35.  
  36. }SimpleBGC_MSG_t;
  37.  
  38. int8_t header_checksum(SimpleBGC_MSG_t msg){
  39.     return (msg.command_id + msg.data_size)%256;
  40. }
  41. int8_t body_checksum(SimpleBGC_MSG_t msg){
  42.     int16_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);
  50. }
  51.  
  52.  
  53.     CMD_CONTROL_t data = {0,0,0,0,0,0,0};
  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_4,&msg, sizeof(msg));
  70.        sleep(1000);
  71.     }
  72.  
  73.  
  74.     return 0;
  75. }
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