-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
103 lines (93 loc) · 3.35 KB
/
main.go
File metadata and controls
103 lines (93 loc) · 3.35 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"fmt"
"math/rand"
"os"
"strconv"
"time"
log "github.com/Sirupsen/logrus"
"github.com/gatorloopdatagenerator/database"
_ "github.com/go-sql-driver/mysql"
)
func random(min, max float64) float64 {
return rand.Float64()*(max-min) + min
}
func getVelAccandPos(currentVel, currentAcc, currentPos float64, accelerationInterval float64) (float64, float64, float64) {
if currentPos > 1609 {
currentAcc -= accelerationInterval
if currentVel <= 0 {
return 0, 0, currentPos
}
} else {
currentAcc += accelerationInterval
}
currentVel = currentVel + currentAcc/20
if currentVel > 250 {
currentVel = 250
currentAcc = 0
}
currentPos = currentPos + currentVel/20
return currentVel, currentAcc, currentPos
}
var acceleration, velocity, position, pressure, roll, pitch, yaw, temperature float64
var pVoltage, pSOC, pTemp, pAmpHour float64
var aVoltage, aSOC, aTemp, aAmpHour float64
var startTime time.Time
var accelerationInterval float64
func main() {
database.InitDB()
if len(os.Args) == 2 && os.Args[1] == "cleanup" {
database.DB.Exec("DELETE FROM gatorloop.Acceleration")
database.DB.Exec("DELETE FROM gatorloop.Position")
database.DB.Exec("DELETE FROM gatorloop.Rotation")
database.DB.Exec("DELETE FROM gatorloop.Temperature")
database.DB.Exec("DELETE FROM gatorloop.Velocity")
database.DB.Exec("DELETE FROM gatorloop.PrimaryBattery")
database.DB.Exec("DELETE FROM gatorloop.AuxiliaryBattery")
log.Info("Deleted all entries in database")
return
} else if len(os.Args) == 2 {
interval, err := strconv.Atoi(os.Args[1])
accelerationInterval = float64(interval)
if err != nil {
fmt.Println("This program only accepts cleanup or an integer to specify acceleration interval")
os.Exit(1)
}
}
pSOC = 1.0
aSOC = 1.0
rand.Seed(time.Now().Unix())
startTime = time.Now()
resetAcceleration := false
for {
database.DB.Exec("INSERT INTO gatorloop.Acceleration VALUES(NULL, " + fmt.Sprintf("%f", acceleration) + ")")
database.DB.Exec("INSERT INTO gatorloop.Position VALUES(NULL, " + fmt.Sprintf("%f", position) + ")")
database.DB.Exec("INSERT INTO gatorloop.Pressure VALUES(NULL, " + fmt.Sprintf("%f", pressure) + ")")
database.DB.Exec("INSERT INTO gatorloop.Rotation VALUES(NULL, " + fmt.Sprintf("%f,%f,%f", roll, pitch, yaw) + ")")
database.DB.Exec("INSERT INTO gatorloop.Temperature VALUES(NULL, " + fmt.Sprintf("%f", temperature) + ")")
database.DB.Exec("INSERT INTO gatorloop.Velocity VALUES(NULL, " + fmt.Sprintf("%f", velocity) + ")")
database.DB.Exec("INSERT INTO gatorloop.PrimaryBattery VALUES(NULL," + fmt.Sprintf("%f,%f,%f,%f", pVoltage, pSOC, pTemp, pAmpHour) + ")")
database.DB.Exec("INSERT INTO gatorloop.AuxiliaryBattery VALUES(NULL," + fmt.Sprintf("%f,%f,%f,%f", aVoltage, aSOC, aTemp, aAmpHour) + ")")
velocity, acceleration, position = getVelAccandPos(velocity, acceleration, position, accelerationInterval)
if position > 1609 && !resetAcceleration {
acceleration = 0
resetAcceleration = true
}
pressure = random(40, 60)
roll = random(0, 1)
pitch = random(0, 1)
yaw = random(0, 1)
temperature = random(75, 80)
pVoltage = random(4.8, 5)
pSOC -= random(.0001, .001)
pTemp = random(75, 80)
pAmpHour = random(180, 200)
aVoltage = random(4.8, 5)
if pSOC <= 0 {
aSOC -= random(.0001, .001)
}
aTemp = random(75, 80)
aAmpHour = random(180, 200)
time.Sleep(time.Millisecond * 50)
}
}