1 #ifndef single_leg_controller_h
2 #define single_leg_controller_h
6 #include "std_msgs/Empty.h"
7 #include "std_msgs/Bool.h"
8 #include "std_msgs/Float64.h"
9 #include "std_msgs/Float64MultiArray.h"
10 #include "sensor_msgs/JointState.h"
11 #include "eigen_conversions/eigen_msg.h"
94 const double &_percentage,
95 const double &_period,
96 const double &_max_travel,
119 const Eigen::Matrix<double, 3, 1> &_joint_pos_ref,
120 const Eigen::Matrix<double, 3, 1> &_joint_vel_ref,
121 const Eigen::Matrix<double, 3, 1> &_joint_acc_ref,
122 const Eigen::Matrix<double, 3, 1> &_joint_pos,
123 const Eigen::Matrix<double, 3, 1> &_joint_vel
158 public:
void setPoseGoal(Eigen::Matrix<double, 3, 1> _foot_pos);
221 private: Eigen::Matrix<double, 3, 1>
foot_pos_ref = Eigen::Matrix<double, 3, 1>::Zero();
224 private: Eigen::Matrix<double, 3, 1>
foot_vel_ref = Eigen::Matrix<double, 3, 1>::Zero();
227 private: Eigen::Matrix<double, 3, 1>
foot_acc_ref = Eigen::Matrix<double, 3, 1>::Zero();
230 private: Eigen::Matrix<double, 3, 1>
foot_pos_goal = Eigen::Matrix<double, 3, 1>::Zero();
233 private: Eigen::Matrix<double, 3, 1>
joint_pos_goal = Eigen::Matrix<double, 3, 1>::Zero();
239 private: Eigen::Matrix<double, 3, 1>
joint_pos = Eigen::Matrix<double, 3, 1>::Zero();
242 private: Eigen::Matrix<double, 3, 1>
joint_vel = Eigen::Matrix<double, 3, 1>::Zero();
245 private: Eigen::Matrix<double, 3, 1>
joint_torque = Eigen::Matrix<double, 3, 1>::Zero();
248 private: Eigen::Matrix<double, 3, 1>
joint_pos_ref = Eigen::Matrix<double, 3, 1>::Zero();
251 private: Eigen::Matrix<double, 3, 1>
joint_vel_ref = Eigen::Matrix<double, 3, 1>::Zero();
254 private: Eigen::Matrix<double, 3, 1>
joint_acc_ref = Eigen::Matrix<double, 3, 1>::Zero();
257 private: Eigen::Matrix<double, 3, 1>
joint_torque_ref = Eigen::Matrix<double, 3, 1>::Zero();
311 private: Eigen::Matrix<double, 3, 3>
K_p = Eigen::Matrix<double, 3, 3>::Zero();
314 private: Eigen::Matrix<double, 3, 3>
K_d = Eigen::Matrix<double, 3, 3>::Zero();
A class for analytical Kinematics Solving.
const int NUMBER_OF_MOTORS
The number of motors used in single leg control tests.
Eigen::Matrix< double, 3, 1 > foot_pos_goal
When using setpointTrajectory control these are the joint angles we want to reach eventually.
double k_p_torque_kp
Knee pitch motor torque control proportional gain.
ros::Subscriber motor_confirmation_subscriber
Subscribes to confirmation messages from the motor.
double max_swing_height
The maximum height above the ground to lift the foot.
void writeToLog()
Write the joint references and estimated states to the log.
ros::Subscriber generalized_forces_subscriber
Subscribes to generalized forces messages.
std::unique_ptr< ros::NodeHandle > node_handle
ROS node handle.
double k_i_torque_hp
Hip pitch motor torque control integral gain.
GaitPhase getGaitPhase()
Return the leg's phase state.
void jointSetpointCallback(const std_msgs::Float64MultiArrayConstPtr &_msg)
Listens to joint setpoints messages.
double max_pose_vel
Max pose control joint angle velocity [rad/s].
Eigen::Matrix< double, 3, 1 > joint_torque_ref
The reference joint torques for the motors.
void updateJointVelocityCommands()
Updates the joint velocity control commands based on the joint velocity reference and the joint posit...
virtual ~SingleLegController()
Destructor.
Eigen::Matrix< double, 3, 1 > joint_vel_ref
The reference joint velocities for the motors.
void setMotorGains()
Tries to set the control gains in the motors. The function loops until it succeeds.
double k_p_torque_hp
Hip pitch motor torque control proportional gain.
void printJointTrajectories()
Print the joint trajectory references.
double k_p_torque_hy
Hip yaw motor torque control proportional gain.
ros::Publisher log_joint_references_publisher
Publishes joint position references for logging.
sensor_msgs::JointState motor_command_msg
The joint state message that is sent to the Teensy.
void printAllStates()
Print various information about all joints.
double publish_frequency
The expected publish frequency of the robot. This is used to calculate the maximum number of iteratio...
void updateFootTrajectoryReference()
Update the foot trajectory based on the leg state.
const double POSITION_CONVERGENCE_CRITERIA
Convergence crieria for position control test.
Eigen::Matrix< double, 3, 1 > foot_acc_ref
The foot acceleration reference relative to the hip.
double k_p_vel_hy
Hip yaw joint motor velocity control proportional gain.
void updateClosedLoopTorqueCommands()
A non model based torque controller.
void printSpatialTrajectories()
Print the foot trajectory reference.
Eigen::Matrix< double, 3, 1 > joint_torque
The estimated joint torques of the motors.
Eigen::Matrix< double, 3, 1 > joint_pos_goal
The joint angles we want to eventually reach when using pose trajectory control.
Eigen::Matrix< double, 3, 1 > joint_torque_commands
The joint torque command being sent to the motors.
double k_i_vel_hp
Hip pitch joint motor velocity control integral gain.
double k_i_vel_hy
Hip yaw joint motor velocity control integral gain.
double k_i_torque_kp
Knee pitch motor torque control integral gain.
double final_pose_iteration
The final iteration used for pose control.
bool moveFootToNominalPosition()
The function tries to move the foot to the nominal trajectory position.
Eigen::Matrix< double, 3, 1 > joint_pos
The estimated joint angles of the motors.
Eigen::Matrix< double, 3, 1 > joint_acc_ref
The reference joint accelerations for the motors.
ros::Subscriber ready_to_proceed_subscriber
Subscribes to messages deciding whether or not we should proceed in the script.
void updateStanceFootPositionTrajectory()
Update the stance foot tractory for the leg.
ros::Publisher log_joint_states_publisher
Publishes joint positions for logging.
Eigen::Matrix< double, 3, 1 > joint_pos_ref
The reference joint angles for the motors.
const double POSITION_COMMAND
The identifier to be used for position command messages.
double k_p_vel_hp
Hip pitch joint motor velocity control proportional gain.
ros::Subscriber generalized_velocities_subscriber
Subscribes to generalized velocities messages.
ros::Publisher joint_state_publisher
Publishes velocity commands to the teensy to control the motors.
Kinematics kinematics
Kinematics object.
void printTorqueReferences()
Print the joint torque references.
ros::Subscriber generalized_coordinates_subscriber
Subscribes to generalized coordinates messages.
double k_p_pos_kp
Knee pitch joint motor position control proportional gain.
void generalizedForcesCallback(const std_msgs::Float64MultiArrayConstPtr &_msg)
Listens to joint force messages from the simulated leg.
double phase_period
The duration of a phase period in seconds.
bool gains_set
Keeps track of whether or not the motor gains have been set.
double k_p_vel_kp
Knee pitch joint motor velocity control proportional gain.
ros::Subscriber joint_setpoint_subscriber
Subscribes to joint setpoint messages.
Eigen::Matrix< double, 3, 3 > K_d
A diagonal matrix of derivative gains for the closed loop torque controller.
Eigen::Matrix< double, 3, 1 > joint_vel
The estimated joint velocities of the motors.
void jointStateCallback(const sensor_msgs::JointStatePtr &_msg)
Listens to joint state messages from the motors The messages contains joint angles,...
void resetReadyToProceed()
Set the ready_to_proceed flag to false.
Eigen::Matrix< double, 3, 1 > foot_pos_ref
The foot position reference relative to the hip.
void initROS()
This function initilizes ROS.
SingleLegController(double _publish_frequency)
Constructor.
void sendJointVelocityCommands()
Updates the joint velocity commands and send them to the motors.
void sendJointPositionCommands()
Sends a joint position commands to the motors.
double x_step_distance
The step distance in the x direction.
bool updatePoseControlJointTrajectoryReference()
Update the pose control trajectory reference for the single leg.
bool isInitialStateReceived()
Check if the uninitalized joint state of the robot has been overridden by measurements.
double current_pose_iteration
The current iteration used for pose control.
double k_p_pos_hp
Hip pitch joint motor position control proportional gain.
double hip_height
The standard height of the hips above the ground.
Eigen::Matrix< double, 3, 1 > calculateSwingLegHeightTrajectory(double _percentage, double _period, double _max_swing_height, double _hip_height)
This function calculates the swing leg height trajectory based on various gait cycle parameters.
const double TORQUE_COMMAND
The identifier to be used for torque command messages.
void motorConfirmationCallback(const std_msgs::Bool &_msg)
Listens to a confirmation message from the motors which is used to indicate if the motor gains have b...
double final_iteration
The final iteration of a gait phase.
bool isJointVelocitySmall()
Checks if the sum of squared joint velocities are smaller than a certain threshold.
void updateSwingFootPositionTrajectory()
Update the swing foot trajectory for the leg.
void setPoseGoal(Eigen::Matrix< double, 3, 1 > _foot_pos)
Set the final and initial states for pose control trajectories.
double y_step_distance
The step distance in the y direction.
sensor_msgs::JointState joint_state_log_msg
The joint state message that is used to log states.
double k_i_pos_hy
Hip yaw joint motor position control integral gain.
double k_i_torque_hy
Hip yaw motor torque control integral gain.
Eigen::Matrix< double, 3, 1 > foot_vel_ref
The foot velocity reference relative to the hip.
void updateJointReferences()
Update The joint trajectory reference based on the spatial foot trajectory.
ros::Subscriber joint_state_subscriber
Subscribes to joint state messages from the motors.
double current_iteration
The current iteration in a gait phase. This should be incremented for every control loop.
void generalizedVelocitiesCallback(const std_msgs::Float64MultiArrayConstPtr &_msg)
Listens to joint velocity messages from the simulated leg.
Eigen::Matrix< double, 3, 3 > K_p
A diagonal matrix of proportional gains for the closed loop torque controller.
ros::Publisher motor_gain_publisher
Publishes desired motor gains to the motors.
bool moveJointsToSetpoints()
The function tries to move the foot to the foot position given by the input parameters.
Eigen::Matrix< double, 3, 1 > joint_pos_initial
The joint angles at the beginning of a trajectory.
const double VELOCITY_COMMAND
The identifier to be used for velocity command messages.
bool ready_to_proceed
A variable used to control the flow of the program. It can be set throuh a boolean message received b...
sensor_msgs::JointState joint_reference_log_msg
The joint state message that is used to log references.
bool updateGaitPhase()
Increments the gait cycle iterator and updates the leg state.
bool moveFootToPosition(Eigen::Matrix< double, 3, 1 > _foot_goal_pos)
Creates a trajectory from the current foot position to the goal foot position and moves the foot to t...
void increaseIterator()
Increment the gait cycle iterator. It stops iterating when the final iteration is reached.
double k_p_pos_hy
Hip yaw joint motor position control proportional gain.
void readyToProceedCallback(const std_msgs::Bool &_msg)
The ready_to_proceed parameter is changed based on the incomming message.
void sendJointTorqueCommands()
Updates the joint torque control commands based on the desired foot position.
void checkForNewMessages()
Function used to check if any new ROS messages has been received.
void updateJointTorqueCommands()
Overloaded function that uses the current joint references and joint states.
double y_nominal
The nominal y position of the foot relative to the hip.
void generalizedCoordinatesCallback(const std_msgs::Float64MultiArrayConstPtr &_msg)
Listens to joint angle messages from the simulated leg.
double pose_period
The time used to change from one pose to the next.
bool isTargetPositionReached()
Check if the squared error between the current joint angles and target joint angles is smaller than s...
double k_i_pos_kp
Knee pitch joint motor position control integral gain.
const double UNINITIALIZED_STATE
The value of an uninitialized state.
Eigen::Matrix< double, 3, 1 > joint_vel_commands
The velocity commands sent to the motors.
Eigen::Matrix< double, 3, 3 > K_pos_error_vel_control
A digonal matrix for of gains used for the position error in the closed loop velocity controller.
double k_i_pos_hp
Hip pitch joint motor position control integral gain.
GaitPhase gait_phase
The current gait phase of the leg.
void calculateSingleAxisTrajectory(const double &_percentage, const double &_period, const double &_max_travel, double &_axis_pos, double &_axis_vel, double &_axis_acc)
This functions calculates a smooth trajectory along a single linear axis. Please see the report for d...
bool readyToProceed()
Check whether or not a ready to proceed message has been received.
double x_nominal
The nominal x position of the foot relative to the hip.
double k_i_vel_kp
Knee pitch joint motor velocity control integral gain.
double degToRad(const double &_deg)
The degToRad function converts degrees to radians.