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

Implement IRobotControl python bindings #200

Merged
merged 3 commits into from
Feb 23, 2021

Conversation

GiulioRomualdi
Copy link
Member

The PR introduces the python bindings for the IRobotControl and the YARP implementation.

This is a usage example

import bipedal_locomotion_framework.bindings as blf
import time

if __name__ == "__main__":
    handler = blf.StdParametersHandler()
    handler.set_parameter_vector_string("joints_list", ["r_hip_pitch", "r_hip_roll", "r_hip_yaw", "r_knee", "r_ankle_pitch", "r_ankle_roll"])
    handler.set_parameter_vector_string("remote_control_boards", ["right_leg"])
    handler.set_parameter_string("robot_name", "icubSim")
    handler.set_parameter_string("local_prefix", "test_local")
    handler.set_parameter_float("positioning_duration", 3.0)
    handler.set_parameter_float("positioning_tolerance", 0.05)
    handler.set_parameter_float("position_direct_max_admissible_error", 0.1)

    # Create the control board
    control_board = blf.construct_remote_control_board_remapper(handler)
    time.sleep(1)

    # Create the robot control 
    robot_control = blf.YarpRobotControl()
    robot_control.initialize(handler)
    robot_control.set_driver(control_board.poly)

    # Move the robot
    robot_control.set_references([0.8, 0.5, 0.0, 0.0, 0.5, 0.0], \
                                 blf.IRobotControl.ControlMode.Position)
    
    while(1):
        time.sleep(2.0)
        print("I'm alive.")

@GiulioRomualdi GiulioRomualdi added the enhancement New feature or request label Feb 23, 2021
@traversaro
Copy link
Collaborator

In the future it could make sense to ensure that we can compile the blf bindings even if YARP is disabled, but we can see how to do that later.

Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 🚀

Comment on lines +35 to +36
.def_readwrite("key", &PolyDriverDescriptor::key)
.def_readwrite("poly", &PolyDriverDescriptor::poly)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is intended here to have both read and write capabilities?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to replicate the c++ implementation. There they are members of a struct

Copy link
Member

@diegoferigo diegoferigo Feb 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Then, it's up to you if you want to allow and it makes sense from python to override the values. Structs in python are typically mapped as NamedTuple if they are immutable, or dataclass if they are mutable (but they can be made immutable as well, they are more recent that NamedTuples).

I think that pybind creates a full class from a struct, but as said you can decide to make it read-only if it doesn't make sense to update the field after creation.

std::vector<std::pair<std::string, double>> info;
bool isOk = impl.checkMotionDone(motionDone, isTimeExpired, info);

return std::make_tuple(isOk, motionDone, isTimeExpired, info);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a complex output, did you double check in particular that info is mapped to native Python types?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked if I print info it contains data of the form

[('r_hip_pitch', 0.5426321143221097), ('r_ankle_roll', 0.05311822268293803)]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok great!

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

Successfully merging this pull request may close these issues.

3 participants