Timer not accurate?

Hi, I’m trying to do a simple experiment in order to determine gravitational acceleration using metal ball which is dropped from a gripper by a servo and falls on a plastic plate on which a shock sensor is stuck.
The idea is to get the time since servo is released to when the ball lands and use it do some calculation to find out g.

When I push a button, servo is released along with a pulse that goes into delta time node along with the impulse from the shock sensor, via an ANY node.

My problem is that my final result is too low, meaning the time detected and calculated using delta time is too big.

Do you have any idea why this is happening?

How far are you dropping it? What result are you expecting vs what you get? Which puls… nodes are you using? Does the shock sensor only detect initial hit, or is it detecting bounces & adding that time?

The shorter your drop, the greater any error is going to show up. One possible source of error is how quickly the servo releases. Just because you have pressed the button and started the servo, does not mean it is releasing immediately. Would it be more accurate to use light sensors to generate pulses? Ball has dropped when top sensor sees light, reached “destination” when bottom sensor sees dark; Top sensor should be low enough to JUST be blocked by top of ball (or low enough it is ALMOST blocked by bottom of ball), bottom sensor can be above the ground so it does not detect any bounce.

Another source of error might be Arduino is busy doing something else when button or shock sensor is triggered. Servo and I2C communication both use timers & interrupts that can “distract” the Arudino. If you are using light sensor for top trigger, you can manually release ball rather than using servo. You can disable LCD until you have a result to display.

Height is 60cm and it records the bunce but only shows the result when delta is less than 0.2, I couldn’t find any other way to record just the first pulse and record the others.
I added a physical contact on the gripper now so when the ball is released a FALSE is recorded and a pulse is sent to the delta node and this reduced the error a lot but not enough.
I tried to disable the LCD but without any success. How can I do it?
What other ways are there to make it more accurate?

Screenshot attached, thanks a lot for your help.

You disable LCD by setting the ACT pin to false until you are ready to display something.

delta-time records the start time on RST, then calculates current_time - start_time for each UPD. This means if sensor is recording bounce, it will time from release until last bounce is detected, not initial hit. You might be able to use debounce or extra logic to limit delta-time-UPD to only pulse on initial hit. That is kind of what you are trying to do with pass-if on output, but there is a chance the sensor will pulse pass-if before pass-if-COND has updated, and in your case, delta-time is returning time from release to last bounce, not time between bounces, so you are not ignoring bounce times by ignoring short delta-time.

In general, it is better to limit input rather than output. If delta-time only receives one UPD pulse, there is only one set of calculations to run. By using pass-if on output to do the same thing, you are likely running calculations multiple times, but ignoring all but the 1st set of calculations.

I’m trying to use debounce but I can’t see ho because IN value will change for a short time with every bounce and will change for all subsequnt bounces so all values will go thru, if that makes sense.
On the other side, is there any node to store an array and release just the first position or something like this?
Can’t see any other way of doing it.

Output of delta-time is zero only if it has been RST with no UPD, so if output is not zero, don’t allow UPD (block UPD pulse using ‘gate’ node):

image

This will not work if equal/defer/gate doesn’t update before your ball bounces. I have no idea how long it might take gate to close…

Just tried it, is not working, second bounce still gets thru.
Maybe gate is too slow.

If I understand your problem, you essentially have a Start and a Stop that happens quickly, and you need to get the difference. The attached shows 2 methods, where Method 1 is better than Method 2…

Example shown with 174.124 mS between pressing Button Start and Stop (just substitute your own sensor signal switch)

Method1: use the XOD tools, and store the delta-micros in a buffer… Very efficient.

Method2: store the micros in two buffers, and you have to change the subtract node to use “float” instead of “auto” (at least it didn’t work with auto for me). AFTER changing micros to millis (with another custom node).

#pragma XOD dirtieness disable

node {
    void evaluate(Context ctx) {
        float x = getValue<input_IN1>(ctx);
        float y = getValue<input_IN2>(ctx);

        emitValue<output_OUT>(ctx,  x - y);
    }
}

node {
    void evaluate(Context ctx) {
        float micros = getValue<input_IN>(ctx);
        emitValue<output_OUT>(ctx, micros / 1000 );
    }
}

I did use the regular XOD/Button (I guess has a 20mS Debounce)… I not sure if this would help you. But, maybe one of the two methods can be adapted to completely avoid the Debounce problem, altogether? Another option, if your experiment apparatus setup is limited by the electronics, then maybe change the apparatus? Bigger? Lighter ball? Toss slower?

microsecond-signal-timer
here’s the code: microsecond-signal-timer.xodball (14.7 KB)

Method with the Debounce Gates… If you really have some debounce issues, then the Gates may be implemented to debounce the signals as follows:

microsecond-signal-timer.xodball (29.6 KB)

Thanks anlot, there’s some heavy lifting in your solutions, I need to find some time to go thru them.
To define the problem, I have a ball who falls and bounces on a surface that has a shock sensor attached.
What I need is to get the first pulse from the first bounce but ignore the others immediately after the read, without slowing down the time, so I can have an as accurate as possible calculation for g.
At the moment, I’m limiting the recorded delta to more than 0.2 which is fine for now but I don’t know if is the fastest solution because my current g is still a bit smaller than it should be.
I thonk it’s fine for what I need to prove now but I really want to find the most accurate possible solution because I love xod and I want to go further and try new things with it, maybe try to teach some people to use it, people like me which don’t know c/c++.

Great! Try it out… Just use two buttons, or a piece of wire from D2 and D4 on and off to GND…
Also, consider replacing the actual button nodes in my example, with the signal from your project…
Also, also, consider using an “Interrupt” Rising/Falling edge for the “Stop” condition (If you need super fast sensing).

The examples I gave should work for your bouncing ball issue… no longer an issue.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.