Skip to content
Draft
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
11 changes: 11 additions & 0 deletions include/ur_client_library/control/script_command_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ class ScriptCommandInterface : public ReverseInterface
*/
bool setPayload(const double mass, const vector3d_t* cog);

/*!
* \brief Set the gravity vector
*
* \param gravity Gravity, a vector [x, y, z] specifying the gravity vector (pointing towards
* the Earth's center) given in the robot's base frame
*
* \returns True, if the write was performed successfully, false otherwise.
*/
bool setGravity(const vector3d_t* gravity);

/*!
* \brief Set the tool voltage.
*
Expand Down Expand Up @@ -227,6 +237,7 @@ class ScriptCommandInterface : public ReverseInterface
END_TOOL_CONTACT = 6, ///< End detecting tool contact
SET_FRICTION_COMPENSATION = 7, ///< Set friction compensation
FT_RTDE_INPUT_ENABLE = 8, ///< Enable FT RTDE input
SET_GRAVITY = 9, ///< Set gravity vector
};

/*!
Expand Down
11 changes: 11 additions & 0 deletions include/ur_client_library/ur/ur_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,17 @@ class UrDriver
*/
bool setPayload(const float mass, const vector3d_t& cog);

/*!
* \brief Set the gravity vector. Note: It requires the external control script to be running or
* the robot to be in headless mode.
*
* \param gravity Gravity, a vector [x, y, z] specifying the gravity vector (pointing towards
* the Earth's center) given in the robot's base frame
*
* \returns True on successful write.
*/
bool setGravity(const vector3d_t& gravity);

/*!
* \brief Set the tool voltage. Note: It requires the external control script to be running or the robot to be in
* headless mode.
Expand Down
4 changes: 4 additions & 0 deletions resources/external_control.urscript
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ START_TOOL_CONTACT = 5
END_TOOL_CONTACT = 6
SET_FRICTION_COMPENSATION = 7
FT_RTDE_INPUT_ENABLE = 8
SET_GRAVITY = 9
SCRIPT_COMMAND_DATA_DIMENSION = 28

FREEDRIVE_MODE_START = 1
Expand Down Expand Up @@ -756,6 +757,9 @@ thread script_commands():
mass = raw_command[2] / MULT_jointstate
cog = [raw_command[3] / MULT_jointstate, raw_command[4] / MULT_jointstate, raw_command[5] / MULT_jointstate]
set_payload(mass, cog)
elif command == SET_GRAVITY:
gravity = [raw_command[2] / MULT_jointstate, raw_command[3] / MULT_jointstate, raw_command[4] / MULT_jointstate]
set_gravity(gravity)
elif command == SET_TOOL_VOLTAGE:
tool_voltage = raw_command[2] / MULT_jointstate
set_tool_voltage(tool_voltage)
Expand Down
25 changes: 25 additions & 0 deletions src/control/script_command_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@ bool ScriptCommandInterface::setPayload(const double mass, const vector3d_t* cog
return server_.write(client_fd_, buffer, sizeof(buffer), written);
}

bool ScriptCommandInterface::setGravity(const vector3d_t* gravity)
{
const int message_length = 4;
uint8_t buffer[sizeof(int32_t) * MAX_MESSAGE_LENGTH];
uint8_t* b_pos = buffer;
int32_t val = htobe32(toUnderlying(ScriptCommand::SET_GRAVITY));
b_pos += append(b_pos, val);

for (auto const& grav_component : *gravity)
{
val = htobe32(static_cast<int32_t>(round(grav_component * MULT_JOINTSTATE)));
b_pos += append(b_pos, val);
}

// writing zeros to allow usage with other script commands
for (size_t i = message_length; i < MAX_MESSAGE_LENGTH; i++)
{
val = htobe32(0);
b_pos += append(b_pos, val);
}
size_t written;

return server_.write(client_fd_, buffer, sizeof(buffer), written);
}

bool ScriptCommandInterface::setToolVoltage(const ToolVoltage voltage)
{
const int message_length = 2;
Expand Down
20 changes: 20 additions & 0 deletions src/ur/ur_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,26 @@ bool UrDriver::setPayload(const float mass, const vector3d_t& cog)
}
}

bool UrDriver::setGravity(const vector3d_t& gravity)
{
if (script_command_interface_->clientConnected())
{
return script_command_interface_->setGravity(&gravity);
}
else
{
URCL_LOG_WARN("Script command interface is not running. Falling back to sending plain script code. On e-Series "
"robots this will only work, if the robot is in remote_control mode.");
std::stringstream cmd;
cmd.imbue(std::locale::classic()); // Make sure, decimal divider is actually '.'
cmd << "sec setup():" << std::endl
<< " set_gravity([" << gravity[0] << ", " << gravity[1] << ", " << gravity[2] << "])" << std::endl
<< "end";
return sendScript(cmd.str());
return true;
}
}

bool UrDriver::setToolVoltage(const ToolVoltage voltage)
{
// Test that the tool voltage is either 0, 12 or 24.
Expand Down