Skip to content

Commit

Permalink
Fixed bugs related to controlBoard implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Oct 29, 2013
1 parent 42a502f commit 0c419f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
28 changes: 12 additions & 16 deletions include/coman.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ class yarp::dev::coman : public DeviceDriver,

~coman()
{
delete [] control_mode;
delete [] motion_done;
}

/**
Expand All @@ -84,15 +82,12 @@ class yarp::dev::coman : public DeviceDriver,
}
}
pos_lock.lock();
// read sensors (for now only joints angle)
auto joints=_robot->GetJoints();
int j=0;
for (auto joint:joints)
{
pos[j]=joint->GetAngle(0).Degree(); //TODO: if zero_pos=0, it works, if zero_pos=pos[j], pos[j] return 0, if zero_pos=k, pos[j]return 0-k, but since it is an angle, you may get 2*pi
//std::cout<<"joint"<<j<<" pos"<<pos[j]<<std::endl;
j++;

for(int jnt_cnt=0; jnt_cnt < joint_names.size(); jnt_cnt++ ) {
/** \todo consider multi-dof joint ? */
pos[jnt_cnt] = this->_robot->GetJoint(joint_names[jnt_cnt])->GetAngle(0).Degree();

This comment has been minimized.

Copy link
@MirkoFerrati

MirkoFerrati Oct 29, 2013

Contributor

Silvio, the code that reads the position is executed at every simulation cycle, please consider caching the value returned from robot->GetJoint so that you don't have to access a map and a vector everytime. We don't know if the compiler is smart enough to understand what you are doing and apply optimization to the code in order to automatically cache values.

This comment has been minimized.

Copy link
@traversaro

traversaro Oct 29, 2013

Author Member

Definitly to do.

}

pos_lock.unlock();
// send positions to the actuators
_clock++;
Expand Down Expand Up @@ -120,8 +115,9 @@ class yarp::dev::coman : public DeviceDriver,
else
motion_done[j]=true;
std::cout<<"pos: "<<pos[j]<<" ref_pos: "<<ref_pos[j]<<" ref_speed: "<<ref_speed[j]<<" period: "<<robot_refresh_period<<" result: "<<temp<<std::endl;
sendPositionToGazebo(j,temp);
}
sendPositionToGazebo(j,temp);

}
}
}
}
Expand Down Expand Up @@ -317,6 +313,8 @@ class yarp::dev::coman : public DeviceDriver,

virtual bool close() //NOT IMPLEMENTED
{
delete [] control_mode;
delete [] motion_done;
return true;
}

Expand Down Expand Up @@ -586,12 +584,10 @@ class yarp::dev::coman : public DeviceDriver,
void setMinMaxPos() //NOT TESTED
{
std::cout<<"Joint Limits"<<std::endl;
gazebo::physics::Joint_V joints = _robot->GetJoints();
for(unsigned int i = 0; i < _robot_number_of_joints; ++i)
{
gazebo::physics::JointPtr j = joints[i];
max_pos[i] = j->GetUpperLimit(0).Degree();
min_pos[i] = j->GetLowerLimit(0).Degree();
max_pos[i] = this->_robot->GetJoint(joint_names[i])->GetUpperLimit(0).Degree();
min_pos[i] = this->_robot->GetJoint(joint_names[i])->GetLowerLimit(0).Degree();
std::cout<<joint_names[i]<<" max_pos: "<<max_pos[i]<<" min_pos: "<<min_pos[i]<<std::endl;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/coman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void coman::gazebo_init()
ref_acc.size(_robot_number_of_joints);
max_pos.resize(_robot_number_of_joints);
min_pos.size(_robot_number_of_joints);
joint_names.reserve(_robot_number_of_joints);
_p.reserve(_robot_number_of_joints);
_i.reserve(_robot_number_of_joints);
_d.reserve(_robot_number_of_joints);
Expand Down

0 comments on commit 0c419f9

Please sign in to comment.