-
Notifications
You must be signed in to change notification settings - Fork 90
Allow to change to torque control mode #1326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 22 commits
91ec2f2
108fb6b
3eb9a0f
0a39c13
8846a8b
228ce6f
ef3910b
e3adcb7
e827887
4ede167
9c750dc
81d2f79
cee9a70
6584025
b8d1516
cbed8f4
134ec67
84941fc
ea83f7a
64ddc71
53e70f4
34c8f9f
d068033
42f6519
d8d245f
b439493
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,6 +175,42 @@ extern "C"{ | |
| */ | ||
| int write_angle_offset(int id, double offset); | ||
|
|
||
| /** | ||
| * @brief read lower joint limit[rad] | ||
| * @param id joint id | ||
| * @param angle lower joint limit[rad] | ||
| * @retval TRUE this function is supported | ||
| * @retval FALSE otherwise | ||
| */ | ||
| int read_llimit_angle(int id, double *angle); | ||
|
|
||
| /** | ||
| * @brief read upper joint limit[rad] | ||
| * @param id joint id | ||
| * @param angle upper joint limit[rad] | ||
| * @retval TRUE this function is supported | ||
| * @retval FALSE otherwise | ||
| */ | ||
| int read_ulimit_angle(int id, double *angle); | ||
|
|
||
| /** | ||
| * @brief write lower joint limit[rad] | ||
| * @param id joint id | ||
| * @param angle lower joint limit[rad] | ||
| * @retval TRUE this function is supported | ||
| * @retval FALSE otherwise | ||
| */ | ||
| int write_llimit_angle(int id, double angle); | ||
|
|
||
| /** | ||
| * @brief write upper joint limit[rad] | ||
| * @param id joint id | ||
| * @param angle upper joint limit[rad] | ||
| * @retval TRUE this function is supported | ||
| * @retval FALSE otherwise | ||
| */ | ||
| int write_ulimit_angle(int id, double angle); | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these necessary? They are not called in this PR.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fkanehiro In this PR they are not used, but in the
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If they are not relevant to this PR, I think they should be removed from this PR. In addition, as adding APIs will break compatibility, you need to use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it... I have removed these APIs in d8d245f |
||
| //@} | ||
|
|
||
| // @name joint | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ RobotHardware::RobotHardware(RTC::Manager* manager) | |
| m_dqRefIn("dqRef", m_dqRef), | ||
| m_ddqRefIn("ddqRef", m_ddqRef), | ||
| m_tauRefIn("tauRef", m_tauRef), | ||
| m_torqueControlModeIn("torqueControlMode", m_torqueControlMode), | ||
| m_qOut("q", m_q), | ||
| m_dqOut("dq", m_dq), | ||
| m_tauOut("tau", m_tau), | ||
|
|
@@ -61,7 +62,8 @@ RobotHardware::RobotHardware(RTC::Manager* manager) | |
| m_rstate2Out("rstate2", m_rstate2), | ||
| m_RobotHardwareServicePort("RobotHardwareService"), | ||
| // </rtc-template> | ||
| dummy(0) | ||
| allowTorqueControlMode(true), | ||
|
||
| dummy(0) | ||
| { | ||
| } | ||
|
|
||
|
|
@@ -79,6 +81,7 @@ RTC::ReturnCode_t RobotHardware::onInitialize() | |
| addInPort("dqRef", m_dqRefIn); | ||
| addInPort("ddqRef", m_ddqRefIn); | ||
| addInPort("tauRef", m_tauRefIn); | ||
| addInPort("torqueControlMode", m_torqueControlModeIn); | ||
|
|
||
| addOutPort("q", m_qOut); | ||
| addOutPort("dq", m_dqOut); | ||
|
|
@@ -145,6 +148,7 @@ RTC::ReturnCode_t RobotHardware::onInitialize() | |
| m_dqRef.data.length(m_robot->numJoints()); | ||
| m_ddqRef.data.length(m_robot->numJoints()); | ||
| m_tauRef.data.length(m_robot->numJoints()); | ||
| m_torqueControlMode.data.length(m_robot->numJoints()); | ||
|
|
||
| int ngyro = m_robot->numSensors(Sensor::RATE_GYRO); | ||
| std::cout << "the number of gyros = " << ngyro << std::endl; | ||
|
|
@@ -248,7 +252,7 @@ RTC::ReturnCode_t RobotHardware::onExecute(RTC::UniqueId ec_id) | |
| m_emergencySignalOut.write(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (m_qRefIn.isNew()){ | ||
| m_qRefIn.read(); | ||
|
|
@@ -281,6 +285,14 @@ RTC::ReturnCode_t RobotHardware::onExecute(RTC::UniqueId ec_id) | |
| // output to iob | ||
| m_robot->writeTorqueCommands(m_tauRef.data.get_buffer()); | ||
| } | ||
| if (m_torqueControlModeIn.isNew()){ | ||
| m_torqueControlModeIn.read(); | ||
| if (allowTorqueControlMode){ | ||
| for (unsigned int i=0; i<m_robot->numJoints(); ++i){ | ||
| m_robot->setJointControlMode(m_robot->joint(i)->name.c_str(), m_torqueControlMode.data[i] ? JCM_TORQUE : JCM_POSITION); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // read from iob | ||
| m_robot->readJointAngles(m_q.data.get_buffer()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| #include <rtm/idl/ExtendedDataTypesSkel.h> | ||
|
|
||
| #include <hrpModel/Body.h> | ||
| #include <hrpModel/Link.h> | ||
|
|
||
| // Service implementation headers | ||
| // <rtc-template block="service_impl_h"> | ||
|
|
@@ -140,7 +141,12 @@ class RobotHardware | |
| */ | ||
| TimedDoubleSeq m_tauRef; | ||
| InPort<TimedDoubleSeq> m_tauRefIn; | ||
|
|
||
| /** | ||
| \brief array of booleans indicating which joint is in torque mode (1) or position mode (0) | ||
| */ | ||
| TimedBooleanSeq m_torqueControlMode; | ||
| InPort<TimedBooleanSeq> m_torqueControlModeIn; | ||
|
|
||
| // </rtc-template> | ||
|
|
||
| /** | ||
|
|
@@ -216,7 +222,9 @@ class RobotHardware | |
| robot *robot_ptr(void) { return m_robot.get(); }; | ||
| private: | ||
| void getStatus2(OpenHRP::RobotHardwareService::RobotState2 &rstate2); | ||
|
|
||
|
|
||
| bool allowTorqueControlMode; // Added by Rafa | ||
|
|
||
|
||
| int dummy; | ||
| boost::shared_ptr<robot> m_robot; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -665,9 +665,11 @@ bool robot::checkJointCommands(const double *i_commands) | |
| bool robot::checkEmergency(emg_reason &o_reason, int &o_id) | ||
| { | ||
| int state; | ||
| joint_control_mode mode; // Added by Rafa | ||
| for (unsigned int i=0; i<numJoints(); i++){ | ||
| read_servo_state(i, &state); | ||
| if (state == ON && m_servoErrorLimit[i] != 0){ | ||
| read_control_mode(i, &mode); // Added by Rafa | ||
| if (state == ON && m_servoErrorLimit[i] != 0 && mode != JCM_TORQUE){ // Modified by Rafa | ||
| double angle, command; | ||
| read_actual_angle(i, &angle); | ||
| read_command_angle(i, &command); | ||
|
|
@@ -1048,18 +1050,18 @@ bool robot::setJointControlMode(const char *i_jname, joint_control_mode mode) | |
| for (int i=0; i < numJoints(); i++) { | ||
| write_control_mode(i, mode); | ||
| } | ||
| std::cerr << "[RobotHardware] setJointControlMode for all joints : " << mode << std::endl; | ||
| // std::cerr << "[RobotHardware] setJointControlMode for all joints : " << mode << std::endl; // Commented out by Rafa | ||
|
||
| } else if ((l = link(i_jname)) && (l->jointId >= 0)) { | ||
| write_control_mode(l->jointId, mode); | ||
| std::cerr << "[RobotHardware] setJointControlMode for " << i_jname << " : " << mode << std::endl; | ||
| // std::cerr << "[RobotHardware] setJointControlMode for " << i_jname << " : " << mode << std::endl; // Commented out by Rafa | ||
| } else { | ||
| char *s = (char *)i_jname; while(*s) { *s=toupper(*s); s++; } | ||
| const std::vector<int> jgroup = m_jointGroups[i_jname]; | ||
| if (jgroup.size()==0) return false; | ||
| for (unsigned int i=0; i<jgroup.size(); i++) { | ||
| write_control_mode(jgroup[i], mode); | ||
| } | ||
| std::cerr << "[RobotHardware] setJointControlMode for " << i_jname << " : " << mode << std::endl; | ||
| // std::cerr << "[RobotHardware] setJointControlMode for " << i_jname << " : " << mode << std::endl; // Commented out by Rafa | ||
| } | ||
| return true; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to minimize diff.