diff --git a/src/emc/motion/simple_tp.c b/src/emc/motion/simple_tp.c index 92394bce6ac..3f117c1510e 100644 --- a/src/emc/motion/simple_tp.c +++ b/src/emc/motion/simple_tp.c @@ -205,8 +205,12 @@ void simple_scurve_tp_update(simple_tp_t *tp, double period){ } } }else{ + /* at the target: stop here, without the step the last cycle's + speed would still take, which would put it back outside */ vel_req = 0.0; tp->curr_jerk = 0; + curr_vel = 0.0; + curr_acc = 0.0; } /* a max_vel lowered under the current speed is reached by the ramp diff --git a/tests/jog-speed-change/README b/tests/jog-speed-change/README index 5653ec1fbc0..cbda3b1da56 100644 --- a/tests/jog-speed-change/README +++ b/tests/jog-speed-change/README @@ -1,6 +1,7 @@ A continuous jog asked again at a lower speed while it runs, as halui does when halui.axis.jog-speed or halui.joint.jog-speed changes while a jog pin is held: the speed comes down to the new one within the -acceleration limit. A joint jog in free mode and a world jog in teleop -mode, every servo cycle sampled, on the trapezoid and on the S-curve -planner. +acceleration limit. Then an incremental jog of each, which must end +where it was sent and not go back and forth over its end. A joint jog +in free mode and a world jog in teleop mode, every servo cycle sampled, +on the trapezoid and on the S-curve planner. diff --git a/tests/jog-speed-change/sim.hal b/tests/jog-speed-change/sim.hal index efc26461f7b..443dfbbafb2 100644 --- a/tests/jog-speed-change/sim.hal +++ b/tests/jog-speed-change/sim.hal @@ -1,8 +1,9 @@ loadrt [KINS]KINEMATICS loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS -# the commanded velocity of joint 0 and of axis X every servo cycle -loadrt sampler depth=4000 cfg=ff +# the commanded velocity of joint 0 and of axis X every servo cycle, and +# whether motion is in teleop, where the joint's comes from the cubic +loadrt sampler depth=4000 cfg=ffb addf motion-command-handler servo-thread addf motion-controller servo-thread @@ -10,6 +11,7 @@ addf sampler.0 servo-thread net VJ joint.0.vel-cmd => sampler.0.pin.0 net VX axis.x.teleop-vel-cmd => sampler.0.pin.1 +net TM motion.teleop-mode => sampler.0.pin.2 loadusr halsampler -t samples.log net J0 joint.0.motor-pos-cmd => joint.0.motor-pos-fb diff --git a/tests/jog-speed-change/test-ui.py b/tests/jog-speed-change/test-ui.py index a27fef12831..5130a7a0889 100755 --- a/tests/jog-speed-change/test-ui.py +++ b/tests/jog-speed-change/test-ui.py @@ -49,7 +49,9 @@ def wait_for(what, test, timeout=30): def settled(): wait_for("the machine to stop", - lambda: s.inpos and not hal.get_value("motion.jog-is-active")) + lambda: s.inpos and not hal.get_value("motion.jog-is-active") + and hal.get_value("joint.0.vel-cmd") == 0 + and hal.get_value("axis.x.teleop-vel-cmd") == 0) def slow_down(jjog, what): # FAST, then the same jog again at SLOW while it still runs @@ -66,6 +68,19 @@ def slow_down(jjog, what): settled() drain() +def step(jjog, what): + # an incremental jog of 5, in the same direction as the others; the + # position read from HAL, live like the speeds settled() waits on + before = hal.get_value("joint.0.pos-cmd") + c.jog(linuxcnc.JOG_INCREMENT, jjog, 0, FAST, 5) + wait_for("%s to start" % what, lambda: hal.get_value("motion.jog-is-active"), timeout=5) + settled() + moved = hal.get_value("joint.0.pos-cmd") - before + print("%s: an incremental jog of 5 moved %.9f" % (what, moved)) + if abs(moved - 5) > 1e-5: + error("%s: an incremental jog of 5 moved %.9f" % (what, moved)) + drain() + h = hal.component("test-ui") h.ready() @@ -83,22 +98,25 @@ def slow_down(jjog, what): c.wait_complete(30) wait_for("free mode", lambda: s.motion_mode == linuxcnc.TRAJ_MODE_FREE) slow_down(True, "joint 0") +step(True, "joint 0") # a world jog in teleop mode c.teleop_enable(1) c.wait_complete(30) wait_for("teleop mode", lambda: s.motion_mode == linuxcnc.TRAJ_MODE_TELEOP) slow_down(False, "axis X") +step(False, "axis X") # every servo cycle: the speed comes down to SLOW within the acceleration -# limit, it does not drop at once +# limit, it does not drop at once; and every jog runs one way, so a speed +# the other way is a jog going back and forth over its end time.sleep(0.5) with open(LOG) as f: lines = f.read().split("\n") samples = [] for line in lines[:-1]: v = line.split() - if len(v) == 3: + if len(v) == 4: samples.append([float(x) for x in v[1:]]) print("%d samples" % len(samples)) for i, what in enumerate(("joint 0", "axis X")): @@ -113,6 +131,10 @@ def slow_down(jjog, what): error("%s ran at %.3f, over the %.3f asked" % (what, vpeak, FAST)) if apeak > ACC * 1.001: error("%s accelerated at %.2f, over its limit of %.2f" % (what, apeak, ACC)) + # the joint's own planner runs in free mode only + back = sum(1 for v in samples if v[i] < 0 and (i == 1 or not v[2])) + if back: + error("%s ran backwards in %d servo cycles" % (what, back)) if not samples: error("no samples") overruns = int(hal.get_value("sampler.0.overruns"))