Skip to content

Commit 36840d8

Browse files
committed
Pod5 Cleanup
1 parent 3243756 commit 36840d8

File tree

12 files changed

+157
-30
lines changed

12 files changed

+157
-30
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ matrix:
1313
language: c
1414
compiler: gcc-6
1515
sudo: require
16+
dist: trusty
1617
python:
1718
- "3.4"
1819

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Badgerloop Pod IV
2-
[![Build Status](https://travis-ci.org/badgerloop-software/pod.svg?branch=master)](https://travis-ci.org/badgerloop-software/pod)
1+
# Badgerloop Pod V
2+
[![Build Status](https://travis-ci.org/badgerloop-software/pod-embedded.svg?branch=master)](https://travis-ci.org/badgerloop-software/pod-embedded)
33

4-
*Developers: Ezra Boley, Eric Udlis, Rohan Daruwala, Luke Houge, Alex Vesel*
4+
*Developers: Rohan Daruwala, Ezra Boley*
55

6-
The master repository for Badgerloop's pod in the Hyperloop Competition
6+
The embedded repository for Badgerloop's pod in the Hyperloop Competition
77

88
## Beaglebone Make Instructions
99

badgerloop_HV.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Includes
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <unistd.h>
5+
#include <signal.h>
6+
#include "HVTelemetry_Loop.h"
7+
#include "HVTCPSocket.h"
8+
#include "HV_Telem_Recv.h"
9+
#include "data_dump.h"
10+
11+
12+
extern "C"
13+
{
14+
#include "bbgpio.h"
15+
#include "connStat.h"
16+
#include <signal.h>
17+
#include <rms.h>
18+
#include "motor.h"
19+
#include "hv_iox.h"
20+
#include "motor.h"
21+
#include "proc_iox.h"
22+
#include "data.h"
23+
#include "can_devices.h"
24+
#include "state_machine.h"
25+
#include "NCD9830DBR2G.h"
26+
}
27+
void emergQuitter(int sig, siginfo_t* inf, void *nul) {
28+
printf("shutdown\n");
29+
setMCUHVEnabled(false);
30+
rmsCmdNoTorque();
31+
sleep(1);
32+
rmsDischarge();
33+
sleep(1);
34+
rmsInvDis();
35+
exit(0);
36+
}
37+
38+
int init() {
39+
/* Init Data struct */
40+
initData();
41+
42+
/* Init all drivers */
43+
SetupCANDevices();
44+
initProcIox(true);
45+
initHVIox(true);
46+
47+
SetupMotor();
48+
/* initMotor(); */
49+
/* initPressureSensors();*/
50+
/* Allocate needed memory for state machine and create graph */
51+
buildStateMachine();
52+
printf("Ezra\n");
53+
/* Init telemetry */
54+
SetupHVTelemetry((char *) DASHBOARD_IP, DASHBOARD_PORT);
55+
SetupHVTCPServer();
56+
SetupHVTelemRecv();
57+
58+
struct sigaction sig;
59+
sig.sa_sigaction = emergQuitter;
60+
sigaction(SIGINT, &sig, NULL);
61+
/* Start 'black box' data saving */
62+
/* SetupDataDump();*/
63+
64+
return 0;
65+
}
66+
67+
int main() {
68+
/* Create the big data structures to house pod data */
69+
int i = 0;
70+
char buffer[100];
71+
72+
if (init() == 1) {
73+
fprintf(stderr, "Error in initialization! Exiting...\r\n");
74+
exit(1);
75+
}
76+
77+
while(1) {
78+
runStateMachine();
79+
80+
/* printf("CONN STAT: TCP - %d | UDP - %d\n", */
81+
/* checkTCPStat(),*/
82+
/* checkUDPStat());*/
83+
if (data->flags->shouldBrake) {
84+
printf("signalling\n");
85+
signalLV((char *)"brake");
86+
data->flags->shouldBrake = false;
87+
printf("signallingDone\n");
88+
}
89+
if (data->flags->brakeInit) {
90+
printf("Cancelling brake\n");
91+
signalLV((char *)"primBrakeOff");
92+
usleep(1000);
93+
signalLV((char *)"secBrakeOff");
94+
data->flags->brakeInit = false;
95+
}
96+
if (data->flags->clrMotionData) {
97+
printf("signal clear\n");
98+
signalLV((char *) "clrMotion");
99+
data->flags->clrMotionData = false;
100+
}
101+
102+
if (i >= 50) {
103+
sprintf(buffer, "state%d\n", data->state == 1);
104+
signalLV((char *) buffer);
105+
i = 0;
106+
} else {
107+
i += 1;
108+
}
109+
usleep(10000);
110+
111+
// Control loop
112+
}
113+
return 0;
114+
}

deploy.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
sudo modprobe vcan
44
./embedded/utils/setupCAN.sh
55
make examples VIRTUAL=1
6+
retVal=$?
7+
if [ $retVal -ne 0 ]; then
8+
exit 1
9+
fi
610
make VIRTUAL=1
11+
retVal=$?
12+
if [ $retVal -ne 0 ]; then
13+
exit 1
14+
fi
715
python3 ./embedded/examples/sims/rms.py &
816
./out/tests/can_test
917
exit 0

embedded/app/src/bms_fault_checking.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ bool checkPrerunBattery(void){
2828
return false;
2929
}
3030
if(data->bms->cellMaxVoltage > MAX_CELL_VOLTAGE || data->bms->cellMinVoltage < MIN_CELL_VOLTAGE){
31-
printf("Cell Voltage Error: %i, %i\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
31+
printf("Cell Voltage Error: %f, %f\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
3232
return false;
3333
}
3434
if(data->bms->packVoltage > MAX_PACK_VOLTAGE || data->bms->packVoltage < MIN_PACK_VOLTAGE_PRERUN){
@@ -53,7 +53,7 @@ bool checkRunBattery(void){
5353
return false;
5454
}
5555
if(data->bms->cellMaxVoltage > MAX_CELL_VOLTAGE || data->bms->cellMinVoltage < MIN_CELL_VOLTAGE){
56-
printf("Cell Voltage Error: %i, %i\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
56+
printf("Cell Voltage Error: %f, %f\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
5757
return false;
5858
}
5959
if(data->bms->packVoltage > MAX_PACK_VOLTAGE || data->bms->packVoltage < MIN_PACK_VOLTAGE_RUN){
@@ -78,7 +78,7 @@ bool checkBrakingBattery(void){
7878
return false;
7979
}
8080
if(data->bms->cellMaxVoltage > MAX_CELL_VOLTAGE || data->bms->cellMinVoltage < MIN_CELL_VOLTAGE){
81-
printf("Cell Voltage Error: %i, %i\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
81+
printf("Cell Voltage Error: %f, %f\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
8282
return false;
8383
}
8484
if(data->bms->packVoltage > MAX_PACK_VOLTAGE || data->bms->packVoltage < MIN_PACK_VOLTAGE_RUN){
@@ -103,7 +103,7 @@ bool checkStoppedBattery(void){
103103
return false;
104104
}
105105
if(data->bms->cellMaxVoltage > MAX_CELL_VOLTAGE || data->bms->cellMinVoltage < MIN_CELL_VOLTAGE){
106-
printf("Cell Voltage Error: %i, %i\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
106+
printf("Cell Voltage Error: %f, %f\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
107107
return false;
108108
}
109109
if(data->bms->packVoltage > MAX_PACK_VOLTAGE || data->bms->packVoltage < MIN_PACK_VOLTAGE_RUN){
@@ -128,7 +128,7 @@ bool checkCrawlBattery(void){
128128
return false;
129129
}
130130
if(data->bms->cellMaxVoltage > MAX_CELL_VOLTAGE || data->bms->cellMinVoltage < MIN_CELL_VOLTAGE){
131-
printf("Cell Voltage Error: %i, %i\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
131+
printf("Cell Voltage Error: %f, %f\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
132132
return false;
133133
}
134134
if(data->bms->packVoltage > MAX_PACK_VOLTAGE || data->bms->packVoltage < MIN_PACK_VOLTAGE_POSTRUN){
@@ -153,7 +153,7 @@ bool checkPostrunBattery(void){
153153
return false;
154154
}
155155
if(data->bms->cellMaxVoltage > MAX_CELL_VOLTAGE || data->bms->cellMinVoltage < MIN_CELL_VOLTAGE){
156-
printf("Cell Voltage Error: %i, %i\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
156+
printf("Cell Voltage Error: %f, %f\n", data->bms->cellMinVoltage, data->bms->cellMaxVoltage);
157157
return false;
158158
}
159159
if(data->bms->packVoltage > MAX_PACK_VOLTAGE || data->bms->packVoltage < MIN_PACK_VOLTAGE_POSTRUN){

embedded/app/src/motor.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,8 @@
1616

1717

1818
/* Thread management variables */
19-
static pthread_mutex_t torqueLock, motorLock;
20-
static sem_t hbSem;
21-
static pthread_t hbLoop;
22-
static bool JOIN_HB_THREAD = false;
23-
24-
static void *motorHeartbeatLoop(void *);
2519
extern int rmsInvEnNoTorque();
20+
2621
/* Create the semaphores and mutexes for thread sensitive operations
2722
* and creates the HB loop that just waits for the motor to be started
2823
*/
@@ -31,7 +26,7 @@ extern int rmsInvEnNoTorque();
3126
static pthread_t hbThread;
3227
static bool motorEnabled = false;
3328
static bool lowTorqueMode = false;
34-
static void motorHbLoop();
29+
static void *motorHbLoop(void *arg);
3530

3631
void setMotorEn() {
3732
motorEnabled = true;
@@ -53,7 +48,8 @@ void SetupMotor() {
5348
pthread_create(&hbThread, NULL, (motorHbLoop), NULL);
5449
}
5550

56-
static void motorHbLoop() {
51+
static void *motorHbLoop(void *arg) {
52+
(void) arg;
5753
while(1) {
5854
if (motorEnabled)
5955
rmsSendHbMsg(2);
@@ -63,5 +59,7 @@ static void motorHbLoop() {
6359
rmsIdleHb();
6460
usleep(10000);
6561
}
62+
63+
return NULL;
6664
}
6765

embedded/app/src/nav.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ void resetNav() {
146146
* 2. Are we going in X or Y plane
147147
*/
148148
void navLoop(void *unused) {
149+
(void) unused;
150+
149151
int lastRetroCount = 0;
150152
data->motion->missedRetro = 0;
151153
csvFormatHeader();

embedded/peripherals/src/imu.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ void *IMULoop(void *arg){
6969
unsigned char res1[4];
7070
uint32_t tempx, tempy, tempz;
7171
int i;
72-
uint64_t curr, prev, delt;
73-
prev = getuSTimestamp();
72+
//uint64_t curr, prev;
73+
// uint64_t delt;
74+
//prev = getuSTimestamp();
7475
while (1){
7576
i = 0;
7677
// Information on data registers can be found @ https://www.xsens.com/download/pdf/documentation/mti-1/mti-1-series_datasheet.pdf
@@ -86,7 +87,7 @@ void *IMULoop(void *arg){
8687
unsigned char dataBuffer[messageSize];
8788
read_i2c(i2c, dataBuffer, messageSize);
8889
i = 0;
89-
curr = getuSTimestamp();
90+
//curr = getuSTimestamp();
9091
while(i < messageSize){
9192
//Check delta velocity
9293

@@ -120,7 +121,7 @@ void *IMULoop(void *arg){
120121
data->accelY = * ((float *) &tempy);
121122
data->accelZ = * ((float *) &tempz);
122123

123-
delt = curr - prev;
124+
//delt = curr - prev;
124125

125126
data->velX = data->velX + (data->accelX * .025);
126127
data->velY = data->velY + (data->accelY * .025);
@@ -142,7 +143,7 @@ void *IMULoop(void *arg){
142143
data->posY += data->velY * .025;
143144
data->posZ += data->velZ * .025;
144145
sem_post(&data->mutex);
145-
prev = curr;
146+
//prev = curr;
146147
usleep(10000);
147148

148149
}

embedded/peripherals/src/retro.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static bool blockInts = true;
3535
static int onTapeStrip (int retroNum);
3636
static void * waitForStrip (void * retroNum);
3737
static int getPin(int retroNum);
38-
static void * blockSpuriousInts(uint64_t timeout);
38+
static void * blockSpuriousInts(int timeout);
3939

4040

4141
/***
@@ -50,7 +50,7 @@ int initRetros() {
5050
if (bbGpioExport(getPin(i)) != 0) return -1;
5151
if (bbGpioSetDir(getPin(i), IN_DIR) != 0) return -1;
5252
if (bbGpioSetEdge(getPin(i), RISING_EDGE) != 0) return -1;
53-
if (pthread_create(&retroThreads[i], NULL, waitForStrip, (void *) i) != 0)
53+
if (pthread_create(&retroThreads[i], NULL, waitForStrip, (void *)(intptr_t) i) != 0)
5454
return -1;
5555
}
5656

@@ -139,7 +139,7 @@ static int onTapeStrip(int retroNum) {
139139
* void *num - an identifier for which retro is running the thread
140140
***/
141141
static void *waitForStrip(void *num) {
142-
int retroNum = (int) num;
142+
int retroNum = (intptr_t) num;
143143
int gpioFd = bbGpioFdOpen(getPin(retroNum));
144144
struct pollfd fds[1];
145145
int nfds = 1;
@@ -192,7 +192,7 @@ static int getPin(int retroNum) {
192192
return -1; /* Will never get here */
193193
}
194194

195-
static void *blockSpuriousInts(uint64_t timeout) {
195+
static void *blockSpuriousInts(int timeout) {
196196
blockInts = true;
197197
usleep(timeout);
198198
blockInts = false;

embedded/peripherals/src/rms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ int rms_parser(uint32_t id, uint8_t *rmsData, uint32_t filter){
168168
return 1;
169169
}
170170
uint16_t val;
171-
uint16_t val2;
171+
//uint16_t val2;
172172
int16_t temp;
173173
switch(id){
174174
case (0xa0):

0 commit comments

Comments
 (0)