Skip to content

Commit

Permalink
Merge branch 'test/active-control-base' into fr3-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
BarisYazici committed Nov 17, 2023
2 parents d0c9f3c + 17502f9 commit 457021b
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 145 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# CHANGELOG

## 0.13.0 - 2023-11-16

* Add abstract ActiveControlBase class for the ActiveControllers to implement.
* **BREAKING** Fix function naming errors in robot class.
* **BREAKING** ActiveController initializer functions return ActiveControlBase

## 0.12.1 - 2023-09-20

* Fix install common/include typo
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.4)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(libfranka_VERSION 0.12.1)
set(libfranka_VERSION 0.13.0)

project(libfranka
VERSION ${libfranka_VERSION}
Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ WARN_NO_PARAMDOC = YES
# a warning is encountered.
# The default value is: NO.

WARN_AS_ERROR = @DOXYGEN_WARN_AS_ERROR@
WARN_AS_ERROR = NO

# The WARN_FORMAT tag determines the format of the warning messages that doxygen
# can produce. The string should contain the $file, $line, and $text tags, which
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(int argc, char** argv) {
};

bool motion_finished = false;
std::unique_ptr<franka::ActiveControl> active_control = robot.startCartesianPositionControl(
auto active_control = robot.startCartesianPoseControl(
research_interface::robot::Move::ControllerMode::kJointImpedance);
while (!motion_finished) {
auto read_once_return = active_control->readOnce();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int main(int argc, char** argv) {
};

bool motion_finished = false;
std::unique_ptr<franka::ActiveControl> active_control = robot.startCartesianVelocityControl(
auto active_control = robot.startCartesianVelocityControl(
research_interface::robot::Move::ControllerMode::kJointImpedance);
while (!motion_finished) {
auto read_once_return = active_control->readOnce();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main(int argc, char** argv) {
};

bool motion_finished = false;
std::unique_ptr<franka::ActiveControl> active_control = robot.startJointPositionControl(
auto active_control = robot.startJointPositionControl(
research_interface::robot::Move::ControllerMode::kJointImpedance);
while (!motion_finished) {
auto read_once_return = active_control->readOnce();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main(int argc, char** argv) {
};

bool motion_finished = false;
std::unique_ptr<franka::ActiveControl> active_control = robot.startJointVelocityControl(
auto active_control = robot.startJointVelocityControl(
research_interface::robot::Move::ControllerMode::kJointImpedance);
while (!motion_finished) {
auto read_once_return = active_control->readOnce();
Expand Down
2 changes: 1 addition & 1 deletion examples/motion_with_control_external_control_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ int main(int argc, char** argv) {
};

bool motion_finished = false;
std::unique_ptr<franka::ActiveControl> active_control = robot.startJointVelocityControl(
auto active_control = robot.startJointVelocityControl(
research_interface::robot::Move::ControllerMode::kExternalController);
while (!motion_finished) {
auto read_once_return = active_control->readOnce();
Expand Down
122 changes: 20 additions & 102 deletions include/franka/active_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,147 +2,65 @@
// Use of this source code is governed by the Apache-2.0 license, see LICENSE
#pragma once

#include <memory>
#include <optional>
#include <utility>

#include <franka/control_types.h>
#include <franka/active_control_base.h>
#include <franka/exception.h>
#include <franka/robot_state.h>

#include "robot.h"

/**
* @file active_control.h
* Contains the `franka::ActiveControl`, `franka::ActiveTorqueControl` and
* `franka::ActiveMotionGenerator` type.
* Implements the ActiveControlBase abstract class. Contains the `franka::ActiveControl`,
* `franka::ActiveTorqueControl` and `franka::ActiveMotionGenerator` type.
*/

namespace franka {

/**
* Allows the user to read the state of a Robot and to send new control commands after starting a
* control process of a Robot.
*
* hint: To create an ActiveControl, see franka::ActiveTorqueControl or
* franka::ActiveMotionGenerator
*
* Documented in ActiveControlBase
*/
class ActiveControl {
class ActiveControl : public ActiveControlBase {
public:
virtual ~ActiveControl();
~ActiveControl() override;

/**
* Waits for a robot state update and returns it.
*
* @return Current robot state & time since last read operation
*
* @throw NetworkException if the connection is lost, e.g. after a timeout.
* @throw ProtocolException if robot returns an unexpected message.
* @throw ControlException if robot is in an error state.
*/
std::pair<RobotState, Duration> readOnce();
std::pair<RobotState, Duration> readOnce() override;

/**
* Updates torque commands of an active control
*
* hint: implemented in ActiveTorqueControl
*
* @return void
*/
virtual void writeOnce(const Torques& /* control_input */) {
void writeOnce(const Torques& /* control_input */) override {
throw franka::ControlException(wrong_write_once_method_called);
};

/**
* Updates the joint position and torque commands of an active control
*
* hint: implemented in ActiveMotionGenerator<JointPositions>
*
* @return void
*/
virtual void writeOnce(const JointPositions& /* motion_generator_input */,
const std::optional<const Torques>& /*control_input*/) {
void writeOnce(const JointPositions& /* motion_generator_input */,
const std::optional<const Torques>& /*control_input*/) override {
throw franka::ControlException(wrong_write_once_method_called);
};

/**
* Updates the joint velocity and torque commands of an active control
*
* hint: implemented in ActiveMotionGenerator<JointVelocities>
*
* @return void
*/
virtual void writeOnce(const JointVelocities& /* motion_generator_input */,
const std::optional<const Torques>& /* control_input */) {
void writeOnce(const JointVelocities& /* motion_generator_input */,
const std::optional<const Torques>& /* control_input */) override {
throw franka::ControlException(wrong_write_once_method_called);
};

/**
* Updates the cartesian position and torque commands of an active control
*
* hint: implemented in ActiveMotionGenerator<CartesianPose>
*
* @return void
*/
virtual void writeOnce(const CartesianPose& /* motion_generator_input */,
const std::optional<const Torques>& /* control_input */) {
void writeOnce(const CartesianPose& /* motion_generator_input */,
const std::optional<const Torques>& /* control_input */) override {
throw franka::ControlException(wrong_write_once_method_called);
};

/**
* Updates the cartesian velocity and torque commands of an active control
*
* hint: implemented in ActiveMotionGenerator<CartesianVelocities>
*
* @return void
*/
virtual void writeOnce(const CartesianVelocities& /* motion_generator_input */,
const std::optional<const Torques>& /* control_input */) {
void writeOnce(const CartesianVelocities& /* motion_generator_input */,
const std::optional<const Torques>& /* control_input */) override {
throw franka::ControlException(wrong_write_once_method_called);
};

/**
* Updates the joint position commands of an active control, with internal controller
*
* @param motion_generator_input the new motion generator input
*
* @return void
*/
virtual void writeOnce(const JointPositions& motion_generator_input) {
void writeOnce(const JointPositions& motion_generator_input) override {
writeOnce(motion_generator_input, std::optional<const Torques>());
};

/**
* Updates the joint velocity commands of an active control, with internal controller
*
* @param motion_generator_input the new motion generator input
*
* @return void
*/
virtual void writeOnce(const JointVelocities& motion_generator_input) {
void writeOnce(const JointVelocities& motion_generator_input) override {
writeOnce(motion_generator_input, std::optional<const Torques>());
};

/**
* Updates the cartesian position commands of an active control, with internal controller
*
* @param motion_generator_input the new motion generator input
*
* @return void
*/
virtual void writeOnce(const CartesianPose& motion_generator_input) {
void writeOnce(const CartesianPose& motion_generator_input) override {
writeOnce(motion_generator_input, std::optional<const Torques>());
};

/**
* Updates the cartesian velocity commands of an active control, with internal controller
*
* @param motion_generator_input the new motion generator input
*
* @return void
*/
virtual void writeOnce(const CartesianVelocities& motion_generator_input) {
void writeOnce(const CartesianVelocities& motion_generator_input) override {
writeOnce(motion_generator_input, std::optional<const Torques>());
};

Expand Down
119 changes: 119 additions & 0 deletions include/franka/active_control_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright (c) 2023 Franka Emika GmbH
// Use of this source code is governed by the Apache-2.0 license, see LICENSE
#pragma once

#include <franka/control_types.h>
#include <franka/exception.h>
#include <franka/robot_state.h>
#include <memory>
#include <optional>
#include <utility>

/**
* @file active_control_base.h
* Abstract interface class as the base of the active controllers.
*/

namespace franka {

/**
* Allows the user to read the state of a Robot and to send new control commands after starting a
* control process of a Robot.
*
* hint: To create an ActiveControlBase, see franka::ActiveTorqueControl or
* franka::ActiveMotionGenerator
*
*/
class ActiveControlBase {
public:
virtual ~ActiveControlBase() = default;

/**
* Waits for a robot state update and returns it.
*
* @return Current robot state & time since last read operation
*
* @throw NetworkException if the connection is lost, e.g. after a timeout.
* @throw ProtocolException if robot returns an unexpected message.
* @throw ControlException if robot is in an error state.
*/
virtual std::pair<RobotState, Duration> readOnce() = 0;

/**
* Updates torque commands of an active control
*
* hint: implemented in ActiveTorqueControl
*
*/
virtual void writeOnce(const Torques& /* control_input */) = 0;

/**
* Updates the joint position and torque commands of an active control
*
* hint: implemented in ActiveMotionGenerator<JointPositions>
*
*/
virtual void writeOnce(const JointPositions& /* motion_generator_input */,
const std::optional<const Torques>& /*control_input*/) = 0;

/**
* Updates the joint velocity and torque commands of an active control
*
* hint: implemented in ActiveMotionGenerator<JointVelocities>
*
*/
virtual void writeOnce(const JointVelocities& /* motion_generator_input */,
const std::optional<const Torques>& /* control_input */) = 0;
/**
* Updates the cartesian position and torque commands of an active control
*
* hint: implemented in ActiveMotionGenerator<CartesianPose>
*
*/
virtual void writeOnce(const CartesianPose& /* motion_generator_input */,
const std::optional<const Torques>& /* control_input */) = 0;

/**
* Updates the cartesian velocity and torque commands of an active control
*
* hint: implemented in ActiveMotionGenerator<CartesianVelocities>
*
*/
virtual void writeOnce(const CartesianVelocities& /* motion_generator_input */,
const std::optional<const Torques>& /* control_input */) = 0;
/**
* Updates the joint position commands of an active control, with internal controller
*
* @param motion_generator_input the new motion generator input
*
*/
virtual void writeOnce(const JointPositions& motion_generator_input) = 0;

/**
* Updates the joint velocity commands of an active control, with internal controller
*
* @param motion_generator_input the new motion generator input
*
*/
virtual void writeOnce(const JointVelocities& motion_generator_input) = 0;
/**
* Updates the cartesian pose commands of an active control, with internal controller
*
* @param motion_generator_input the new motion generator input
*
*/
virtual void writeOnce(const CartesianPose& motion_generator_input) = 0;

/**
* Updates the cartesian velocity commands of an active control, with internal controller
*
* @param motion_generator_input the new motion generator input
*
*/
virtual void writeOnce(const CartesianVelocities& motion_generator_input) = 0;

protected:
ActiveControlBase() = default;
};

} // namespace franka
2 changes: 1 addition & 1 deletion include/franka/active_motion_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "active_control.h"

/**
* @file active_control.h
* @file active_motion_generator.h
* Contains the `franka::ActiveMotionGenerator` type.
*/

Expand Down
Loading

0 comments on commit 457021b

Please sign in to comment.