Skip to content
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

added test file for joint torque control #4

Open
wants to merge 1 commit into
base: foxy-devel
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion src/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ add_executable(base_arm_gripper_test
YouBotGripperTest.cpp
)

add_executable(arm_torque_test YouBotArmTorqueTest.cpp)

target_link_libraries(base_arm_gripper_test YouBotDriver cppunit)
target_link_libraries(arm_torque_test YouBotDriver cppunit)

install(TARGETS base_arm_gripper_test
install(TARGETS base_arm_gripper_test arm_torque_test
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
)
114 changes: 114 additions & 0 deletions src/testing/YouBotArmTorqueTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include "youbot_driver/testing/YouBotArmTest.hpp"

using namespace youbot;

YouBotArmTest::YouBotArmTest():dof(5) {

EthercatMaster::getInstance("youbot-ethercat.cfg", CONFIG_FOLDER_PATH, true);


}

YouBotArmTest::~YouBotArmTest() {

}

void YouBotArmTest::setUp() {
// oneSec = 1000000;
}

void YouBotArmTest::tearDown() {
// EthercatMaster::destroy();
}

void YouBotArmTest::youBotArmTest() {
int oneSec = 1000000;

YouBotManipulator myArm("youbot-manipulator");
myArm.doJointCommutation();
std::cout << "Calibrating the arm!" << std::endl;
myArm.calibrateManipulator();

std::stringstream jointNameStream;
std::vector<JointAngleSetpoint> upstretchedpose;
std::vector<JointAngleSetpoint> foldedpose;
JointAngleSetpoint desiredJointAngle;

desiredJointAngle.angle = 2.56244 * radian;
upstretchedpose.push_back(desiredJointAngle);
desiredJointAngle.angle = 1.04883 * radian;
upstretchedpose.push_back(desiredJointAngle);
desiredJointAngle.angle = -2.43523 * radian;
upstretchedpose.push_back(desiredJointAngle);
desiredJointAngle.angle = 1.73184 * radian;
upstretchedpose.push_back(desiredJointAngle);
desiredJointAngle.angle = 1.5 * radian;
upstretchedpose.push_back(desiredJointAngle);

desiredJointAngle.angle = 0.11 * radian;
foldedpose.push_back(desiredJointAngle);
desiredJointAngle.angle = 0.11 * radian;
foldedpose.push_back(desiredJointAngle);
desiredJointAngle.angle = -0.11 * radian;
foldedpose.push_back(desiredJointAngle);
desiredJointAngle.angle = 0.11 * radian;
foldedpose.push_back(desiredJointAngle);
desiredJointAngle.angle = 0.2 * radian;
foldedpose.push_back(desiredJointAngle);


for (int i = 1; i <= dof; i++) {
jointNameStream << "Joint_" << i << "_" << __func__;
jointNameStream.str("");
}

int counter = 0;
while (counter < 1) {
usleep(oneSec);
counter++;
}

// send torques to joints
std::cout << "Testing torque interface" << std::endl;

JointTorqueSetpoint desiredJointTorque;
std::vector<JointTorqueSetpoint> commandTorques;

// joint 0 torque
desiredJointTorque.torque = 1.0 * si::newton_meters;
commandTorques.push_back(desiredJointTorque);
desiredJointTorque.torque = 0.0 * si::newton_meters;
commandTorques.push_back(desiredJointTorque);
desiredJointTorque.torque = 0.0 * si::newton_meters;
commandTorques.push_back(desiredJointTorque);
desiredJointTorque.torque = 0.0 * si::newton_meters;
commandTorques.push_back(desiredJointTorque);
desiredJointTorque.torque = 0.0 * si::newton_meters;
commandTorques.push_back(desiredJointTorque);

// move with command torques
myArm.setJointData(commandTorques);
counter = 0;
while (counter < 2) {
usleep(oneSec);
counter++;
}

std::cout << "Testing torque interface done" << std::endl;


// 1 sec no movement
counter = 0;
while (counter < 1) {
usleep(oneSec);
counter++;
}
}

int main()
{
YouBotArmTest youbot_arm_torque_test;
youbot_arm_torque_test.setUp();
youbot_arm_torque_test.youBotArmTest();
youbot_arm_torque_test.tearDown();
}