# GPS controlled NMEA DATA following tracker

#### camerart

##### Active Member
Hi,

Firstly, I have other threads on this subject open, but they could be confusing!! e,g, (http://www.electro-tech-online.com/threads/gps-data-tracker-for-antenna-aiming.140729/) So I hope that this one is clearer? I have attached a program, that has been written and helped by others on this and other forums, so thanks to them.

What the program does is read an azimuth or AZIMVAL angle as a 3x digit number e,g, 090 = 90degrees. The tracker compares this with a base angle POSCNT set to '0' at north and counts round 360 degrees, so if AZIMVAL = 090 then the tracker moves round 90 counts till it points at 90degrees. There are a number of extra things to note, such as degrees are actually counted as a 4 digit number so 090 = 0900. also counts are QUADRATURE etc.

The program has gone through many revisions. I have spent a long time testing PWM, velocity, slow and fast braking etc, but find the best results have been from the more simple: 'If AZIMVAL<POSCNT then go one way and visa versa. If AZIMVAL=POSCNT then stop'. This sometimes works and stops, but over-runs a few degrees, and sometimes oscillates within the SETPOINT or '1deg' either side. What is happening is, as the SETPOINT is passed the program re-sets AZIMVAL, so there can be no more comparisons before actually stopping.

What I am hoping for is at SETPOINT set BRAKE and wait for a split second till stopped before updating AZIMVAL so it can keep comparing. Later if necessary, I can widen the each side of SETPOINT degrees till the BRAKE stops at or near SETPOINT. I think the fast oscillations with introduce a kind of PWM, but I'm not sure, so hopefully only '1' bounce will occur.

The program is ok above the '////////////////////////////// line. (Check for errors)

I hope it's all understandable and looking forward to any replies. (I will update this post if there are any errors.)

EDIT: I've made some progress with the attached program. This now stops at the SET POINT. It will receive data at 1sec intervals, but perhaps errors if the data is too far to move before the next is received. It would be better if the incoming data was held ready for the next input instead of as it is now. Also the timer0 needs setting.

Camerart.

#### Attachments

• 8.2 KB Views: 248
Last edited:

#### camerart

##### Active Member
I have updated the program, which needs more work, but does stop at the set-point received. It stops abruptly at the set-point, which I'm sure could be corrected with PWM, as previous programs, but for me this is too difficult.

One thing to note is that: The motor I'm using has magnetic poles that won't allow it to stop and stay in the same position. This means that if the same data is input repeatedly, the motor will keep trying to correct slightly. I will try widening the set-point from 1 deg to 'say' 3deg. Other motor may have different characteristics.

Camerart.

#### granddad

##### Active Member
Hi camerart , Top marks for your perseverance with your project ... the motor stopping thing will depend on the number of poles , if you could gear down the output you would get a 'finer' position .

#### camerart

##### Active Member
Hi camerart , Top marks for your perseverance with your project ... the motor stopping thing will depend on the number of poles , if you could gear down the output you would get a 'finer' position .
Hi G,

I made the tracker over a year ago, much work! There aren't many options but to persevere and get it working or skip it (I'm sure I've bored people to death with it)

Regarding the motor poles: The motor has a 1:100 gearbox with an opto disk on the motor rotor. The motor has 10 steps and the opto disk has 36 steps, which don't always match.

HAPPY NEW YEAR

C.

#### camerart

##### Active Member
Hi,
The program attached in post #1 mostly stops at the SETPOINT, but sometimes doesn't stop at BRAKE as it passes '0' and bounces back from the reverse motor direction and then oscillates.
I am now trying to widen the DEADBAND by '1' degree each side of SETPOINT where the BRAKE is applied. The BRAKE will be on over 3degrees.

I have attached the latest program. It brakes if '0'OR'1' is entered it simulates and BRAKES then resets.

I know there are errors, but my question is: Below the OUTSIDEDEADBAND: line. Is the way I've written lines such as (If poscnt - azimvaltemp - 20 >= 1800 Then) correct?

Any other corrections welcomed.

EDIT:Program in post#1 updated

C.

#### Attachments

• 10.2 KB Views: 166
Last edited:

#### camerart

##### Active Member
Hi,

I've realised that there is a problem when subtracting a DEADBAND around the zero point of a 360degree circle. As Oshonsoft doesn't cater for negative numbers (Correct me if I'm wrong) if a DEADBAND is subtracted from a number that takes it negative, then it doesn't work. Is there a way round this please?

C.

#### jjw

##### Member
Hi,

I've realised that there is a problem when subtracting a DEADBAND around the zero point of a 360degree circle. As Oshonsoft doesn't cater for negative numbers (Correct me if I'm wrong) if a DEADBAND is subtracted from a number that takes it negative, then it doesn't work. Is there a way round this please?

C.
If deadband > degrees you can subtract with 360+degrees-deadband

#### ericgibbs

##### Well-Known Member
Most Helpful Member
hi C,
I mini-demo Basic program showing how to use Single variables for the Sign.
E

#### Attachments

• 6.7 KB Views: 176
• 1.2 KB Views: 154

#### jjw

##### Member
I think in the demo it should be:
If a < 0 Then
a = 360 + a
The demo gives correct result only if x is exactly 0

With integers ( unsigned ) it is also easy:
If x < y Then
a = 360-(y-x)
Else a=x-y

#### camerart

##### Active Member
Hi E and J,

I looked a the examples posted, thanks. Also noticing a difference of opinion.

If you look at the image posted, you will see that 'A' is entered as a Degree then a calculation x it by 9.95 to make it match 'B' which is a count 0000 to 3581 being a 360 Degree circle. I'm concerned about crossing zero, when 'B' will flip from 3581 to 0000 or 0000 to 3581.

I want to 'in this case' have a 20 count each side of the SETPOINT as a DEADBAND. Bear in mind that Oshonsoft doesn't like decimal points.

How does this affect your answers, please?

C.

#### Attachments

• 6.9 KB Views: 153

#### ericgibbs

##### Well-Known Member
Most Helpful Member
Bear in mind that Oshonsoft doesn't like decimal points.
hi C
Look at this, NOTE: the use of SINGLE variable!!!
Define SINGLE_DECIMAL_PLACES = 2

Code:
Define CONFIG = 0x23e4
Define CONFIG2 = 0x3eff

'16F887
AllDigital
Define SIMULATION_WAITMS_VALUE = 1  '''''''''''''''''''
Define SINGLE_DECIMAL_PLACES = 2

Define CLOCK_FREQUENCY = 8
Define SPICLOCK_STRETCH = 5
Define I2CCLOCK_STRETCH = 10  ''20  ''50
Define I2CREAD_DELAYUS = 100  '200  ''400

Define LCD_INITMS = 2
Define LCD_LINES = 4
Define LCD_CHARS = 20
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4
Define LCD_EREG = PORTB
Define LCD_EBIT = 3
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 2
Define LCD_RWREG = PORTB
Define LCD_RWBIT = 1
Define LCD_READ_BUSY_FLAG = 1

ADCON0 = %01000011
ADCON1 = %10001110
ANSEL = %00000011
OSCCON = %01110000

TRISA = %000011111
TRISB = %00000001
TRISC = %11000011
TRISD = %00001111
TRISE = %00000111

Dim x As Single
Dim y As Single
Dim a As Single

x = 0  '000 degree
y = 10.75  'band

Lcdinit
WaitMs 100
Lcdcmdout LcdLine1Home
Lcdout "x= ", #x, "    ", " y = ", #y

main:

a = x - y

Lcdcmdout LcdLine2Home

Lcdout "a= ", #a
If a < 0 Then
Lcdcmdout LcdLine3Home
Lcdout "a is minus value"
a = a + 360
Lcdcmdout LcdLine4Home
Lcdout "So, Drive ", #a, "deg"
Endif

Goto main

End

#### Attachments

• 6.1 KB Views: 170

#### camerart

##### Active Member
Hi Eric,

Bear in mind that Oshonsoft doesn't like decimal points.

Define SINGLE_DECIMAL_PLACES = 2 'in program.

C.

#### Attachments

• 9.5 KB Views: 167
Last edited:

#### jjw

##### Member
Hi Eric,

Bear in mind that Oshonsoft doesn't like decimal points.

Define SINGLE_DECIMAL_PLACES = 2 'in program.

C.
You have to use single variables for that.

#### camerart

##### Active Member
You have to use single variables for that.
Hi J,

That did the trick, thanks.

C,

#### ericgibbs

##### Well-Known Member
Most Helpful Member
hi C,
Didn't you read thru my program listing??
Dim x As Single
Dim y As Single
Dim a As Single

E
Also from Post #8
I mini-demo Basic program showing how to use Single variables for the Sign

#### camerart

##### Active Member
hi C,
Didn't you read thru my program listing??
Dim x As Single
Dim y As Single
Dim a As Single

E
Also from Post #8
I mini-demo Basic program showing how to use Single variables for the Sign
Hi Eric,

I did scan it, and noticed that TRISA has 9bits, but missed the SINGLEs.

What do these lines do? They're not for my puspose are they?
Define SPICLOCK_STRETCH = 5
Define I2CCLOCK_STRETCH = 10 ''20 ''50
Define I2CREAD_DELAYUS = 100 '200 ''400

Thanks, C.

#### ericgibbs

##### Well-Known Member
Most Helpful Member
hi C,
Those SPI/I2C lines are from a bigger program which I chopped down to create the demo, I should have deleted them.

Interesting that the Compiler didn't pick up on that PORTA typo.?

Do you now have sufficient info in order to solve the 'minus' and 'deci-points' problems.?
E

#### camerart

##### Active Member
hi C,
Do you now have sufficient info in order to solve the 'minus' and 'deci-points' problems.?
E
Hi Eric,

I've probably got enough info, time will tell if I've got enough brain cells.

C.

#### camerart

##### Active Member
Hi,

I have an = that uses dband, but the dband variable shows more that two decimal places, so is not exactly the same, which doesn't work. Any ideas please?

C.

#### Attachments

• 1.4 KB Views: 165
• 2 KB Views: 160
• 1.8 KB Views: 168

#### jjw

##### Member
The single type variable has 7 digit precision in calculations.
Single_decimal_places = 2 means that only 2 decimals are displayed.

Last edited:

Loading