Program Listing for File control_mode.h

Return to documentation for file (include/ur_client_library/comm/control_mode.h)

// this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-

// -- BEGIN LICENSE BLOCK ----------------------------------------------
// Copyright 2021 FZI Forschungszentrum Informatik
// Created on behalf of Universal Robots A/S
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -- END LICENSE BLOCK ------------------------------------------------

//----------------------------------------------------------------------
//----------------------------------------------------------------------

#ifndef UR_CLIENT_LIBRARY_CONTROL_MODE_H_INCLUDED
#define UR_CLIENT_LIBRARY_CONTROL_MODE_H_INCLUDED

#include <algorithm>
#include <vector>

namespace urcl
{
namespace comm
{
enum class ControlMode : int32_t
{
  MODE_STOPPED = -2,
  MODE_UNINITIALIZED = -1,
  MODE_IDLE = 0,
  MODE_SERVOJ = 1,
  MODE_SPEEDJ = 2,
  MODE_FORWARD = 3,
  MODE_SPEEDL = 4,
  MODE_POSE = 5,
  MODE_FREEDRIVE = 6,
  MODE_TOOL_IN_CONTACT =
      7,
  END
};

class ControlModeTypes
{
public:
  // Control modes that require realtime communication
  static const inline std::vector<ControlMode> REALTIME_CONTROL_MODES = {
    ControlMode::MODE_SERVOJ, ControlMode::MODE_SPEEDJ, ControlMode::MODE_SPEEDL, ControlMode::MODE_POSE
  };

  // Control modes that doesn't require realtime communication
  static const inline std::vector<ControlMode> NON_REALTIME_CONTROL_MODES = { ControlMode::MODE_IDLE,
                                                                              ControlMode::MODE_FORWARD,
                                                                              ControlMode::MODE_FREEDRIVE };

  // Control modes which doesn't move the robot, meaning they are neither realtime or non realtime
  static const inline std::vector<ControlMode> STATIONARY_CONTROL_MODES = { ControlMode::MODE_STOPPED,
                                                                            ControlMode::MODE_UNINITIALIZED,
                                                                            ControlMode::MODE_TOOL_IN_CONTACT };

  static bool is_control_mode_realtime(ControlMode control_mode)
  {
    return (std::find(ControlModeTypes::REALTIME_CONTROL_MODES.begin(), ControlModeTypes::REALTIME_CONTROL_MODES.end(),
                      control_mode) != ControlModeTypes::REALTIME_CONTROL_MODES.end());
  }

  static bool is_control_mode_non_realtime(ControlMode control_mode)
  {
    return (std::find(ControlModeTypes::NON_REALTIME_CONTROL_MODES.begin(),
                      ControlModeTypes::NON_REALTIME_CONTROL_MODES.end(),
                      control_mode) != ControlModeTypes::NON_REALTIME_CONTROL_MODES.end());
  }
};

}  // namespace comm
}  // namespace urcl

#endif  // ifndef UR_CLIENT_LIBRARY_CONTROL_MODE_H_INCLUDED