Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Aron Svastits committed Apr 25, 2024
1 parent 5c745c3 commit 86c6ac2
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
/**
* Implementation of a robot application.
* <p>
* The application provides a {@link RoboticsAPITask#initialize()} and a
* {@link RoboticsAPITask#run()} method, which will be called successively in
* the application lifecycle. The application will terminate automatically after
* the {@link RoboticsAPITask#run()} method has finished or after stopping the
* task. The {@link RoboticsAPITask#dispose()} method will be called, even if an
* exception is thrown during initialization or run.
* The application provides a {@link RoboticsAPITask#initialize()} and a
* {@link RoboticsAPITask#run()} method, which will be called successively in
* the application lifecycle. The application will terminate automatically after
* the {@link RoboticsAPITask#run()} method has finished or after stopping the
* task. The {@link RoboticsAPITask#dispose()} method will be called, even if an
* exception is thrown during initialization or run.
* <p>
* <b>It is imperative to call <code>super.dispose()</code> when overriding the
* {@link RoboticsAPITask#dispose()} method.</b>
*
* <b>It is imperative to call <code>super.dispose()</code> when overriding the
* {@link RoboticsAPITask#dispose()} method.</b>
*
* @see UseRoboticsAPIContext
* @see #initialize()
* @see #run()
Expand All @@ -30,7 +30,7 @@
public class ROS2_Control extends RoboticsAPIApplication {
@Inject
private LBR _lbr;

private TCPConnection _TCPConnection;
private ROS2Connection _ROS2Connection;
private FRIManager _FRIManager;
Expand All @@ -41,7 +41,7 @@ public void initialize() {
_TCPConnection = new TCPConnection(30000);
_ROS2Connection = new ROS2Connection();
_FRIManager = new FRIManager(_lbr, getApplicationControl());

_FRIManager.registerROS2ConnectionModule(_ROS2Connection);
_TCPConnection.registerROS2ConnectionModule(_ROS2Connection);
_ROS2Connection.registerTCPConnectionModule(_TCPConnection);
Expand All @@ -57,7 +57,7 @@ public void run() {
_ROS2Connection.rejectCommands();
_FRIManager.close();
}

@Override
public void dispose() {
getLogger().info("disposes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum CommandResult{
ERRORED;
}
private ROS2Connection _ROS2Connection;

private State _currentState;
private LBR _lbr;
private FRISession _FRISession;
Expand All @@ -42,9 +42,9 @@ public enum CommandResult{
private IMotionContainer _motionContainer;
private FRIMotionErrorHandler _friMotionErrorHandler = new FRIMotionErrorHandler();
//private IApplicationControl _applicationControl;

private static double[] stiffness_ = new double[7];

public FRIManager(LBR lbr, IApplicationControl applicationControl){
_currentState = new InactiveState();
_lbr = lbr;
Expand All @@ -57,11 +57,11 @@ public FRIManager(LBR lbr, IApplicationControl applicationControl){
//_applicationControl = applicationControl;
applicationControl.registerMoveAsyncErrorHandler(_friMotionErrorHandler);
}

public void registerROS2ConnectionModule(ROS2Connection ros2ConnectionModule){
_ROS2Connection = ros2ConnectionModule;
}

public void close(){
if(_currentState instanceof ControlActiveState){
deactivateControl();
Expand All @@ -70,36 +70,36 @@ public void close(){
endFRI();//TODO: handle error
}
}

public FRIConfigurationParams getFRIConfig(){
FRIConfigurationParams friConfigurationParams = new FRIConfigurationParams(_FRIConfiguration);
return friConfigurationParams;
}

public ClientCommandMode getClientCommandMode(){
return _clientCommandMode;
}

public IMotionControlMode getControlMode(){
return _controlMode;
}

public FRISessionState getFRISessionState(){
return _FRISession.getFRIChannelInformation().getFRISessionState();
}

/*
* The Following commands change the state of the FRI Manager, and thus are forwarded to the state machine for validation
* */

public CommandResult setControlMode(IMotionControlMode controlMode){
return _currentState.setControlMode(controlMode);
}

public CommandResult setCommandMode(ClientCommandMode clientCommandMode){
return _currentState.setCommandMode(clientCommandMode);
}

public CommandResult setFRIConfig(FRIConfigurationParams friConfigurationParams){
return _currentState.setFRIConfig(friConfigurationParams);
}
Expand All @@ -111,62 +111,62 @@ public CommandResult startFRI(){
}
return commandResult;
}

public CommandResult endFRI(){
CommandResult commandResult = _currentState.endFRI();
if(commandResult == CommandResult.EXECUTED){
_currentState = new InactiveState();
}
return commandResult;
}

public CommandResult activateControl(){
CommandResult commandResult = _currentState.activateControl();
if(commandResult == CommandResult.EXECUTED){
_currentState = new ControlActiveState();
}
return commandResult;
}

public CommandResult deactivateControl(){
CommandResult commandResult = _currentState.deactivateControl();
if(commandResult == CommandResult.EXECUTED){
_currentState = new FRIActiveState();
}
return commandResult;
}

private class State{
/* By default reject all commands */
public CommandResult startFRI(){
return CommandResult.REJECTED;
}

public CommandResult endFRI(){
return CommandResult.REJECTED;
}

public CommandResult activateControl(){
return CommandResult.REJECTED;
}

public CommandResult deactivateControl(){
return CommandResult.REJECTED;
}

public CommandResult setFRIConfig(FRIConfigurationParams friConfigurationParams){
return CommandResult.REJECTED;
}

public CommandResult setControlMode(IMotionControlMode controlMode){
return CommandResult.REJECTED;
}

public CommandResult setCommandMode(ClientCommandMode clientCommandMode){
return CommandResult.REJECTED;
}
}

private class InactiveState extends State{
@Override
public CommandResult startFRI(){
Expand All @@ -177,7 +177,7 @@ public CommandResult startFRI(){
FRIManager.this._FRISession.close();
return CommandResult.ERRORED;
}

return CommandResult.EXECUTED;
}
@Override
Expand All @@ -196,7 +196,7 @@ public CommandResult setCommandMode(ClientCommandMode clientCommandMode){
return CommandResult.EXECUTED;
}
}

private class FRIActiveState extends State {
@Override
public CommandResult endFRI(){
Expand All @@ -209,11 +209,11 @@ public CommandResult endFRI(){
}
@Override
public CommandResult activateControl(){
FRIJointOverlay friJointOverlay =
FRIJointOverlay friJointOverlay =
new FRIJointOverlay(FRIManager.this._FRISession, FRIManager.this._clientCommandMode);
PositionHold motion =
PositionHold motion =
new PositionHold(FRIManager.this._controlMode, -1, null);
FRIManager.this._motionContainer =
FRIManager.this._motionContainer =
FRIManager.this._lbr.moveAsync(motion.addMotionOverlay(friJointOverlay));
return CommandResult.EXECUTED;
}
Expand All @@ -228,15 +228,15 @@ public CommandResult setCommandMode(ClientCommandMode clientCommandMode){
return CommandResult.EXECUTED;
}
}

private class ControlActiveState extends State {
@Override
public CommandResult deactivateControl(){
FRIManager.this._motionContainer.cancel();
return CommandResult.EXECUTED;
}
}

private class FRIMotionErrorHandler implements IErrorHandler{

@Override
Expand All @@ -260,7 +260,7 @@ public ErrorHandlingAction handleError(Device device,
System.out.println("Cancelled containers: " + canceledContainers.toString());
return ErrorHandlingAction.Ignore;
}

}

}
Loading

0 comments on commit 86c6ac2

Please sign in to comment.