ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

how can i migrate ros1 hw to ros2 hw

asked 2022-10-12 08:54:50 -0500

omeranar1 gravatar image

Hello there
I am trying to switch from ros1 melodic version to ros2 humble version.
I'm stuck on the hardware interface and controller manager.

how can i migrate ros1 hw to ros2 hw
this is my hw;

#include <Hardwares/KRVizHWInterface.h>
extern KPyGlobals kPyGlobals;

KRVizHWInterface::KRVizHWInterface( ros::NodeHandle& nh ) : nh_( nh )
{
    init();
    controller_manager_.reset( new controller_manager::ControllerManager( this, nh_ ) );
    ros::Duration update_freq = ros::Duration( 1.0 / 3000 );
    non_realtime_loop_ = nh_.createTimer( update_freq, &KRVizHWInterface::callBack, this );
}

KRVizHWInterface::~KRVizHWInterface() {}

void KRVizHWInterface::init()
{
    // Get joint names
    ROS_INFO( "initializing..." );

    position_state.resize( JOINT_COUNT );
    velocity_state.resize( JOINT_COUNT );
    effort_state.resize( JOINT_COUNT );

    position_command.resize( JOINT_COUNT );
    // Initialize Controllers
    for ( int i = 0; i < JOINT_COUNT; ++i )
    {
        hardware_interface::JointStateHandle jointStateHandle( JOINT_NAMES[i], &position_state[i], &velocity_state[i], &effort_state[i] );
        joint_state_interface_.registerHandle( jointStateHandle );

        hardware_interface::JointHandle jointPositionHandle( jointStateHandle, &position_command[i] );
        JointLimits limits;

        SoftJointLimits softLimits;
        getJointLimits( JOINT_NAMES[i], nh_, limits );
        PositionJointSoftLimitsHandle jointLimitsHandle( jointPositionHandle, limits, softLimits );
        position_joint_interface_.registerHandle( jointPositionHandle );
        positionJointSoftLimitsInterface.registerHandle( jointLimitsHandle );
    }

    registerInterface( &joint_state_interface_ );
    registerInterface( &position_joint_interface_ );
    registerInterface( &positionJointSoftLimitsInterface );
    ROS_INFO( "All joints handeled." );
}

void KRVizHWInterface::callBack( const ros::TimerEvent& e )
{
    elapsed_time_ = ros::Duration( e.current_real - e.last_real );
    ////////////////////////////////////////////////////////////////////////
    for ( int i = 0; i < JOINT_COUNT; i++ )
        position_state[i] = kPyGlobals.USB.recv_Angles[i] * deg2rad;
    ////////////////////////////////////////////////////////////////////////
    controller_manager_->update( ros::Time::now(), elapsed_time_ );
    ////////////////////////////////////////////////////////////////////////
    positionJointSoftLimitsInterface.enforceLimits( elapsed_time_ );
    for ( int i = 0; i < JOINT_COUNT; i++ )
        kPyGlobals.recv_RVizAngles_INFO[i] = position_command[i] * rad2deg;
}

this is my starter;

ros::NodeHandle nh;
KRVizHWInterface rhi( nh );
ros::AsyncSpinner spinner( ASYNC_COUNT );
spinner.start();
ros::waitForShutdown();
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-10-12 12:14:56 -0500

duck-development gravatar image

You may read the guide

How to migrate from ros1 to ros2 controller

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-10-12 08:54:50 -0500

Seen: 127 times

Last updated: Oct 12 '22