Advertisement
Bartosz_Popielarczyk

Untitled

Jul 19th, 2022
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -(void) setThrottle:(float)y andYaw:(float)x
  2. {
  3.     self.mThrottle = y * -2;
  4.     self.mYaw = x * 30;
  5.    
  6.     [self updateVirtualStick];
  7. }
  8.  
  9. -(void) setXVelocity:(float)x andYVelocity:(float)y {
  10.     self.mXVelocity = x * 15.0;
  11.     self.mYVelocity = y * 15.0;
  12.     [self updateVirtualStick];
  13. }
  14.  
  15. -(void) updateVirtualStick
  16. {
  17.     // In rollPitchVelocity mode, the pitch property in DJIVirtualStickFlightControlData represents the Y direction velocity.
  18.     // The roll property represents the X direction velocity.
  19.     DJIVirtualStickFlightControlData ctrlData = {0};
  20.     ctrlData.pitch = self.mYVelocity;
  21.     ctrlData.roll = self.mXVelocity;
  22.     ctrlData.yaw = self.mYaw;
  23.     ctrlData.verticalThrottle = self.mThrottle;
  24.     DJIFlightController* fc = [DemoUtility fetchFlightController];
  25.     WeakRef(target);
  26.     if (fc && fc.isVirtualStickControlModeAvailable) {
  27.         [fc sendVirtualStickFlightControlData:ctrlData withCompletion:^(NSError * _Nullable error) {
  28.             WeakReturn(target);
  29.             if (error) {
  30.                 NSLog(@"Send Control Data error!");
  31.             }
  32.             else
  33.             {
  34.                 NSLog(@"Send Control Data succeeded!");
  35.             }
  36.            
  37.         }];
  38.     }
  39.     else{
  40.         NSLog(@"Virtual Stick Control Mode not Availabe!");
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement