1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
use anyhow::Result as AnyResult; use arsdk_rs::{ command::Feature::JumpingSumo as JumpingSumoFeature, frame::{BufferID, Frame, Type as FrameType}, jumping_sumo::PilotState, jumping_sumo::{Anim, Class::*, PilotingID::*}, Config, Drone, }; pub mod prelude { pub use crate::JumpingSumo; pub use arsdk_rs::{jumping_sumo::PilotState, prelude::*}; } pub struct JumpingSumo { drone: Drone, } const TURN_ANGLE: i8 = 30; const FORWARD_SPEED: i8 = 100; impl JumpingSumo { pub fn connect(config: Config) -> AnyResult<Self> { Ok(Self { drone: Drone::connect(config)?, }) } pub fn forward(&self) -> AnyResult<()> { self.drive(PilotState { flag: true, speed: FORWARD_SPEED, turn: 0, }) } pub fn backwards(&self) -> AnyResult<()> { self.drive(PilotState { flag: true, speed: -FORWARD_SPEED, turn: 0, }) } pub fn turn_left(&self) -> AnyResult<()> { self.drive(PilotState { flag: true, speed: 0, turn: -TURN_ANGLE, }) } pub fn turn_right(&self) -> AnyResult<()> { self.drive(PilotState { flag: true, speed: 0, turn: TURN_ANGLE, }) } pub fn stop(&self) -> AnyResult<()> { self.drive(PilotState { flag: false, speed: 0, turn: 0, }) } pub fn drive(&self, state: PilotState) -> AnyResult<()> { let feature = JumpingSumoFeature(Piloting(Pilot(state))); let frame = Frame::for_drone( &self.drone, FrameType::Data, BufferID::CDNonAck, Some(feature), ); self.drone.send_frame(frame) } pub fn jump(&self) -> AnyResult<()> { let feature = JumpingSumoFeature(Animations(Anim::Jump)); let frame = Frame::for_drone( &self.drone, FrameType::DataWithAck, BufferID::CDAck, Some(feature), ); self.drone.send_frame(frame) } }