Skip to content

Commit

Permalink
Add bevy feature (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxkitsune authored Oct 8, 2024
1 parent b4a4ac4 commit d654b62
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
6 changes: 4 additions & 2 deletions nidhogg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nidhogg"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -15,13 +15,15 @@ tracing = "0.1.37"
nidhogg_derive = { workspace = true }
coppeliasim_zmq_remote_api = { git = "https://github.com/samuel-cavalcanti/rust_zmqRemoteApi", optional = true }
num = "0.4.1"
bevy_ecs = { version = "0.14.2", optional = true }

[dev-dependencies]
tracing-subscriber = "0.3.16"

[features]
default = ["serde", "lola"]
default = ["serde", "lola", "bevy"]

serde = []
lola = ["dep:rmp-serde"]
coppelia = ["dep:coppeliasim_zmq_remote_api"]
bevy = ["dep:bevy_ecs"]
13 changes: 11 additions & 2 deletions nidhogg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,17 @@ pub mod types;

pub use error::{Error, Result};
use nidhogg_derive::Builder;
use serde::Serialize;
use types::{
color::RgbF32, Battery, FillExt, ForceSensitiveResistors, JointArray, LeftEar, LeftEye,
RightEar, RightEye, Skull, SonarEnabled, SonarValues, Touch, Vector2, Vector3,
};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[cfg(feature = "bevy")]
use bevy_ecs::prelude::Resource;

/// Generic backend trait used for implementing a NAO interface.
pub trait NaoBackend: Sized {
/// Connects to a NAO backend
Expand Down Expand Up @@ -107,7 +112,9 @@ pub trait DisconnectExt {
}

/// High level representation of the `LoLA` state message.
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct NaoState {
pub position: JointArray<f32>,
pub stiffness: JointArray<f32>,
Expand Down Expand Up @@ -154,6 +161,7 @@ pub struct NaoState {

/// High level representation of the `LoLA` update message.
#[derive(Builder, Clone, Debug)]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct NaoControlMessage {
pub position: JointArray<f32>,
pub stiffness: JointArray<f32>,
Expand Down Expand Up @@ -193,6 +201,7 @@ impl Default for NaoControlMessage {

/// Struct containing the hardware identifiers for the NAO V6 robot.
#[derive(Debug)]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct HardwareInfo {
pub body_id: String,
pub body_version: String,
Expand Down
14 changes: 14 additions & 0 deletions nidhogg/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use nidhogg_derive::{Builder, Filler};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[cfg(feature = "bevy")]
use bevy_ecs::prelude::Resource;

pub mod color;
mod joint_array;
mod vector;
Expand All @@ -25,6 +28,7 @@ pub trait FillExt<T> {
/// Each value represents the intensity of a white LED.
#[derive(Builder, Clone, Debug, Default, Filler)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct Skull {
pub left_front_0: f32,
pub left_front_1: f32,
Expand All @@ -49,6 +53,7 @@ pub struct Skull {
/// ![Left Ear](https://cdn.dutchnao.team/nidhogg/hardware_led_left_ear.png)
#[derive(Builder, Clone, Debug, Default, Filler)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct LeftEar {
pub l0: f32,
pub l1: f32,
Expand All @@ -70,6 +75,7 @@ pub struct LeftEar {
/// ![Right Ear](https://cdn.dutchnao.team/nidhogg/hardware_led_right_ear.png)
#[derive(Builder, Clone, Debug, Default, Filler)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct RightEar {
pub r0: f32,
pub r1: f32,
Expand All @@ -90,6 +96,7 @@ pub struct RightEar {
/// ![Left Eye](https://cdn.dutchnao.team/nidhogg/hardware_led_left_eye.png)
#[derive(Builder, Clone, Debug, Default, Filler)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct LeftEye {
pub l0: RgbF32,
pub l1: RgbF32,
Expand All @@ -108,6 +115,7 @@ pub struct LeftEye {
/// ![Right Eye](https://cdn.dutchnao.team/nidhogg/hardware_led_right_eye.png)
#[derive(Builder, Clone, Debug, Default, Filler)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct RightEye {
pub r0: RgbF32,
pub r1: RgbF32,
Expand All @@ -122,6 +130,7 @@ pub struct RightEye {
/// Struct representing the battery status of the robot.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct Battery {
/// The battery percentage
pub charge: f32,
Expand All @@ -137,6 +146,7 @@ pub struct Battery {
/// Struct containing the [`ForceSensitiveResistorFoot`] value for each foot.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct ForceSensitiveResistors {
/// FSR values from the four sensors in the left foot.
pub left_foot: ForceSensitiveResistorFoot,
Expand All @@ -159,6 +169,7 @@ impl ForceSensitiveResistors {
/// Struct representing the force sensitive resistors in one of the feet.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct ForceSensitiveResistorFoot {
/// FSR value representing the estimated weight in kilograms on the front left foot sensor.
///
Expand Down Expand Up @@ -193,6 +204,7 @@ impl ForceSensitiveResistorFoot {
/// Values read by the left and right sonar sensor.
#[derive(Builder, Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct SonarValues {
/// Left Sonar Value.
///
Expand All @@ -219,6 +231,7 @@ pub struct SonarValues {
/// Enabled state of the left and right sonar sensors.
#[derive(Builder, Clone, Default, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct SonarEnabled {
pub left: bool,
pub right: bool,
Expand All @@ -227,6 +240,7 @@ pub struct SonarEnabled {
/// Struct containing the touch activiation value for each touch sensor on the robot.
#[derive(Clone, Debug, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "bevy", derive(Resource))]
pub struct Touch {
pub chest_board: f32,
pub head_front: f32,
Expand Down

0 comments on commit d654b62

Please sign in to comment.