Skip to content
Open
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
2 changes: 2 additions & 0 deletions sr_robot_lib/include/sr_robot_lib/sr_joint_motor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ struct Joint
sr_math_utils::filters::LowPassFilter pos_filter;
// used to filter the effort
sr_math_utils::filters::LowPassFilter effort_filter;
// used to filter the position and the velocity of a second joint
sr_math_utils::filters::LowPassFilter pos_filter_2;

bool has_actuator;
boost::shared_ptr<SrActuatorWrapper> actuator_wrapper;
Expand Down
11 changes: 11 additions & 0 deletions sr_robot_lib/src/sr_motor_hand_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ namespace shadow_robot
joint.joint_name = joint_names[index];
joint.joint_to_sensor = joint_to_sensors[index];

if ((!joint.joint_to_sensor.calibrate_after_combining_sensors)
&& (joint.joint_to_sensor.joint_to_sensor_vector.size() == 2))
{
joint.pos_filter_2 = sr_math_utils::filters::LowPassFilter(tau);
}

full_param << act_name << "/effort_filter/tau";
this->nodehandle_.template param<float>(full_param.str(), tau, 0.05);
full_param.str("");
joint.effort_filter = sr_math_utils::filters::LowPassFilter(tau);

if (actuator_ids[index] != -1)
{
joint.has_actuator = true;
Expand Down
39 changes: 32 additions & 7 deletions sr_robot_lib/src/sr_motor_robot_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,13 +1024,38 @@ namespace shadow_robot
// calibrate the joint and update the position.
calibrate_joint(joint_tmp, status_data);

// filter the position and velocity
pair<double, double> pos_and_velocity = joint_tmp->pos_filter.compute(actuator->motor_state_.position_unfiltered_,
timestamp);
// reset the position to the filtered value
actuator->state_.position_ = pos_and_velocity.first;
// set the velocity to the filtered velocity
actuator->state_.velocity_ = pos_and_velocity.second;
if ((!joint_tmp->joint_to_sensor.calibrate_after_combining_sensors)
&& (joint_tmp->joint_to_sensor.joint_to_sensor_vector.size() == 2))
{
actuator->motor_state_.filtered_calibrated_position_values_.clear();
actuator->motor_state_.filtered_calibrated_velocity_values_.clear();

// filter the position and velocity
pair<double, double> pos_and_velocity = joint_tmp->pos_filter.compute(actuator->motor_state_.calibrated_sensor_values_[0],
timestamp);
// set the position to the filtered value
actuator->motor_state_.filtered_calibrated_position_values_.push_back(pos_and_velocity.first);
// set the velocity to the filtered velocity
actuator->motor_state_.filtered_calibrated_velocity_values_.push_back(pos_and_velocity.second);

// filter the position and velocity for the second joint
pos_and_velocity = joint_tmp->pos_filter_2.compute(actuator->motor_state_.calibrated_sensor_values_[1],
timestamp);
// set the position to the filtered value for the second joint
actuator->motor_state_.filtered_calibrated_position_values_.push_back(pos_and_velocity.first);
// set the velocity to the filtered velocity for the second joint
actuator->motor_state_.filtered_calibrated_velocity_values_.push_back(pos_and_velocity.second);
}
else
{
// filter the position and velocity
pair<double, double> pos_and_velocity = joint_tmp->pos_filter.compute(actuator->motor_state_.position_unfiltered_,
timestamp);
// reset the position to the filtered value
actuator->state_.position_ = pos_and_velocity.first;
// set the velocity to the filtered velocity
actuator->state_.velocity_ = pos_and_velocity.second;
}
}

template<class StatusType, class CommandType>
Expand Down