problem with trig functions?

Gtuner IV general support. Operation, questions, updates, feature request.

problem with trig functions?

Postby WaffleHouse2t2 » Wed Apr 28, 2021 4:53 am

Maybe I'm doing this wrong, found this while developing my first script. This is a minimal script to show the problem. I'm not sure if the trig functions are embedded in the Titan Two device or are added by Gtuner or something else.

Code: Select all
 
#pragma METAINFO("problem-trig", 1, 0, "WaffleHouse2t2")
 
/****
There appears to be glitches in the trig functions.
 
This is on a Titan Two (firmware 1.11.3.0),
connected to a Windows 10 PC,
running Gtuner IV version 1.11.3.1.
 
For cos(), between  80 and 100 degrees there is a jag.
For sin(), between 170 and 190 degrees there is a jag.
 
I grew up using degrees, I am not used to using radians.
I think the problem is *not* in deg2rad() function.
 
In Device Monitor
drag GPC Designator STICK_2_X to one of the channels,
drag STICK_2_Y to another channel.
Run the channel log, run the script.
Observe the channel output curves.
Terminate the script and channel right after a jag.
(To terminate the script, press one of the Memory Slot buttons on the Titan Two.)
Scroll thru the Output Panel to see where the jag happened.
 
 
2021 Apr 27    WaffleHouse2t2    Initial code.
 
 
****/

 
fix32 degrees = 0.0;
fix32 radians;
fix32 xx;
fix32 yy;
 
main
{
 
  if ( !output_x )
  {
    radians = deg2rad(degrees);
    xx = cos(radians) * 100.0;
    yy = sin(radians) * 100.0;
 
    printf("degrees %3.2f  radians %3.3f  xx %3.3f  yy %3.3f", degrees, radians, xx, yy);
 
    combo_run(output_x);
 
    degrees = degrees + 1.0;
    if ( degrees >= 360.0 )  degrees = 0.0;
  }
}
 
combo output_x
{
  set_val(STICK_2_X, xx);
  set_val(STICK_2_Y, yy);
  wait(20);
}
 
Human beings make life so interesting.
Do you know, that in a universe so full of wonders,
they have managed to invent boredom.
-- Death in Terry Pratchett's "Hogfather"
User avatar
WaffleHouse2t2
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Tue Jul 10, 2018 3:23 pm
Location: California, USA

Re: problem with trig functions?

Postby Mad » Wed Apr 28, 2021 5:15 am

Place this at the very top of your script (Dont@Me's fix):
Code: Select all
fix32 _COSINE_(fix32 a, bool b) { /* cos/sin fix */
  if ((a = mod(a + 6.28319, 6.28319)) < 0.0) a = mod(a += 6.28319, 6.28319);
  if (a > 0.785522 && a < 3.92761) return b ? sin(1.5708 - a) : cos(1.5708 - a);
  return b ? cos(a) : sin(a);
}
#define sin(a) (_COSINE_(a))
#define cos(a) (_COSINE_(a, 1))
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord
Mad
Major General
Major General
 
Posts: 4536
Joined: Wed May 22, 2019 5:39 am

Re: problem with trig functions?

Postby WaffleHouse2t2 » Wed Apr 28, 2021 4:04 pm

Thank you Mad for the work-around and quick reply. I made the patch into an include file.

Had this problem already been reported? I searched these forums but didn't find anything that I thought was relevant.

Hmmm, it occurs to me that there may be other glitches and work-arounds like this. Consider creating a restricted forum that anyone can read but only select members can write. Each topic would be about a particular glitch and work-around, maybe with pointers to other relevant posts. If a glitch is finally corrected, a final post would have the version, maybe adjust the initial post to include "fixed" in the subject. Yeah, I know, more work for someone. Well, it was a thought/hallucination. :-)

Thanks again.
Human beings make life so interesting.
Do you know, that in a universe so full of wonders,
they have managed to invent boredom.
-- Death in Terry Pratchett's "Hogfather"
User avatar
WaffleHouse2t2
Staff Sergeant
Staff Sergeant
 
Posts: 11
Joined: Tue Jul 10, 2018 3:23 pm
Location: California, USA

Re: problem with trig functions?

Postby Mad » Wed Apr 28, 2021 10:46 pm

I had actually forgot to report this, so I have done it now: https://github.com/J2Kbr/TitanTwo/issues/303

You can submit your own issues to github or you can PM me on here or Discord. :smile0517:
ConsoleTuner Support Team || ConsoleTuner Discord || InputSense Discord
Mad
Major General
Major General
 
Posts: 4536
Joined: Wed May 22, 2019 5:39 am


Return to Gtuner IV Support

Who is online

Users browsing this forum: No registered users and 68 guests