Scenario:
I have a robotic arm that has a (1D) lidar on its end, to orient itself with respect to the slant table in front of it. The lidar returns pretty accurate distance values in mm. The motor controlling the arm's motion towards the table (or away from it), uses time-duration values in seconds provided by the user and moves the arm fast or slow, at a pre-defined velocity.
e.g., arm_up(0.5)
pulls the arm up at some velocity, for 0.5 seconds.
What am I trying to do:
I am trying to control the the position of the arm before it comes to a certain distance from the table (200 mm). That is, it moves more when far and less when near it.
Attempts:
I planned to use a controller to achieve this. First attempt included using a P-controller (P: Proportional) which involved fixing a gain Kp that gets multiplied with the error. I wanted the output of this controller to be in the range 0.1 to 1.0. I tried multiple values of Kp but did not get factor
values proportional to the distance to be covered. When I set Kp=0.008, It works well when the error = 500 (mm), and the factor comes out to be = error x Kp, or 500 x 0.008=0.4, but when the error=10mm, factor=10 x 0.008=0.8 which is too below for the actuator to do anything, owing to the fact that all values must be in the range 0.1 to 1.0. Alternatively, setting higher values for Kp (as 0.01), requires me to clamp the output to a fixed value.
Kp = 0.003
if(LIDAR_1 > 200):
# P Controller
error = abs(200 - LIDAR_1)
duration = error * Kp
# To keep everything < 1.0
factor = duration%1.0
arm_down(factor)
Then, I used the feature scaler to scale the range (given by the lidar) to the desired range (0.1 to 1.0). To filter very high values, I used a mod
operator a.k.a %
in Python.
if(LIDAR_1 > 200):
# Using Feature Scaling
duration = ((LIDAR_1-200)*0.8/800) + 0.2
# To keep everything < 1.0
factor = duration%1.0
arm_down(factor)