Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <aubo_new_driver/aubo_hardware_interface.h>
00039
00040
00041 namespace ros_control_aubo {
00042
00043 AuboHardwareInterface::AuboHardwareInterface(ros::NodeHandle& nh, AuboNewDriver* robot) :
00044 nh_(nh), robot_(robot) {
00045
00046 init();
00047
00048 max_vel_change_ = 0.12;
00049
00050 ROS_INFO_NAMED("aubo_hardware_interface", "Loaded aubo_hardware_interface.");
00051 }
00052
00053 void AuboHardwareInterface::init() {
00054 ROS_INFO_STREAM_NAMED("aubo_hardware_interface",
00055 "Reading rosparams from namespace: " << nh_.getNamespace());
00056
00057
00058 nh_.getParam("hardware_interface/joints", joint_names_);
00059 if (joint_names_.size() == 0) {
00060 ROS_FATAL_STREAM_NAMED("aubo_hardware_interface",
00061 "No joints found on parameter server for controller, did you load the proper yaml file?" << " Namespace: " << nh_.getNamespace());
00062 exit(-1);
00063 }
00064 num_joints_ = joint_names_.size();
00065
00066
00067 joint_position_.resize(num_joints_);
00068 joint_velocity_.resize(num_joints_);
00069 joint_effort_.resize(num_joints_);
00070 joint_position_command_.resize(num_joints_);
00071 last_joint_position_command_.resize(num_joints_);
00072 joint_velocity_command_.resize(num_joints_);
00073 prev_joint_velocity_command_.resize(num_joints_);
00074
00075
00076 for (std::size_t i = 0; i < num_joints_; ++i) {
00077 ROS_DEBUG_STREAM_NAMED("aubo_hardware_interface",
00078 "Loading joint name: " << joint_names_[i]);
00079
00080
00081 joint_state_interface_.registerHandle(
00082 hardware_interface::JointStateHandle(joint_names_[i],
00083 &joint_position_[i], &joint_velocity_[i],
00084 &joint_effort_[i]));
00085
00086
00087 position_joint_interface_.registerHandle(
00088 hardware_interface::JointHandle(
00089 joint_state_interface_.getHandle(joint_names_[i]),
00090 &joint_position_command_[i]));
00091
00092
00093 velocity_joint_interface_.registerHandle(
00094 hardware_interface::JointHandle(
00095 joint_state_interface_.getHandle(joint_names_[i]),
00096 &joint_velocity_command_[i]));
00097 prev_joint_velocity_command_[i] = 0.;
00098 }
00099
00100
00101 force_torque_interface_.registerHandle(
00102 hardware_interface::ForceTorqueSensorHandle("wrench", "",
00103 robot_force_, robot_torque_));
00104
00105 registerInterface(&joint_state_interface_);
00106 registerInterface(&position_joint_interface_);
00107 registerInterface(&velocity_joint_interface_);
00108 registerInterface(&force_torque_interface_);
00109 velocity_interface_running_ = false;
00110 position_interface_running_ = false;
00111 }
00112
00113 void AuboHardwareInterface::read() {
00114 std::vector<double> pos, vel, current, tcp;
00115 pos = robot_->rt_interface_->robot_state_->getJonitPosition();
00116 vel = robot_->rt_interface_->robot_state_->getJonitVelocity();
00117 current = robot_->rt_interface_->robot_state_->getJointCurrent();
00118 tcp = robot_->rt_interface_->robot_state_->getTcpForce();
00119 for (std::size_t i = 0; i < num_joints_; ++i) {
00120 joint_position_[i] = pos[i];
00121 joint_velocity_[i] = vel[i];
00122 joint_effort_[i] = current[i];
00123 }
00124 for (std::size_t i = 0; i < 3; ++i) {
00125 robot_force_[i] = tcp[i];
00126 robot_torque_[i] = tcp[i + 3];
00127 }
00128 }
00129
00130 void AuboHardwareInterface::setMaxVelChange(double inp) {
00131 max_vel_change_ = inp;
00132 }
00133
00134 void AuboHardwareInterface::write() {
00135 int i=0;
00136 if (velocity_interface_running_) {
00137 std::vector<double> cmd;
00138
00139 cmd.resize(joint_velocity_command_.size());
00140 for (unsigned int i = 0; i < joint_velocity_command_.size(); i++) {
00141 cmd[i] = joint_velocity_command_[i];
00142 if (cmd[i] > prev_joint_velocity_command_[i] + max_vel_change_) {
00143 cmd[i] = prev_joint_velocity_command_[i] + max_vel_change_;
00144 } else if (cmd[i]
00145 < prev_joint_velocity_command_[i] - max_vel_change_) {
00146 cmd[i] = prev_joint_velocity_command_[i] - max_vel_change_;
00147 }
00148 prev_joint_velocity_command_[i] = cmd[i];
00149 }
00150 robot_->setSpeed(cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], cmd[5], max_vel_change_*125);
00151 }
00152 else if (position_interface_running_) {
00153
00154 for(i=0;i<6;i++)
00155 {
00156 if(fabs(joint_position_command_[i]-last_joint_position_command_[i])>=0.000001)
00157 {
00158 break;
00159 }
00160 }
00161
00162 if(i<6)
00163 {
00164 robot_->servoj(joint_position_command_);
00165 last_joint_position_command_ = joint_position_command_;
00166 }
00167 }
00168 }
00169
00170 bool AuboHardwareInterface::canSwitch(
00171 const std::list<hardware_interface::ControllerInfo> &start_list,
00172 const std::list<hardware_interface::ControllerInfo> &stop_list) const {
00173 for (std::list<hardware_interface::ControllerInfo>::const_iterator controller_it =
00174 start_list.begin(); controller_it != start_list.end();
00175 ++controller_it) {
00176 if (controller_it->type
00177 == "velocity_controllers/JointTrajectoryController") {
00178 if (velocity_interface_running_) {
00179 ROS_ERROR(
00180 "%s: An interface of that type (%s) is already running",
00181 controller_it->name.c_str(),
00182 controller_it->type.c_str());
00183 return false;
00184 }
00185 if (position_interface_running_) {
00186 bool error = true;
00187 for (std::list<hardware_interface::ControllerInfo>::const_iterator stop_controller_it =
00188 stop_list.begin();
00189 stop_controller_it != stop_list.end();
00190 ++stop_controller_it) {
00191 if (stop_controller_it->type
00192 == "position_controllers/JointTrajectoryController") {
00193 error = false;
00194 break;
00195 }
00196 }
00197 if (error) {
00198 ROS_ERROR(
00199 "%s (type %s) can not be run simultaneously with a PositionJointInterface",
00200 controller_it->name.c_str(),
00201 controller_it->type.c_str());
00202 return false;
00203 }
00204 }
00205 } else if (controller_it->type
00206 == "position_controllers/JointTrajectoryController") {
00207 if (position_interface_running_) {
00208 ROS_ERROR(
00209 "%s: An interface of that type (%s) is already running",
00210 controller_it->name.c_str(),
00211 controller_it->type.c_str());
00212 return false;
00213 }
00214 if (velocity_interface_running_) {
00215 bool error = true;
00216 for (std::list<hardware_interface::ControllerInfo>::const_iterator stop_controller_it =
00217 stop_list.begin();
00218 stop_controller_it != stop_list.end();
00219 ++stop_controller_it) {
00220 if (stop_controller_it->type
00221 == "velocity_controllers/JointTrajectoryController") {
00222 error = false;
00223 break;
00224 }
00225 }
00226 if (error) {
00227 ROS_ERROR(
00228 "%s (type %s) can not be run simultaneously with a VelocityJointInterface",
00229 controller_it->name.c_str(),
00230 controller_it->type.c_str());
00231 return false;
00232 }
00233 }
00234 }
00235 }
00236
00237
00238 return true;
00239 }
00240
00241 void AuboHardwareInterface::doSwitch(
00242 const std::list<hardware_interface::ControllerInfo>& start_list,
00243 const std::list<hardware_interface::ControllerInfo>& stop_list) {
00244 for (std::list<hardware_interface::ControllerInfo>::const_iterator controller_it =
00245 stop_list.begin(); controller_it != stop_list.end();
00246 ++controller_it) {
00247 if (controller_it->type
00248 == "velocity_controllers/JointTrajectoryController") {
00249 velocity_interface_running_ = false;
00250 ROS_DEBUG("Stopping velocity interface");
00251 }
00252 if (controller_it->type
00253 == "position_controllers/JointTrajectoryController") {
00254 position_interface_running_ = false;
00255 std::vector<double> tmp;
00256 robot_->closeServo(tmp);
00257 ROS_DEBUG("Stopping position interface");
00258 }
00259 }
00260 for (std::list<hardware_interface::ControllerInfo>::const_iterator controller_it =
00261 start_list.begin(); controller_it != start_list.end();
00262 ++controller_it) {
00263
00264 if (controller_it->type
00265 == "velocity_controllers/JointTrajectoryController") {
00266 velocity_interface_running_ = true;
00267 ROS_DEBUG("Starting velocity interface");
00268 }
00269 if (controller_it->type
00270 == "position_controllers/JointTrajectoryController") {
00271 position_interface_running_ = true;
00272 robot_->openServo();
00273 ROS_DEBUG("Starting position interface");
00274 }
00275 }
00276
00277 }
00278
00279 }
00280