Skip to content
Merged

K1 SDK #2153

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
5 changes: 1 addition & 4 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ jobs:
path:
- .
- services/aliveness
- services/breeze
- services/hula
runs-on:
- self-hosted
- v3
Expand Down Expand Up @@ -118,6 +116,7 @@ jobs:
- imagine
- replayer
- mujoco
- booster
profile:
- dev
- release
Expand All @@ -140,8 +139,6 @@ jobs:
matrix:
service:
- aliveness
- breeze
- hula
runs-on:
- self-hosted
- v3
Expand Down
15 changes: 14 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"crates/geometry",
"crates/hardware",
"crates/hula_types",
"crates/hulk_booster",
"crates/hulk_imagine",
"crates/hulk_manifest",
"crates/hulk_mujoco",
Expand Down Expand Up @@ -65,8 +66,6 @@ resolver = "2"
# services are built independently by yocto
exclude = [
"services/aliveness",
"services/breeze",
"services/hula",
"services/power-panic",
]

Expand Down
4 changes: 0 additions & 4 deletions crates/aliveness/src/service_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use zbus::{
#[derive(Debug)]
enum Service {
Hal,
Hula,
Hulk,
Lola,
}
Expand Down Expand Up @@ -59,7 +58,6 @@ impl Display for ServiceState {
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct SystemServices {
pub hal: ServiceState,
pub hula: ServiceState,
pub hulk: ServiceState,
pub lola: ServiceState,
}
Expand All @@ -68,7 +66,6 @@ impl SystemServices {
pub async fn query(dbus_connection: &Connection) -> Result<Self, Error> {
Ok(Self {
hal: get_service_state(dbus_connection, Service::Hal).await?,
hula: get_service_state(dbus_connection, Service::Hula).await?,
hulk: get_service_state(dbus_connection, Service::Hulk).await?,
lola: get_service_state(dbus_connection, Service::Lola).await?,
})
Expand All @@ -81,7 +78,6 @@ async fn get_unit_path(
) -> Result<OwnedObjectPath, Error> {
let service_name = match service {
Service::Hal => "hal.service",
Service::Hula => "hula.service",
Service::Hulk => "hulk.service",
Service::Lola => "lola.service",
};
Expand Down
6 changes: 0 additions & 6 deletions crates/constants/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};

pub const HULA_DBUS_INTERFACE: &str = "org.hulks.hula";
pub const HULA_DBUS_PATH: &str = "/org/hulks/HuLA";
pub const HULA_DBUS_SERVICE: &str = "org.hulks.hula";
pub const HULA_SOCKET_PATH: &str = "/tmp/hula";
pub const OS_IS_NOT_LINUX: bool = !cfg!(target_os = "linux");
pub const OS_RELEASE_PATH: &str = "/etc/os-release";
pub const OS_VERSION: &str = "8.0.2";
pub const SDK_VERSION: &str = "8.0.0";

#[derive(Serialize, Deserialize)]
pub struct Team {
Expand Down
21 changes: 21 additions & 0 deletions crates/hulk_booster/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "hulk_booster"
version.workspace = true
edition.workspace = true
license.workspace = true
homepage.workspace = true

[package.metadata.pepsi]
cross-compile = true

[dependencies]
color-eyre = { workspace = true }
control = { workspace = true }
vision = { workspace = true }
walking_inference = { workspace = true }

[build-dependencies]
code_generation = { workspace = true }
color-eyre = { workspace = true }
hulk_manifest = { workspace = true }
source_analyzer = { workspace = true }
19 changes: 19 additions & 0 deletions crates/hulk_booster/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use code_generation::{generate, write_to_file::WriteToFile, ExecutionMode};
use color_eyre::eyre::{Result, WrapErr};
use hulk_manifest::collect_hulk_cyclers;
use source_analyzer::{pretty::to_string_pretty, structs::Structs};

fn main() -> Result<()> {
let cyclers = collect_hulk_cyclers("..")?;
for path in cyclers.watch_paths() {
println!("cargo:rerun-if-changed={}", path.display());
}

println!();
println!("{}", to_string_pretty(&cyclers)?);

let structs = Structs::try_from_cyclers(&cyclers)?;
generate(&cyclers, &structs, ExecutionMode::Run)
.write_to_file("generated_code.rs")
.wrap_err("failed to write generated code to file")
}
11 changes: 11 additions & 0 deletions crates/hulk_booster/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use std::path::Path;

use color_eyre::Result;
use walking_inference::inference::WalkingInference;

fn main() -> Result<()> {
println!("Hello, world!");
WalkingInference::new(Path::new("etc/neural_network/T1.onnx"), &Default::default())?;

Ok(())
}
143 changes: 86 additions & 57 deletions crates/repository/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,31 @@ use std::{
path::Path,
};

use color_eyre::{
eyre::{bail, Context},
Result,
};
use color_eyre::{eyre::Context, Result};
use tokio::process::Command;

use crate::{sdk::download_and_install, Repository};
use crate::{
sdk::{build_sdk_container, image_exists_locally, SDKImage},
Repository,
};

#[derive(Debug, Clone)]
pub enum Environment {
Native,
Sdk { version: String },
Docker { image: String },
Podman { sdk_image: SDKImage },
Docker { sdk_image: SDKImage },
}

impl Display for Environment {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Environment::Native => write!(f, "Native"),
Environment::Sdk { version } => write!(f, "SDK ({version})"),
Environment::Docker { image } => write!(f, "Docker ({image})"),
Environment::Podman { sdk_image } => {
write!(f, "Podman ({})", sdk_image.name_tagged())
}
Environment::Docker { sdk_image } => {
write!(f, "Docker ({})", sdk_image.name_tagged())
}
}
}
}
Expand Down Expand Up @@ -59,35 +63,32 @@ impl Cargo {
}

pub async fn setup(&self, repository: &Repository) -> Result<()> {
if let Environment::Sdk { version } = &self.environment {
if let Environment::Podman { sdk_image } = &self.environment {
match self.host {
Host::Local => {
let data_home = repository
.resolve_data_home()
.await
.wrap_err("failed to resolve data home")?;

download_and_install(version, data_home)
.await
.wrap_err("failed to download and install SDK")?;
if !image_exists_locally(sdk_image).await {
build_sdk_container(repository, sdk_image)
.await
.wrap_err("failed to build SDK container")?
}
}
Host::Remote => {
let mut command =
Command::new(repository.root.join("scripts/remote_workspace"));

let status = command
.arg("pepsi")
.arg("sdk")
.arg("install")
.arg("--version")
.arg(version)
.status()
.await
.wrap_err("failed to run pepsi")?;

if !status.success() {
bail!("pepsi failed with {status}");
}
// let mut command =
// Command::new(repository.root.join("scripts/remote_workspace"));

// let status = command
// .arg("pepsi")
// .arg("sdk")
// .arg("install")
// .arg("--version")
// .arg(version)
// .status()
// .await
// .wrap_err("failed to run pepsi")?;

// if !status.success() {
// bail!("pepsi failed with {status}");
// }
}
}
}
Expand Down Expand Up @@ -120,36 +121,35 @@ impl Cargo {
command.push(arguments);
command
}
Environment::Sdk { version } => {
let environment_file = format!(
"$({data_home_script})/sdk/{version}/environment-setup-corei7-64-aldebaran-linux",
);
let mut command = OsString::from(format!(". {environment_file} && cargo "));
Environment::Podman { sdk_image } => {
let cargo_home = format!("$({data_home_script})/container-cargo-home/");
// TODO: Make image generic over SDK/native by modifying entry point; source SDK not here
let pwd = Path::new("/hulk").join(&repository.root_to_current_dir()?);
let root = repository.current_dir_to_root()?;
let tagged_image_name = sdk_image.name_tagged();
let mut command = OsString::from(build_command_string(
"podman",
cargo_home,
root.display().to_string(),
tagged_image_name,
pwd.display().to_string(),
));
command.push(arguments);
command.push(OsStr::new("'"));
command
}
Environment::Docker { image } => {
Environment::Docker { sdk_image } => {
let cargo_home = format!("$({data_home_script})/container-cargo-home/");
// TODO: Make image generic over SDK/native by modifying entry point; source SDK not here
let pwd = Path::new("/hulk").join(&repository.root_to_current_dir()?);
let root = repository.current_dir_to_root()?;
let mut command = OsString::from(format!(
"\
mkdir -p {cargo_home} && \
docker run \
--volume={root}:/hulk:z \
--volume={cargo_home}:/root/.cargo:z \
--rm \
--interactive \
--tty {image} \
/bin/sh -c '\
cd {pwd} && \
. /naosdk/environment-setup-corei7-64-aldebaran-linux && \
echo $PATH && \
cargo \
",
root = root.display(),
pwd = pwd.display(),
let tagged_image_name = sdk_image.name_tagged();
let mut command = OsString::from(build_command_string(
"docker",
cargo_home,
root.display().to_string(),
tagged_image_name,
pwd.display().to_string(),
));
command.push(arguments);
command.push(OsStr::new("'"));
Expand Down Expand Up @@ -179,3 +179,32 @@ impl Cargo {
Ok(command)
}
}

fn build_command_string(
container_runtime: &str,
cargo_home: String,
root: String,
tagged_image_name: String,
pwd: String,
) -> String {
format!(
"\
mkdir -p {cargo_home}/git && \
mkdir -p {cargo_home}/registry && \
{container_runtime} run \
--volume={root}:/hulk:z \
--volume={cargo_home}/git:/root/.cargo/git:z \
--volume={cargo_home}/registry:/root/.cargo/registry:z \
--rm \
--network=host \
--interactive \
--pull=never \
--tty \
{tagged_image_name} \
/bin/sh -c '\
cd {pwd} && \
echo $PATH && \
cargo \
"
)
}
Loading