Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,039 changes: 1,676 additions & 363 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ members = [
"arsdk-rs",
"jumpingsumo-rs",
"bebop2",
# "anafi-rs",
"anafi-rs",
]
3 changes: 3 additions & 0 deletions anafi-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
arsdk-rs = { path = "../arsdk-rs" }
glutin = "=0.27"
rdev = {version = "0.5.3", features = ["unstable_grab"] }
scroll = "0.10.1"

[dev-dependencies]
# Used for examples
Expand Down
53 changes: 45 additions & 8 deletions anafi-rs/examples/liftoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,61 @@ use std::error::Error;
use anafi_rs::prelude::*;
use std::time::Duration;

// https://www.dema.ch/media/catalog/product/pdf/1976008063/pdf_file_3/en_US/white-paper-anafi-usa-v1.5.2_en.pdf
// https://github.com/RIAEvangelist/node-parrot-drone/blob/master/docs/ardrone3.md

fn main() -> Result<(), Box<dyn Error>> {
env_logger::init();

let drone_ip: std::net::IpAddr = "192.168.42.1".parse()?;
let drone = Anafi::connect(drone_ip.into())?;

info!("Takeoff!");
drone.take_off()?;

for i in 0..50 {
drone.take_off()?;
}
std::thread::sleep(Duration::from_secs(2));
log::warn!("UP!");
drone.up()?;
std::thread::sleep(Duration::from_secs(2));

info!("Wait 5 seconds and fly UP");
std::thread::sleep(Duration::from_secs(5));
log::warn!("forward!");
drone.forward()?;
std::thread::sleep(Duration::from_secs(1));
drone.stop()?;

log::warn!("backward!");
drone.backward()?;
std::thread::sleep(Duration::from_secs(1));
drone.stop()?;

log::warn!("left!");
drone.strafe_left()?;
std::thread::sleep(Duration::from_secs(1));

log::warn!("right!");
drone.strafe_right()?;
std::thread::sleep(Duration::from_secs(1));

for i in 0..50 {
drone.landing()?;
log::warn!("turn left!");
for _ in 0..30 {
drone.turn_left()?;
std::thread::sleep(Duration::from_millis(300));
}

log::warn!("turn right!");
for _ in 0..30 {
drone.turn_right()?;
std::thread::sleep(Duration::from_millis(300));
}

log::warn!("DOWN!");
drone.down()?;
std::thread::sleep(Duration::from_secs(2));

std::thread::sleep(Duration::from_secs(2));
log::warn!("LAND!");
drone.landing()?;

std::thread::sleep(Duration::from_secs(5));

Ok(())
}
138 changes: 122 additions & 16 deletions anafi-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub mod prelude {
}

pub struct Anafi {
// roll: 0,
// pitch: forward / backward,
// yaw: strafe left / right,
// gaz: up / down
drone: Drone,
}

Expand All @@ -31,41 +35,148 @@ impl Anafi {
pub fn take_off(&self) -> Result<(), Error> {
let feature = Feature::ArDrone3(Some(ArDrone3::Piloting(Piloting::TakeOff)));

let frame = Frame::for_drone(
&self.drone,
Type::DataWithAck,
BufferID::CDAck,
Some(feature),
);
let frame = Frame::for_drone(&self.drone, Type::Data, BufferID::CDNonAck, Some(feature));

self.drone.send_frame(frame)
}

pub fn up(&self, sequence_id: u8) -> Result<(), Error> {
pub fn up(&self) -> Result<(), Error> {
let feature = Feature::ArDrone3(Some(ArDrone3::Piloting(Piloting::PCMD(PCMD {
flag: true,
roll: 0,
pitch: 0,
yaw: 0,
gaz: 100,
timestamp: Utc::now(),
sequence_id,
sequence_id: self.drone.piloting_id(),
}))));

let frame = Frame::for_drone(&self.drone, Type::Data, BufferID::CDNonAck, Some(feature));

self.drone.send_frame(frame)
}

pub fn down(&self, sequence_id: u8) -> Result<(), Error> {
pub fn down(&self) -> Result<(), Error> {
let feature = Feature::ArDrone3(Some(ArDrone3::Piloting(Piloting::PCMD(PCMD {
flag: true,
roll: 0,
pitch: 0,
yaw: 0,
gaz: -100,
timestamp: Utc::now(),
sequence_id,
sequence_id: self.drone.piloting_id(),
}))));

let frame = Frame::for_drone(&self.drone, Type::Data, BufferID::CDNonAck, Some(feature));

self.drone.send_frame(frame)
}

pub fn backward(&self) -> Result<(), Error> {
let feature = Feature::ArDrone3(Some(ArDrone3::Piloting(Piloting::PCMD(PCMD {
flag: true,
roll: 0,
pitch: -100,
yaw: 0,
gaz: 0,
timestamp: Utc::now(),
sequence_id: self.drone.piloting_id(),
}))));

let frame = Frame::for_drone(&self.drone, Type::Data, BufferID::CDNonAck, Some(feature));

self.drone.send_frame(frame)
}

pub fn forward(&self) -> Result<(), Error> {
let feature = Feature::ArDrone3(Some(ArDrone3::Piloting(Piloting::PCMD(PCMD {
flag: true,
roll: 0,
pitch: 100,
yaw: 0,
gaz: 0,
timestamp: Utc::now(),
sequence_id: self.drone.piloting_id(),
}))));

let frame = Frame::for_drone(&self.drone, Type::Data, BufferID::CDNonAck, Some(feature));

self.drone.send_frame(frame)
}

pub fn strafe_left(&self) -> Result<(), Error> {
let feature = Feature::ArDrone3(Some(ArDrone3::Piloting(Piloting::PCMD(PCMD {
flag: true,
roll: -100,
pitch: 0,
yaw: 0,
gaz: 0,
timestamp: Utc::now(),
sequence_id: self.drone.piloting_id(),
}))));

let frame = Frame::for_drone(&self.drone, Type::Data, BufferID::CDNonAck, Some(feature));

self.drone.send_frame(frame)
}

pub fn strafe_right(&self) -> Result<(), Error> {
let feature = Feature::ArDrone3(Some(ArDrone3::Piloting(Piloting::PCMD(PCMD {
flag: true,
roll: 100,
pitch: 0,
yaw: 0,
gaz: 0,
timestamp: Utc::now(),
sequence_id: self.drone.piloting_id(),
}))));

let frame = Frame::for_drone(&self.drone, Type::Data, BufferID::CDNonAck, Some(feature));

self.drone.send_frame(frame)
}

pub fn turn_left(&self) -> Result<(), Error> {
let feature = Feature::ArDrone3(Some(ArDrone3::Piloting(Piloting::PCMD(PCMD {
flag: false,
roll: 0,
pitch: 0,
yaw: -128,
gaz: 0,
timestamp: Utc::now(),
sequence_id: self.drone.piloting_id(),
}))));

let frame = Frame::for_drone(&self.drone, Type::Data, BufferID::CDNonAck, Some(feature));

self.drone.send_frame(frame)
}

pub fn turn_right(&self) -> Result<(), Error> {
let feature = Feature::ArDrone3(Some(ArDrone3::Piloting(Piloting::PCMD(PCMD {
flag: false,
roll: 0,
pitch: 0,
yaw: 127,
gaz: 0,
timestamp: Utc::now(),
sequence_id: self.drone.piloting_id(),
}))));

let frame = Frame::for_drone(&self.drone, Type::Data, BufferID::CDNonAck, Some(feature));

self.drone.send_frame(frame)
}

pub fn stop(&self) -> Result<(), Error> {
let feature = Feature::ArDrone3(Some(ArDrone3::Piloting(Piloting::PCMD(PCMD {
flag: true,
roll: 0,
pitch: 0,
yaw: 0,
gaz: 0,
timestamp: Utc::now(),
sequence_id: self.drone.piloting_id(),
}))));

let frame = Frame::for_drone(&self.drone, Type::Data, BufferID::CDNonAck, Some(feature));
Expand All @@ -76,12 +187,7 @@ impl Anafi {
pub fn landing(&self) -> Result<(), Error> {
let feature = Feature::ArDrone3(Some(ArDrone3::Piloting(Piloting::Landing)));

let frame = Frame::for_drone(
&self.drone,
Type::DataWithAck,
BufferID::CDAck,
Some(feature),
);
let frame = Frame::for_drone(&self.drone, Type::Data, BufferID::CDNonAck, Some(feature));

self.drone.send_frame(frame)
}
Expand Down
9 changes: 6 additions & 3 deletions arsdk-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
[package]
name = "arsdk-rs"
version = "0.0.5"
authors = ["o0Ignition0o <[email protected]>", "Lachezar Lechev <[email protected]>"]
authors = [
"o0Ignition0o <[email protected]>",
"Lachezar Lechev <[email protected]>",
]
edition = "2018"
description = "Parrot drones SDK in Rust (AeroRust)"
license = "MIT/Apache-2.0"
keywords = ["AeroRust", "drone", "parrot", "sdk"]

[dependencies]
thiserror = "1.0"
pnet = "0.25"
serde = {version = "1.0", features = ["derive"]}
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = "1"
dashmap = "3.11"
chrono = "0.4"
scroll = "0.10"
log = "0.4"
pnet = "0.35.0"
2 changes: 1 addition & 1 deletion arsdk-rs/src/ardrone3/piloting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
/// ARCOMMANDS_Decoder_ARDrone3PilotingPCMDCb (_flag, _roll, _pitch, _yaw, _gaz, _timestampAndSeqNum, ARCOMMANDS_Decoder_ARDrone3PilotingPCMDCustom);
/// ARCOMMANDS_Decoder_ARDrone3PilotingPCMDDecodeArgs (uint8_t *_flag, int8_t *_roll, int8_t *_pitch, int8_t *_yaw, int8_t *_gaz, uint32_t *_timestampAndSeqNum)
/// * @param _timestampAndSeqNum Command timestamp in milliseconds (low 24 bits) + command sequence number (high 8 bits) [0;255].
/// 1_588_771_372_921

Check failure on line 17 in arsdk-rs/src/ardrone3/piloting.rs

View workflow job for this annotation

GitHub Actions / Clippy

doc list item without indentation
/// @see https://developer.parrot.com/docs/reference/bebop_2/index.html#move-the-drone

Check failure on line 18 in arsdk-rs/src/ardrone3/piloting.rs

View workflow job for this annotation

GitHub Actions / Clippy

doc list item without indentation
PCMD(PCMD),
/// ARCOMMANDS_ID_ARDRONE3_PILOTING_CMD_LANDING = 3
Landing,
Expand Down Expand Up @@ -45,7 +45,7 @@
StopPilotedPOI,
}

impl Into<u16> for &Piloting {

Check failure on line 48 in arsdk-rs/src/ardrone3/piloting.rs

View workflow job for this annotation

GitHub Actions / Clippy

an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
fn into(self) -> u16 {
use Piloting::*;

Expand Down Expand Up @@ -107,7 +107,7 @@
}
}

impl<'a> ctx::TryIntoCtx<Endian> for Piloting {

Check failure on line 110 in arsdk-rs/src/ardrone3/piloting.rs

View workflow job for this annotation

GitHub Actions / Clippy

this lifetime isn't used in the impl
type Error = Error;

fn try_into_ctx(self, this: &mut [u8], ctx: Endian) -> Result<usize, Self::Error> {
Expand All @@ -120,7 +120,7 @@
Piloting::PCMD(pcmd) => {
this.gwrite_with(pcmd, &mut offset, ctx)?;
}
// Piloting::Landing => {}
Piloting::Landing => {}
// Piloting::Emergency => {}
// Piloting::NavigateHome => {}
// Piloting::AutoTakeOffMode => {}
Expand Down
1 change: 0 additions & 1 deletion arsdk-rs/src/ardrone3/piloting/pcmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
pub yaw: i8,
pub gaz: i8,
pub timestamp: DateTime<Utc>,
// TODO: How should we handle the `sequence_id` in order not to show it to the user?
pub sequence_id: u8,
}

Expand Down Expand Up @@ -59,7 +58,7 @@
}
}

impl<'a> ctx::TryIntoCtx<Endian> for PCMD {

Check failure on line 61 in arsdk-rs/src/ardrone3/piloting/pcmd.rs

View workflow job for this annotation

GitHub Actions / Clippy

this lifetime isn't used in the impl
type Error = Error;

fn try_into_ctx(self, this: &mut [u8], ctx: Endian) -> Result<usize, Self::Error> {
Expand Down Expand Up @@ -100,7 +99,7 @@
0,
0,
]);
let timestamp = Utc.timestamp_millis(timestamp_i64);

Check warning on line 102 in arsdk-rs/src/ardrone3/piloting/pcmd.rs

View workflow job for this annotation

GitHub Actions / Check

use of deprecated method `chrono::TimeZone::timestamp_millis`: use `timestamp_millis_opt()` instead

Check warning on line 102 in arsdk-rs/src/ardrone3/piloting/pcmd.rs

View workflow job for this annotation

GitHub Actions / Check

use of deprecated method `chrono::TimeZone::timestamp_millis`: use `timestamp_millis_opt()` instead

Check warning on line 102 in arsdk-rs/src/ardrone3/piloting/pcmd.rs

View workflow job for this annotation

GitHub Actions / Test Suite

use of deprecated method `chrono::TimeZone::timestamp_millis`: use `timestamp_millis_opt()` instead

Check warning on line 102 in arsdk-rs/src/ardrone3/piloting/pcmd.rs

View workflow job for this annotation

GitHub Actions / Test Suite

use of deprecated method `chrono::TimeZone::timestamp_millis`: use `timestamp_millis_opt()` instead
// 8 bits
let sequence_id = timestamp_and_seq[3];

Expand All @@ -114,7 +113,7 @@
}
}

impl<'a> ctx::TryIntoCtx<Endian> for TimestampAndSeq {

Check failure on line 116 in arsdk-rs/src/ardrone3/piloting/pcmd.rs

View workflow job for this annotation

GitHub Actions / Clippy

this lifetime isn't used in the impl
type Error = Error;

fn try_into_ctx(self, this: &mut [u8], ctx: Endian) -> Result<usize, Self::Error> {
Expand Down
28 changes: 25 additions & 3 deletions arsdk-rs/src/ardrone3/piloting_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum PilotingState {
SpeedChanged,
/// ARCOMMANDS_ID_ARDRONE3_PILOTINGSTATE_CMD_ATTITUDECHANGED = 6,
/// Frame { frame_type: Data, buffer_id: DCNavdata, sequence_id: 40, feature: Some(ArDrone3(Some(PilotingState { data: [6, 0, 44, 49, 49, 55, 153, 38, 7, 185, 107, 25, 201, 63] }))) }
AttitudeChanged,
AttitudeChanged(AttitudeChanged),
/// ARCOMMANDS_ID_ARDRONE3_PILOTINGSTATE_CMD_AUTOTAKEOFFMODECHANGED = 7,
AutoTakeOffModeChanged,
/// ARCOMMANDS_ID_ARDRONE3_PILOTINGSTATE_CMD_ALTITUDECHANGED = 8,
Expand Down Expand Up @@ -91,7 +91,7 @@ impl Into<u16> for &PilotingState {
NavigateHomeStateChanged => 3,
PositionChanged => 4,
SpeedChanged => 5,
AttitudeChanged => 6,
AttitudeChanged(_) => 6,
AutoTakeOffModeChanged => 7,
AltitudeChanged => 8,
GpsLocationChanged => 9,
Expand All @@ -106,6 +106,11 @@ impl Into<u16> for &PilotingState {
}
}

// ------------------------------------------------------------

#[derive(Debug, Clone, Eq, PartialEq)]
pub struct AttitudeChanged(Vec<u8>);

pub mod scroll_impl {
use super::*;
use crate::{frame::Error, parse::read_unknown};
Expand All @@ -118,8 +123,8 @@ pub mod scroll_impl {
fn try_from_ctx(src: &'a [u8], ctx: Endian) -> Result<(Self, usize), Self::Error> {
let mut offset = 0;

#[allow(clippy::match_single_binding)]
let piloting_state = match src.gread_with::<u16>(&mut offset, ctx)? {
6 => Self::AttitudeChanged(AttitudeChanged::try_from_ctx(&src[offset..], ctx)?.0),
unknown => Self::Unknown {
piloting_state: unknown,
data: read_unknown(src, &mut offset)?,
Expand Down Expand Up @@ -148,4 +153,21 @@ pub mod scroll_impl {
Ok(offset)
}
}

impl<'a> ctx::TryFromCtx<'a, Endian> for AttitudeChanged {
type Error = Error;

// and the lifetime annotation on `&'a [u8]` here
fn try_from_ctx(src: &'a [u8], ctx: Endian) -> Result<(Self, usize), Self::Error> {
let mut offset = 0;

let mut buffer = Vec::new();

while let Ok(b) = src.gread_with::<u8>(&mut offset, ctx) {
buffer.push(b);
}

Ok((Self(buffer), offset))
}
}
}
Loading
Loading