Commit d5a5c46a authored by Lucas Felix's avatar Lucas Felix
Browse files

Add closed loop capability to mockup axis

parent 2856e3d3
......@@ -25,6 +25,7 @@ import numpy as np
from bliss.physics.trajectory import LinearTrajectory
from bliss.controllers.motor import Controller, CalcController
from bliss.common.axis import Axis, AxisState
from bliss.common.closed_loop import ClosedLoopState
from bliss.common import event
from bliss.config.settings import SimpleSetting
from bliss.common.hook import MotionHook
......@@ -85,6 +86,10 @@ class Mockup(Controller):
self._axis_moves = {}
self.__encoders = {}
self.__switches = {}
self._cloop_state = {}
self._cloop_params = {}
self._axes_data = collections.defaultdict(dict)
# Custom attributes.
......@@ -130,8 +135,13 @@ class Mockup(Controller):
if self.read_hw_position(axis) is None:
self.set_hw_position(axis, 0)
self._cloop_state[axis] = ClosedLoopState.UNKNOWN
def initialize_hardware_axis(self, axis):
pass
if axis.closed_loop:
self._cloop_params["kp"] = axis.closed_loop.kp
self._cloop_params["ki"] = axis.closed_loop.ki
self._cloop_params["kd"] = axis.closed_loop.kd
def initialize_axis(self, axis):
log_debug(self, "initializing axis %s", axis.name)
......@@ -478,6 +488,39 @@ class Mockup(Controller):
"""
self.set_position(axis, self.read_position(axis) + disc)
"""
CLOSED LOOP
"""
def get_closed_loop_requirements(self):
return ["kp", "ki", "kd"]
def get_closed_loop_state(self, axis):
return self._cloop_state[axis]
def activate_closed_loop(self, axis, onoff=True):
if onoff:
self._cloop_state[axis] = ClosedLoopState.ON
else:
self._cloop_state[axis] = ClosedLoopState.OFF
return self._cloop_state[axis]
def set_closed_loop_param(self, axis, param, value):
"""
Hardware specific method to set closed loop parameters.
"""
if param not in self.get_closed_loop_requirements():
raise KeyError(f"Unknown closed loop parameter: {param}")
self._cloop_params[param] = value
def get_closed_loop_param(self, axis, param):
"""
Hardware specific method to read closed loop parameters.
"""
if param not in self.get_closed_loop_requirements():
raise KeyError(f"Unknown closed loop parameter: {param}")
return self._cloop_params[param]
"""
Custom axis methods
"""
......@@ -514,11 +557,6 @@ class Mockup(Controller):
def custom_send_command(self, axis, value):
log_debug(self, "custom_send_command(axis=%s value=%r):" % (axis.name, value))
# BOOL NONE
@object_method(name="Set_Closed_Loop", types_info=("bool", "None"))
def _set_closed_loop(self, axis, onoff=True):
pass # print "I set the closed loop ", onoff
# Types by default (None, None)
@object_method
def custom_command_no_types(self, axis):
......
......@@ -230,6 +230,20 @@ controller:
acceleration: 1000
low_limit: -5
high_limit: 5
- name: servo1
steps_per_unit: 1000
velocity_high_limit: 500
velocity_low_limit: 10
velocity: 100
acceleration: 200
low_limit: -1000
high_limit: 1000
unit: mm
closed_loop:
state: on
kp: 1
ki: 2
kd: 3
encoders:
- name: m1enc
steps_per_unit: 50
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment