Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Math Exceptions for TwinCat Runtime #120

Open
bazoida opened this issue Apr 28, 2022 · 2 comments
Open

Fixed Math Exceptions for TwinCat Runtime #120

bazoida opened this issue Apr 28, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@bazoida
Copy link

bazoida commented Apr 28, 2022

Hi pantor.
Kudos for ruckig.

At the moment i implement your source code in c++ runtime environment twincat (17c++) First test cases seems to run smooth and nice. I'm impressed on the performance.

Next to a judge namespace war i made in twincat i also needed to adjust the maths.
https://github.com/bazoida/ruckig/tree/chore/fixMathForTwinCat/bazoida

Hint: Separated the includes working in twincat.

#pragma once

#ifdef windows
#include <cmath>
#include <numeric>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <sstream>
#endif// windows

#include <limits>
#include <optional>
#include <string>
#include <array>
#include <vector>
#include <algorithm>
#include <cstdlib>

namespace ruckig {
#ifdef windows
    typedef size_t SIZE_T;
#endif // windows

    const double Pi = 3.14159265358979323846264338327950;

    inline double Power2(double v) {
        return v * v;
    }

} // namespace ruckig


namespace std
{
#ifndef windows
    inline constexpr nullopt_t nullopt{ nullopt_t::_NulloptTag{} };

#endif // !windows
    template<class ForwardIt, class T>
    constexpr // since C++20
        void Iota(ForwardIt first, ForwardIt last, T value)
    {
        while (first != last) {
            *first++ = value;
            ++value;
        }
    }

    inline double Sqrt(double v) {
        if (isnan(v))
            return NAN;
        if (v < 0.0)
            return NAN;
        else
            return std::sqrt(v);
    }
}


TwinCat C++ seems to be more sensitive than the official legacy.

Perhaps you can have a look. I already tested the changes and also tracked your origin ramps and made a one to one comparison.

image

For TwinCat C++ in general we have to take care about 0 Divisions and negative Roots

@pantor
Copy link
Owner

pantor commented May 3, 2022

Hey @bazoida, thanks for your changes - I'm very much interested in TwinCAT for Ruckig!

Do you know where I can find information about which subset of C++ is supported in TwinCat? I've found the Beckhoff Reference, and there is section 12.4 about its limitations, but I can't find anything special about zero devision or nan handling there.

Btw, there is also struckig, a port of Ruckig to Structured Text. Might be of interest to you.

@pantor pantor added the enhancement New feature or request label May 3, 2022
@bazoida
Copy link
Author

bazoida commented May 10, 2022

Hi @pantor

C++ for TwinCat -> Come in and find out. Hehe. Unfortunately Documentation is the weak point on the system.

Mostly you can reach same methods as in standard legacies. TwinCat is doing a great job on rebuilding the std classes for usage in deterministic realtime context. Exception handling by now is really nice. With last versions i wouldn't know any argument except additional license, not using c++ fully for plc programming. i.e. c++ methods can fully be used within codesys environment.

image

I will soon provide a fork shared library for usage standard and twincat within our organization https://github.com/ZoiglValley Need some more tests with extrema, jog mode, reference mode, automatic switch position <-> velocity drive.

I know struckig. kudos for rebuilding your code in codesys. I'm the lazy guy. To be honest, i even don't understand your magic a bit. I just built a wrapper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants