Robotics StackExchange | Archived questions

ROS2 Odometry (Communication With Beckhoff PLC)

Hello. I am using ROS2. And my hardware interface communicate with beckhoff PLC. And my odometry is coming bad. I moved one meter. And odom is coming one meter. But when rotate and one more tour. Mistakes are increase.

More Information : My PLC is working with one ms. I use ADS Package for communicate.

And motor position are calculate in PLC and its coming from driver. When I look the motor_pos(from plc) and turn wheels its coming good to ROS.

My Basic Params.yaml

controllermanager: rosparameters: updaterate: 50 usesimtime: false # true

robovak_diff_drive_controller:
  type: diff_drive_controller/DiffDriveController

joint_state_broadcaster:
  type: joint_state_broadcaster/JointStateBroadcaster

robovakdiffdrivecontroller: ros_parameters:

publish_rate: 50.0
base_frame_id: base_footprint # base_link
left_wheel_names: ['left_wheel_joint']
right_wheel_names: ['right_wheel_joint']
wheel_separation: 0.487
wheel_radius: 0.0820
pose_covariance_diagonal: [0.001, 0.001, 1000000.0, 1000000.0, 1000000.0, 1000.0]
twist_covariance_diagonal: [0.001, 0.001, 1000000.0, 1000000.0, 1000000.0, 1000.0]
# open_loop: true
enable_odom_tf: false

cmd_vel_timeout: 0.5
#publish_limited_velocity: true
use_stamped_vel: false
#velocity_rolling_window_size: 10

# Velocity and acceleration limits
# Whenever a min_* is unspecified, default to -max_*
linear.x.has_velocity_limits: true
linear.x.has_acceleration_limits: true
linear.x.has_jerk_limits: false
linear.x.max_velocity: 0.3
linear.x.min_velocity: -0.3
linear.x.max_acceleration: 0.3
linear.x.min_acceleration: -0.3
linear.x.max_jerk: 5.0
linear.x.min_jerk: 0.0

angular.z.has_velocity_limits: true
angular.z.has_acceleration_limits: true
angular.z.has_jerk_limits: false
angular.z.max_velocity: 0.5
angular.z.min_velocity: -0.5
angular.z.max_acceleration: 0.6
angular.z.min_acceleration: -0.6
angular.z.max_jerk: 0.0
angular.z.min_jerk: 0.0

Hardware Interface Read

hardware_interface::return_type RobovakDiffDrive::read(const rclcpp::Time & time, const rclcpp::Duration & period)
{

  // Calculate time delta
  emergency = com->isEmergencyActive();
  auto new_time = std::chrono::system_clock::now();
  std::chrono::duration<double> diff = new_time - time_;
  double deltaSeconds = diff.count();
  time_ = new_time;
  com->ReadData(readData_);

  l_wheel_.en_diff = com->getMotorPositionData().first - l_wheel_.enc;
  r_wheel_.en_diff = com->getMotorPositionData().second - r_wheel_.enc;

  l_wheel_.enc = com->getMotorPositionData().first;
  r_wheel_.enc = com->getMotorPositionData().second;

  l_wheel_.pos = com->getMotorPositionData().first * 2 * M_PI;
  r_wheel_.pos = com->getMotorPositionData().second * 2 * M_PI;

  if (deltaSeconds > 0)
  {
    // if (use_encoder_velocity)
    // {
      l_wheel_.vel = (com->getMotorVelocityData().first * (2 * M_PI)) / 60;
      r_wheel_.vel = (com->getMotorVelocityData().second * (2 * M_PI)) / 60;

Asked by bextap on 2023-05-17 09:22:17 UTC

Comments

Answers