Remote control by location (PIC in Oshonsoft)

Thread Starter

camerart

Joined Feb 25, 2013
3,835
Yes, it is ok.

I tested x, y = 0,1... 1,0....0,-1 and - 1, - 1 all correct.
0,1 gives 360. If needed could add:
if atn >= 360 then
atn = atn-360
Hi J,
Is it ok to change 'b' to 'bdeg'? There's another 'b' in the program.

Here's what I've tried, but it didn't work. Does it look ok?
C.

'VVVVVVVVVVVVVVVVVVVVVVVVVVVV DEGREE CALC VVVVVVVVVVVVVVVVVVVVV
'Result in degrees clockwise from North = 0

Function atn(x_c As Single, y_c As Single) As Single

If y_c = 0 Then
y_c = y_c + 0.000001 'to prevent divide by zero
Endif

tang = x_c / y_c
at1 = 90 * tang * (bdeg + tang) / (1 + 2 * bdeg * tang + tang * tang)
at2 = -90 * tang * (bdeg - tang) / (1 - 2 * bdeg * tang + tang * tang)

If x_c >= 0 Then
If y_c > 0 Then
atn = at1
Endif
Endif

If x_c >= 0 Then
If y_c < 0 Then
atn = 180 - at2
Endif
Endif

If x_c < 0 Then
If y_c < 0 Then
atn = 180 + at1
Endif
Endif

If y_c > 0 Then
If x_c <= 0 Then
atn = 360 - at2 'atn2 ?????????????????
Endif
Endif

End Function

'AAAAAAAAAAAAAAAAAAAAAAAAAAAA DEGREE CALC AAAAAAAAAAAAAAAAA
 

jjw

Joined Dec 24, 2013
823
How does it not work?
Needs const bdeg= 0.596227 and Dim tang as single.
It is not necessary to change x, y to x_c, y_c.
x, y are function arguments. When the function is called they will be replaced with whatever variables are used in the calling program.
Edit: also Dim at1 as Single, Dim at2 as Single are missing. My fault.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,835
How does it not work?
Needs const bdeg= 0.596227 and Dim tang as single.
It is not necessary to change x, y to x_c, y_c.
x, y are function arguments. When the function is called they will be replaced with whatever variables are used in the calling program.
Edit: also Dim at1 as Single, Dim at2 as Single are missing. My fault.
Hi J,
I had set up:
Const bdeg = 0.596227
Dim tang As Single
Dim at1 As Single
Dim at2 As Single

X and Y are what's READ from the compass, then they go 'two's compliment as Y_nc and Y_nc (not calibrated) then they go through MAGMASTER calibration as X_c and Y_C and (calibrated) then the go into your calculation.

I'll re-check tomorrow, if you think generally it looks as you would expect.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,835
What do you get from atn with some known values of x_c, y_c
atn(x, y) wants x, y as singles.
Hi J,
I think I was too ambitious, trying it on the big program.

Here's a try on a small program with only 5110 and Compass.

Result: DEG = -168064.00

I'll re-check everything.

EDIT: Will you give me examples of x_c and x_c for testing please?
C
 

Attachments

Last edited:

jjw

Joined Dec 24, 2013
823
Hi J,
I think I was too ambitious, trying it on the big program.

Here's a try on a small program with only 5110 and Compass.

Result: DEG = -168064.00

I'll re-check everything.
C
Something is really wrong.
The atn() gives only values 0-90 or 0- - 90
Put constants and Dims of variables used by the atn function inside the function. Now it is difficult to search where and what they are.
The x and y in the original function are arguments.
You can then use variables from your program, when you call the function, eg. DEG = atn( x_c, y_c)
DEG, x_c, y_c must be floating point.

For testing you could use x, y
0,1 - > 0
1,0 - > 90
0, - 1 - > 180
-1,0 - > 270
1,1 - > 45 etc.
or use calculator: input an angle, cos(angle) - > x sin(angle) - > y
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,835
You have call atn(), no arguments, no variable for the result!
It should be DEG=atn( x_c, y_c)
Hi J,
I don't fully understand your last two messages e,g, I don't know what an ARGUMENT is, but the attached program is working.:)

It appears to be an Octant out, but that could be many reasons. I'll test it against a compass, and report back.
Many thanks,
C.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,835
I don't know what an ARGUMENT

hi C,
Look at this diagram, you can have more that one Argument [ a value] passed to the Function.
E
Hi E,
A good explanation. I think the use of badly chosen words, like ARGUMENT, PRAGMA, VOID etc, get rejected, unless I use them lots of time.

Thanks, C.
 

jjw

Joined Dec 24, 2013
823
Hi J,
I don't fully understand your last two messages e,g, I don't know what an ARGUMENT is, but the attached program is working.:)

It appears to be an Octant out, but that could be many reasons. I'll test it against a compass, and report back.
Many thanks,
C.
In Monty Python there was an office, where you could buy an argument.
This is something different.
https://en.m.wikipedia.org/wiki/Parameter_(computer_programming)
What do you mean by octant out.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,835
Hi J,
I actually knew what ARGUMENT meant a year or so ago, but as with many things, they come and go from my mind, especially if they're none sensible words. I could have looked it up, but I use my time working on what I consider more relevant things.

It's not an octant out but it shows zero when pointing about 35Deg east. As it is now incrementing 0-359 is when moving CCW It would be better if it moved CW for incrementing.

The readings are unpredictable, and don't seem to change even if I comment out 'Call atn()' so something's wrong.
C.
 

jjw

Joined Dec 24, 2013
823
Do you mean that the compass gives wrong values so that you get zero at 35 degrees east.
Maybe it needs calibration again.
Atn() is tested to be working 0-360
CW/CCW can be changed easily.
I had an error in thinking that x goes from 0 to + when turning CW.
 

jjw

Joined Dec 24, 2013
823
Hi J,
I actually knew what ARGUMENT meant a year or so ago, but as with many things, they come and go from my mind, especially if they're none sensible words. I could have looked it up, but I use my time working on what I consider more relevant things.

It's not an octant out but it shows zero when pointing about 35Deg east. As it is now incrementing 0-359 is when moving CCW It would be better if it moved CW for incrementing.

The readings are unpredictable, and don't seem to change even if I comment out 'Call atn()' so something's wrong.
C.
Delete call atn() permanently, if it is literally like that.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,835
Delete call atn() permanently, if it is literally like that.
Hi J,
Yes, the compass gives zero when aimed about 30Deg. There is a procedure for calibrating each compass module, I can see the problem is somewhere in the calibration or ATN procedure, which can be corrected later.

I've tried the compass in the big program, but it appears to have broken the ALTIMETER, the TEMP still looks ok though, so the both modules are being READ ok.

With your permission, I would like to fit the PCB into the Transmitter and connect the Incremental encoder and potentiometers, then once I've proved the PCB and connections are ok, we can come back and correct each module.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,835
Hi,
While populating the RX PCB, I realised that temporarily I could use it as a TX TEST PCB, so I added a compass (not calibrated) and an HC12 radio module. I can now fit the 1st PCB into the Transmitter and connect the POTS and incremental encoder, for testing.

Here is a program we can modify the TEST PCB to get the compass working:

I'll show results later.

C.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,835
Hi,
I've calibrated the compass module and updated the program in #396

While first testing, I was getting 0-359 results, but now the results of a full circle are always a narrow spectrum of 'say' 270 to 310 app. ???. I've re-tried earlier programs, but they are all the same
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,835
Hi,
I re-configured the connections and tried the DEG/AZI program on the 'old' PCB, it worked better, but again with errors.

I tried different MAGMASTER BIAS, and the READings changed quite a bit, so perhaps this is where the errors are being generated??
C.
 

jjw

Joined Dec 24, 2013
823
The old bias values were very different from #396.
Is it the same chip and calibrated in the same place?
 
Last edited:
Top