Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. void manual()
  2. {
  3.     float multiplier = 2;
  4.  
  5.     float x = 0;
  6.     float y = 0;
  7.  
  8.     while (1)
  9.     {
  10.         KeyboardState keyboardstate = getKeyboardState();
  11.  
  12.         x += keyboardstate.right * multiplier;
  13.         x -= keyboardstate.left * multiplier;
  14.         y -= keyboardstate.up * multiplier;
  15.         y += keyboardstate.down * multiplier;
  16.  
  17.         // Make sure the velocity values dont go outside [-100,100]
  18.         y = min(max(y, -100), 100);
  19.         x = min(max(x, -100), 100);
  20.  
  21.         if (keyboardstate.quit)
  22.             break;
  23.  
  24.         // Convert the x and y components to tank controls.
  25.         unsigned char left;
  26.         unsigned char right;
  27.         toTankControls(x, y, &left, &right);
  28.  
  29.         sendMotorStatus(left, right);
  30.  
  31.         // Sleep a bit, this ensures that we dont overflow the wixel or 3pi robot with data.
  32.         Sleep(16);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement