Orient component revised

More
01 Mar 2020 10:08 #158882 by alkabal
Replied by alkabal on topic Orient component
Hi

Sorry for late reply, i'm a little busy converting my lathe from MK to LinuxCNC with mesa 7i76e + rpi4.

I check a little more for this component asap.

Br, thanks for reply

Please Log in or Create an account to join the conversation.

More
15 Mar 2020 00:36 - 16 Mar 2020 16:08 #160238 by alkabal
Replied by alkabal on topic Orient component
Hello

Restarting to work with my component, but i have some trouble for direction calculation, i'm sure it's some simple error but...
// 100% sure someone can write this calc more cleaner...
       rev = position;                 // converting to int for extract full rev only for internal calc
       tempcalc = (position - rev) * 360.0;      // converting to degree in a -360 to 360 range 
                                             // converting to degree in 0 to 360 to 0 range
       if (tempcalc < 0) scaled_angle_out = 360 + tempcalc; else scaled_angle_out = tempcalc;
       angle_deviation = angle_scaled_out - angle;
// 100% sure someone can write this calc more cleaner...
                    if (angle_deviation < 0 && fabs angle_deviation > 180) cmd_to_pid_orient = -vel_speed; else cmd_to_pid_orient = vel_speed;
                    if (angle_deviation > 0 && fabs angle_deviation > 180) cmd_to_pid_orient = vel_speed; else cmd_to_pid_orient = vel_speed;



Any help or report proble is really welcom, i will like to be very simple for setup and if i'm not in wrong direction i like to do a accurate orient process.

I have added a automatic spindle homing process immediately after first axis is homed.

Attached is component file

hal setup is here :
#####################################################################
# Spindle orient mode
#####################################################################
loadrt orientv4 names=orient.orient-spindle
loadrt pid      names=pid.orient-spindle

addf orient.orient-spindle                  servo-thread
addf pid.orient-spindle.do-pid-calcs        servo-thread

# setup Orient Spindle PID
setp pid.orient-spindle.Pgain        [ORIENT]P
setp pid.orient-spindle.Igain        [ORIENT]I
setp pid.orient-spindle.Dgain        [ORIENT]D
setp pid.orient-spindle.FF0          [ORIENT]FF0
setp pid.orient-spindle.FF1          [ORIENT]FF1
setp pid.orient-spindle.FF2          [ORIENT]FF2
setp pid.orient-spindle.bias         [ORIENT]BIAS
setp pid.orient-spindle.deadband     [ORIENT]DEADBAND
setp pid.orient-spindle.maxerror     [ORIENT]MAX_ERROR
setp pid.orient-spindle.maxerrorI    [ORIENT]MAX_ERROR_I
setp pid.orient-spindle.maxoutput    [ORIENT]MAX_OUTPUT

setp orient.orient-spindle.vel-speed [ORIENT]VEL_SPEED
setp orient.orient-spindle.tolerance [ORIENT]AT_ANGLE_TOL

# encoder connections feedback
net spindle-pos          => orient.orient-spindle.position
net spindle-pos-deg      <= orient.orient-spindle.scaled-angle-out

# Index connection
net spindle-index-enable <=> orient.orient-spindle.index-enable
net spindle-index-enable  => pid.orient-spindle.index-enable

# Spindle homing link for homing spindle with machine homing
net machinehomed <= joint.0.homed
net machinehomed => orient.orient-spindle.machine-is-homed

# Set asked mode from M19 P0/1/2
net spindle-orient-mode <= spindle.0.orient-mode
net spindle-orient-mode => orient.orient-spindle.mode

# If spindle is not homed report error and cancel orient process
net spindle-orient-error <= orient.orient-spindle.error-not-homed
net spindle-orient-error => spindle.0.orient-fault 

# Spindle orient enable control signals
net spindle-orient-enable     <= spindle.0.orient
net spindle-orient-enable     => orient.orient-spindle.enable

# Pid enable from orient component 
net spindle-orient-pid-ena <= orient.orient-spindle.ena-out-pid-muxed
net spindle-orient-pid-ena => pid.orient-spindle.enable

# enable out for controler from regular spindle or orient mode
net spindle-enable             => orient.orient-spindle.ena-from-velocity
net spindle-orient-enable-out  <= orient.orient-spindle.ena-out-muxed
# moved in the orient input/output but initially in spindle setup
net spindle-orient-enable-out  => [HMOT](CARD0).7i83.0.0.analogena0 

# Is oriented near signal + link position asked to component
net spindle-orient-degree-cmd <= spindle.0.orient-angle
net spindle-orient-degree-cmd => orient.orient-spindle.angle
net spindle-is-oriented <= orient.orient-spindle.is-oriented
net spindle-is-oriented => spindle.0.is-oriented

# Command to pid from component by velocity and velocity feedback
net spindle-orient-vel   <= orient.orient-spindle.cmd-to-pid-orient
net spindle-orient-vel   => pid.orient-spindle.command
net spindle-vel-rpm      => pid.orient-spindle.feedback                # feedback velocity mode

# Input speed velocity from normal mode inside component
# the component passthru the spindle velocity to the Card signal generator or send orient velocity
net spindle-orient-pid-in-out <= pid.orient-spindle.output
net spindle-orient-pid-in-out => orient.orient-spindle.cmd-from-pid-orient
net spindle-vel-cmd-out       => orient.orient-spindle.cmd-from-pid-velocity
net spindle-orient-ctrl-out   <= orient.orient-spindle.cmd-out-muxed
 # moved in the orient input/output but initially in spindle setup
net spindle-orient-ctrl-out   => [HMOT](CARD0).7i83.0.0.analogout0
Attachments:
Last edit: 16 Mar 2020 16:08 by alkabal.

Please Log in or Create an account to join the conversation.

More
19 Mar 2020 22:21 - 19 Mar 2020 22:22 #160778 by andypugh
Replied by andypugh on topic Orient component
                    if (angle_deviation < 0 && fabs angle_deviation > 180) cmd_to_pid_orient = -vel_speed; else cmd_to_pid_orient = vel_speed;
                    if (angle_deviation > 0 && fabs angle_deviation > 180) cmd_to_pid_orient = vel_speed; else cmd_to_pid_orient = vel_speed;

- else +
+ else +

That seems inconsistent.
Also, doesn't it need to be fabs(something) ?

Consider angle_deviation = 100. Both conditions are false, so cmd_to_orient_pid is not set. Is that what you want?

I think I would have something like.
if ( angle_deviation > 0){
    if (fabs(angle_deviation) > 180){
        command_to_orient_pid = -vel_speed;
    } else {
        command_to_orient_pid = vel_speed;
    }
} else {
    if (fabs(angle_deviation) > 180){
        command_to_orient_pid = vel_speed;
    } else {
        command_to_orient_pid = -vel_speed;
    }
}
Last edit: 19 Mar 2020 22:22 by andypugh.

Please Log in or Create an account to join the conversation.

More
19 Mar 2020 23:05 - 19 Mar 2020 23:05 #160792 by alkabal
Replied by alkabal on topic Orient component
Yes sorry this is a tipo mistake inside last attempt, but unfortunatly nothing work 100% from this way else without this error

angle_deviation can be positive or negative and if more than 180% need to reverse direction.

Maybee i'm thinking about bad initialised variable because with your more cleaner solution this does not work fine from 0 as 120 and spindle go reverse, from 120 to 140 run reverse, from 140 to 120 run reverse (but is ok for this one lol)


also try
                if (fabs(angle_deviation) > 180){
                    if (angle_deviation > 0){
                        cmd_to_pid_orient = vel_speed;
                    } else {
                        cmd_to_pid_orient = -vel_speed;
                    }
                } else {
                    if (angle_deviation > 0){
                        cmd_to_pid_orient = -vel_speed;
                    } else {
                        cmd_to_pid_orient = vel_speed;
                    }
                }

Thanks
Last edit: 19 Mar 2020 23:05 by alkabal.

Please Log in or Create an account to join the conversation.

More
20 Mar 2020 00:13 - 20 Mar 2020 00:43 #160804 by alkabal
Replied by alkabal on topic Orient component
                if (angle_deviation > 180){
                        cmd_to_pid_orient = vel_speed;
                        ashortest_move = 1;
                        ashortest_move2 = angle_deviation;
                } else {
                     if (angle_deviation > 0){
                        cmd_to_pid_orient = -vel_speed;
                        ashortest_move = 2;
                        ashortest_move2 = angle_deviation;
                     } else { 
                          if (angle_deviation > -180){
                             cmd_to_pid_orient = vel_speed;
                        ashortest_move = 3;
                        ashortest_move2 = angle_deviation;
                          } else { 
                              if (angle_deviation < -180 ){
                                 cmd_to_pid_orient = -vel_speed;
                        ashortest_move = 4;
                        ashortest_move2 = angle_deviation;
                                     }                        
                                 }
                             }
                        }

Also does not work fine i see only from halscope ashortest_move = 3 ashortest_move2 = -10 (the first move from 0 to 10) and is never updated after other M19 ???

200 to 10 is ok turn cw (deviation 190)
200 to 180 is not ok turn cw (deviation 20)
10 to 200 is not ok turn cw (deviation -190)
180 to 200 is ok turn cw (deviation -20)
Last edit: 20 Mar 2020 00:43 by alkabal.

Please Log in or Create an account to join the conversation.

More
20 Mar 2020 01:15 - 20 Mar 2020 01:58 #160817 by alkabal
Replied by alkabal on topic Orient component
Stupid bug from keeping the "last_enable" checking...

Now work like a charm :silly:



Can now ask if you have some idea for better positionning
if (angle_scaled_out <= angle+tolerance && angle_scaled_out >= angle-tolerance) is_oriented = 1;

And regarding to pid feedback-deriv command-deriv using position and Angle ? (at start rewriting the component i have very bad result using -deriv)

Br
Attachments:
Last edit: 20 Mar 2020 01:58 by alkabal.

Please Log in or Create an account to join the conversation.

More
23 Mar 2020 00:40 #161161 by andypugh
Replied by andypugh on topic Orient component

alkabal wrote: Can now ask if you have some idea for better positionning

if (angle_scaled_out <= angle+tolerance && angle_scaled_out >= angle-tolerance) is_oriented = 1;


If you are asking for a different way to code that, a common way to do it is
if ( absf( angle_scaled_out - angle ) < tolerance ) is_oriented = 1;

Please Log in or Create an account to join the conversation.

More
23 Mar 2020 12:03 #161202 by alkabal
Replied by alkabal on topic Orient component
Thanks this is more cleaner like this !

I will ask mostly for advanced idea : something like use actual_velocity in the calcul for increase accuracy.
Or for increase speed regarding the angle_deviation.

For now this do the job i have no real need orient on this lathe because the encoder is 400ppr, 0.9° per pulse...

I have do this mostly because original component are for me too much difficult to setup and not easy to understand the code.

Please Log in or Create an account to join the conversation.

More
02 Apr 2020 01:01 #162421 by alkabal
Replied by alkabal on topic Orient component
I haven't news for now these revised component seem to work fine.

But i see something IMO wrong, when use M19 "halui.spindle.0.on" and "spindle.0.on" stay to False but the spindle is moving so i think this is a possible cause of problem.

What did you think ?

Please Log in or Create an account to join the conversation.

More
02 Apr 2020 19:25 #162481 by andypugh
Replied by andypugh on topic Orient component
Is there any connection between the *-spindle.0.on and the rest of HAL?

Normally they would be used to enable / disable the spindle drive.

But that might not be ideal in orient mode.

You need to decide how you want to handle spindle-enable.

Please Log in or Create an account to join the conversation.

Time to create page: 0.132 seconds
Powered by Kunena Forum