Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ros service - no module named yaml #367

Open
i-am-logger opened this issue Mar 5, 2024 · 11 comments
Open

ros service - no module named yaml #367

i-am-logger opened this issue Mar 5, 2024 · 11 comments

Comments

@i-am-logger
Copy link

i-am-logger commented Mar 5, 2024

I modified the talker from the demo cpp to a heartbeat service and i get the following error:

image

my fle:

 inputs = {
    nixpkgs.url = "nixpkgs/nixos-unstable";
    nixos-rk3588 = {
      url = "github:realsnick/nixos-rk3588";
    };
    nix-ros-overlay = {
      url = "github:lopsided98/nix-ros-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
  ...
  sky360-packages-overlay = (final: prev: {
    sky360 = {
      sky360-ros-iron-heartbeat = prev.callPackage ./ros/iron/heartbeat { };
      qhyccd_sdk = prev.callPackage ./pkgs/qhyccd_sdk.nix { };
    };
  });
... 
lib.nixosSystem {
  inherit system;
    pkgs = import nixpkgs {
      inherit system;
      config.allowUnfree = true;
      overlays = [
        nix-ros-overlay.overlays.default
        sky360-packages-overlay
      ];
    };
  };

ros2.nix

{ pkgs, ... }:
{
  environment.systemPackages = with pkgs; [
    sky360.sky360-ros-iron-heartbeat
  ];

  services.ros2 = {
    enable = true;
    distro = "iron";
    domainId = 0;
    nodes = {
      heartbeat = {
        package = pkgs.sky360.sky360-ros-iron-heartbeat.pname;
        node = "heartbeat";
        args = [ ];
        rosArgs = [ ];
        params = { };
      };
    };
  };
}

heartbeat.nix

{ pkgs, lib, ... }:
with pkgs;
with pkgs.rosPackages.iron;

buildRosPackage {
  pname = "sky360-ros-iron-heartbeat";

  version = "0.1.1";

  src = ./ros;

  buildType = "ament_cmake";
  buildInputs = [ ament-cmake rmw-implementation-cmake ];
  checkInputs = [ ament-cmake-pytest ament-lint-auto ament-lint-common launch launch-testing launch-testing-ament-cmake launch-testing-ros ];
  propagatedBuildInputs = [ example-interfaces launch-ros launch-xml rcl-interfaces rclcpp rclcpp-components rcutils rmw std-msgs ];
  nativeBuildInputs = [ ament-cmake ];

  meta = {
    description = ''Sky360 heartbeat ros2 node'';
    license = with lib.licenses; [ mit ];
  };
}
@wentasah
Copy link
Contributor

wentasah commented Mar 6, 2024

I cannot easily reproduce your problem with the files you provided (few things are missing there), but it appears that package.xml in rclpy lacks the following line:

<depend>python3-yaml</depend>

As a quick workaround, you can add python3Packages.pyyaml to propagatedBuildInputs in your heartbeat.nix.

To fix this problem for everybody, I suggest to first test whether adding python3Packages.pyyaml to propagatedBuildInputs in distros/iron/rclpy/default.nix (and adding python3Packages to that function parameters) fixes the problem. If yes, than it would be great if you can send a PR adding the above <depend> line to rclpy. Mention there the error message you're experiencing. After some time, the fix will automatically appear in this overlay too.

@i-am-logger
Copy link
Author

tried to add python3Packages.pyyaml but still fails with same error :/

@wentasah
Copy link
Contributor

wentasah commented Mar 7, 2024

Hmm, right. I verified that rospy has the yaml module available, perhaps through some of its dependencies. So the problem is elsewhere. I tried clonning your repo https://github.com/realsnick/sky360/ and running:

nixos-rebuild build-vm --flake .#cyclop-x86_64

But it fails with:

error: The option `sdImage' does not exist. Definition values:
       - In `/nix/store/cxlqv54wad2n39g1axz8k9pra006d80h-source/nixOS/flake.nix':
           {
             imageName = "sky360-cyclop-0.3.2-x86_64-linux";
           }

Do you know why?

@i-am-logger
Copy link
Author

nix build --option system aarch64 .#cyclop-orange_pi_5_plus-sd_image is the command

@i-am-logger
Copy link
Author

i-am-logger commented Mar 7, 2024

i made a mistake! apologizes...adding the pyyaml to rcply seems to fix one issue but now it seems the service fails due to unable to find the package

image

i'm wondering if this is related to the overlay that stopped working as now the package is in its own namespace...

@wentasah
Copy link
Contributor

wentasah commented Mar 7, 2024

I have no practical experience with NixOS ROS modules, but from looking at the code, it seems you should modify your ros2.nix as follows:

{ pkgs, ... }:
{
  services.ros2 = {
    enable = true;
    distro = "iron";
    domainId = 0;
    inherit pkgs;
    systemPackages = pkgs: with pkgs; [
      sky360.sky360-ros-iron-heartbeat
    ];
    nodes = {
      heartbeat = {
        package = pkgs.sky360.sky360-ros-iron-heartbeat.pname;
        node = "heartbeat";
        args = [ ];
        rosArgs = [ ];
        params = { };
      };
    };
  };
}

@i-am-logger
Copy link
Author

i-am-logger commented Mar 7, 2024

i tried that:

the inherit pkgs is the issue here

image

I also tried pkgs = pkgs.rosPackages.iron but the package isn't found there

    systemPackages = pkgs: with pkgs; [
      sky360.sky360-ros-iron-heartbeat
    ];

here the package can't be found when i nixos-rebuild switch however this seems to work

    systemPackages = p: with p; [
      pkgs.sky360.sky360-ros-iron-heartbeat
    ];

something is going on weird in how the pkgs overlay works in ros2 it seems

some more info

i tried to look with nix repl .#

with this overlay:

      sky360-ros-packages-overlay = (final: prev: {
        sky360-ros-iron-heartbeat = prev.callPackage ./ros/iron/heartbeat {};
      });
      sky360-packages-overlay = (self: super: {
        rosPackages = super.rosPackages // {
          iron = super.rosPackages.iron.overrideScope sky360-ros-packages-overlay;
        };
      });   

i cant' find the package in nixosConfigurations.cyclop-orangepi5plus.pkgs.rosPackages.iron
and it used to work so its something that changed with latest nixpkgs

when i use the below overlay outside of rosPackages namespace, the package is found with nix repl but not found in runtime by ros2

      sky360-packages-overlay = (final: prev: {
        sky360 = {
          sky360-ros-iron-heartbeat = prev.callPackage ./ros/iron/heartbeat { };
        };
      });

@wentasah
Copy link
Contributor

wentasah commented Mar 8, 2024

I'd temporarily modify modules/ros2/nodes.nix to print the $AMENT_PREFIX_PATH variable before starting ros2 run (or ros2 launch) and look manually, whether the package is really there and whether it has all needed ROS metadata.

@i-am-logger
Copy link
Author

seems this variable isn't defined... i ran /bin/sh -c env

image

@wentasah
Copy link
Contributor

wentasah commented Mar 8, 2024

Yeah, this seems tricky, but I may have some clue what's going on. nodes.nix uses ROS specific buildEnv to construct the environment with the needed packages. By default, buildEnv works by wrapping all binaries in .../bin to set variables like $AMENT_PREFIX_PATH. So in order to start the service correctly, the ros2 command (which is used in the systemd service files) must be in the same buildEnv as the node package. If I read nodes.nix correctly, it attempts to do it, but there might be bugs.

Can you verify that the ros2 command started by the service (ExecStart in your very first screenshot above (BTW sending the text wrapped in ``` would be easier to work with that the screenshots)) is actually a wrapper, which sets AMENT_PREFIX_PATH? Then look into the paths mentioned there and see if your package is in share/ subdirectory of those paths.

@i-am-logger
Copy link
Author

i'll take a deeper look , thank you!

have some errands this weekend but will get to it as soon as i can...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants