-
Notifications
You must be signed in to change notification settings - Fork 2
/
gps-tracking-from-array.py
77 lines (57 loc) · 1.75 KB
/
gps-tracking-from-array.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import asyncio
import time
import math
import csv
from boxbot import BoxBot
from boxbot import PIDController
from viam.robot.client import RobotClient
from viam.rpc.dial import Credentials, DialOptions
from viam.components.motor import Motor
from viam.components.movement_sensor import MovementSensor
# PID parameters
kp = 0.08 # Proportional gain
ki = 0.002 # Integral gain
kd = 0.2 # Derivative gain
# Integral term saturation limits
integral_max = 400 # Adjust as needed
integral_min = -400 # Adjust as needed
GPSarray = [
[40.770624, -73.978119],
[40.770541, -73.978177],
[40.770617,-73.978149],
[40.770542,-73.978209],
[40.770629,-73.978168],
[40.770550,-73.978221],
[40.770630, -73.978180],
[40.770552,-73.978241]
]
data=[]
async def connect():
creds = Credentials(
type='robot-location-secret',
payload='REDACTED')
opts = RobotClient.Options(
refresh_interval=0,
dial_options=DialOptions(credentials=creds)
)
return await RobotClient.at_address('REDACTED', opts)
async def main():
robot = await connect()
xsens = MovementSensor.from_robot(robot, "xsens")
pid = PIDController(kp, ki, kd, integral_max, integral_min)
boxbot = BoxBot(robot)
gps = MovementSensor.from_robot(robot, "gps")
#while True:
for x in GPSarray:
print('next point: ')
print(x[0])
print(", ")
print(x[1])
await boxbot.gotopoint(boxbot,gps,pid,xsens,x[0],x[1],data)
print(data)
with open("raster5", 'w', newline='') as csvfile:
csv_writer = csv.writer(csvfile)
csv_writer.writerow(['lat', 'long'])
csv_writer.writerows(data)
if __name__ == '__main__':
asyncio.run(main())