Here is a first attempt at a press controller.
Compile / install it with
Code:
sudo halcompile --install press.comp
Once installed
will show the auto-generated docs.
It takes a number of position commands on HAL pins from a GUI, and outputs a target position and velocity.
These should be the inputs to either a limit3 or simple_tp HAL component (I am not sure which will work best) to control velocity, accel and limits. Then the output of that would go to your PID.
The press component also needs to see the position feedback. Provision might have to be made for homing if your scales are not absolute.
I have assumed a three-position foot pedal with up, down and neither outputs.
Starting at the top, pressing the down switch will request a down feed. Releasing the down will set the velocity to zero.
Actuating the up switch will start a retract. releasing the up switch on a retract will stop the motion.
When the press reaches the start height the speed will be changed.
At the finish height motion will stop. Releasing the pedal _without_ actuating the up switch, then re-actuating the down switch will set a target press.0.tweak-down lower. This can be repeated indefinitely.
Code:
component press "A component to control a press-brake";
pin in float brake-pos-fb "Position feedback of the press";
pin in float top_position = 0 "Position to return to";
pin in float return_speed = 1 "Speed to return to top at";
pin in float bend_start = 0 "Point of contact with work";
pin in float start_speed = 1 "Speed to move down to initial contact";
pin in float bend_finish = 0 "Position to complete bend";
pin in float bend_speed = 1 "Speed to move at during bend";
pin in float tweak-down = 0 "Extra bend increment";
pin in float pos-tolerance = 0.05 "How close to target to be to stop";
pin out float brake-pos-cmd "Brake position command to motion";
pin out float brake-vel-cmd "Speed command to motion";
pin in float backstop-pos = 100 "Required backstop position";
pin in float backstop-fb = 100 "Backstop position feedback";
pin out float backstop-pos-cmd "Position command out to backstop";
pin in bit up "Command to move up from pedal";
pin in bit down "Command to move down from pedal";
pin in bit abort "Abort current operation and stop all motion";
pin in bit interlock = 1 "Input signal from interlocks to allow cycle";
function _;
license "GPL";
author "andypugh"
;;
#include "rtapi_math.h"
FUNCTION(_){
static int state = 0;
static double target;
switch (state) {
case 0: // at the top, awaiting commands
if (interlock != 1){ // interlock
return; // do nothing. Needs further consideration
}
if (fabs(backstop_pos_cmd - backstop_fb) > 4 * pos_tolerance){ // new backstop position
state = 10;
break;
}
if (down){
target = bend_start;
state = 5;
return;
}
break;
case 5: // moving down to work
brake_pos_cmd = target;
brake_vel_cmd = start_speed;
if (up){ // aborted motion
target = top_position;
state = 8;
return;
}
if (! down){ // pause the downfeed
brake_vel_cmd = 0;
}
if (fabs(brake_pos_fb - target) < pos_tolerance){ // in position
target = bend_finish;
state = 6;
}
break;
case 6: // bending
brake_pos_cmd = target;
brake_vel_cmd = bend_speed;
if (up){ // aborted motion
target = top_position;
state = 8;
return;
}
if (! down){ // pedal released
if (fabs(brake_pos_fb - target) < pos_tolerance){ // in position, consider tweaking
state = 7;
} else { // not in position, just stop
brake_vel_cmd = 0;
}
}
break;
case 7: // at bottom of stroke, waiting for a tweak
if (up){ // return to top
target = top_position;
state = 8;
return;
}
if (down) { // give it a tweak
target += tweak_down;
state = 6;
}
break;
case 8: // return to top
brake_pos_cmd = target;
brake_vel_cmd = return_speed;
// What to do if the down switch is pressed on the retract?
if (! up) { // pedal un-released
brake_vel_cmd = 0;
}
if (fabs(brake_pos_fb - target) < pos_tolerance){ // retracted
state = 0;
}
break;
case 10: // Backstop positioning
backstop_pos_cmd = backstop_pos;
if (fabs(backstop_fb - backstop_pos_cmd) < pos_tolerance){ // retracted
state = 0;
}
break;
default:
rtapi_print_msg(RTAPI_MSG_ERR, "Unsupported state reached in state machine");
}
}