Skip to content

Commit 6065b8a

Browse files
committed
updated display board code
1 parent cfd340d commit 6065b8a

File tree

1 file changed

+39
-95
lines changed

1 file changed

+39
-95
lines changed

Display/src/main.cpp

Lines changed: 39 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <std_msgs/Float64.h>
1010
#include <std_msgs/Int32.h>
1111
#include <std_msgs/String.h>
12-
#include <cmath>
1312

1413
// Define pin configurations
1514
#define TFT_DC 9
@@ -59,7 +58,7 @@ float batt_voltage_2_new = 0;
5958
int thrusters_new[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
6059
int devices_new[] = { 0, 0, 0, 0, 0, 0, 0 };
6160
String status_new = "I am Douglas!";
62-
float positions_new[] = { 0, 0, 0, 0 };
61+
int tether_new = 0;
6362

6463
// Define global variables for display functions
6564
// Maintains version of variables on screen
@@ -69,7 +68,8 @@ uint16_t batt_colours[] = { WHITE, WHITE };
6968
float thrusters_old[] = { -1, -1, -1, -1, -1, -1, -1, -1 };
7069
float devices_old[] = { -1, -1, -1, -1, -1, -1, -1 };
7170
String status_old = "";
72-
String positions_old[] = { "", "", "", "" };
71+
int tether_old = -1;
72+
int dual_batt_old = -1;
7373

7474
// Status of batteries
7575
boolean BATT1_EMPTY = false;
@@ -148,21 +148,10 @@ void initMainScreen() {
148148
tft.drawLine(0, HEIGHT / 3 + 40 + 45, WIDTH, HEIGHT / 3 + 40 + 45, BLACK);
149149
tft.drawLine(0, HEIGHT - 41, WIDTH, HEIGHT - 41, BLACK);
150150

151-
// Positions section
152-
for (int i = 0; i < 4; i++) {
153-
int x = i * WIDTH / 4;
154-
tft.drawRect(x, HEIGHT - 40, WIDTH / 4, 40, BLACK);
155-
tft.setCursor(x + 2, HEIGHT - 38);
156-
tft.setTextSize(1);
157-
if (i == 0) {
158-
tft.print("YAW");
159-
} else if (i == 1) {
160-
tft.print("X");
161-
} else if (i == 2) {
162-
tft.print("Y");
163-
} else if (i == 3) {
164-
tft.print("Z");
165-
}
151+
// Tether and dual battery section
152+
for (int i = 0; i < 2; i++) {
153+
int x = i * WIDTH / 2;
154+
tft.drawRect(x, HEIGHT - 40, WIDTH / 2, 40, BLACK);
166155
}
167156

168157
// Draws full rectangle on edges
@@ -345,63 +334,41 @@ void status(String status) {
345334
status_old = temp_status;
346335
}
347336

348-
// Function to update positions display
349-
void positions(float YAW, float X, float Y, float Z) {
350-
char bufferYAW[5], bufferX[5], bufferY[5], bufferZ[5];
337+
// Function to update tether and dual battery status
338+
void tether_dual_battery(float tether_status, float batt1_V, float batt2_V) {
339+
uint16_t custom_colors[] = { RED, GREEN };
351340

352-
if (YAW == 1.0) {
353-
strcpy(bufferYAW, "1.0");
354-
} else {
355-
dtostrf(YAW, 3, 2, bufferYAW);
356-
if (bufferYAW[0] == '0') {
357-
memmove(bufferYAW, bufferYAW + 1, strlen(bufferYAW));
358-
}
359-
}
341+
int temp_tether_status = tether_status;
360342

361-
if (X == 1.0) {
362-
strcpy(bufferX, "1.0");
363-
} else {
364-
dtostrf(X, 3, 2, bufferX);
365-
if (bufferX[0] == '0') {
366-
memmove(bufferX, bufferX + 1, strlen(bufferX));
367-
}
368-
}
343+
if (temp_tether_status != tether_old) {
344+
uint16_t tether_color = custom_colors[temp_tether_status];
369345

370-
if (Y == 1.0) {
371-
strcpy(bufferY, "1.0");
372-
} else {
373-
dtostrf(Y, 3, 2, bufferY);
374-
if (bufferY[0] == '0') {
375-
memmove(bufferY, bufferY + 1, strlen(bufferY));
376-
}
377-
}
346+
tft.fillRect(1, HEIGHT - 40 + 1, WIDTH / 2 - 2, 40 - 2, tether_color);
378347

379-
if (Z == 1.0) {
380-
strcpy(bufferZ, "1.0");
381-
} else {
382-
dtostrf(Z, 3, 2, bufferZ);
383-
if (bufferZ[0] == '0') {
384-
memmove(bufferZ, bufferZ + 1, strlen(bufferZ));
385-
}
348+
tft.setTextColor(WHITE);
349+
tft.setTextSize(3);
350+
351+
tft.setCursor(26, HEIGHT - 30);
352+
tft.println("TETHER");
353+
354+
tether_old = temp_tether_status;
386355
}
387356

388-
String temp_positions[] = { bufferYAW, bufferX, bufferY, bufferZ };
357+
float battery_difference = batt2_V - batt1_V;
358+
bool temp_battery_status = battery_difference > 0.52 && battery_difference < 0.63;
389359

390-
for (int i = 0; i < 4; i++) {
391-
int x = i * WIDTH / 4;
360+
if (temp_battery_status != dual_batt_old) {
361+
uint16_t dual_batt_color = custom_colors[temp_battery_status];
392362

393-
if (temp_positions[i] != positions_old[i]) {
394-
tft.fillRect(x + 1 + 8, HEIGHT - 40 + 1 + 6, WIDTH / 4 - 2 - 8, 38 - 6, WHITE);
363+
tft.fillRect(1 + WIDTH / 2, HEIGHT - 40 + 1, WIDTH / 2 - 2, 40 - 2, dual_batt_color);
395364

396-
tft.setCursor(x + 5, HEIGHT - 33);
397-
tft.setTextColor(BLACK);
398-
tft.setTextSize(4);
399-
tft.println(temp_positions[i]);
400-
}
401-
}
365+
tft.setTextColor(WHITE);
366+
tft.setTextSize(3);
402367

403-
for (int i = 0; i < 4; i++) {
404-
positions_old[i] = temp_positions[i];
368+
tft.setCursor(8 + WIDTH / 2, HEIGHT - 30);
369+
tft.println("DUAL BAT");
370+
371+
dual_batt_old = temp_battery_status;
405372
}
406373
}
407374

@@ -472,32 +439,16 @@ void statusMessageCallback(const std_msgs::String& msg) {
472439
status_new = msg.data;
473440
}
474441

475-
// Callback function for position W message
476-
void positionYAWMessageCallback(const std_msgs::Float32& msg) {
477-
positions_new[0] = msg.data;
478-
}
479-
480-
// Callback function for position X message
481-
void positionXMessageCallback(const std_msgs::Float32& msg) {
482-
positions_new[1] = msg.data;
483-
}
484-
485-
// Callback function for position Y message
486-
void positionYMessageCallback(const std_msgs::Float32& msg) {
487-
positions_new[2] = msg.data;
488-
}
489-
490-
// Callback function for position Z message
491-
void positionZMessageCallback(const std_msgs::Float32& msg) {
492-
positions_new[3] = msg.data;
442+
void tetherStatusMessageCallback(const std_msgs::Int32& msg) {
443+
tether_new = msg.data;
493444
}
494445

495446
// Define publisher message variable
496447
std_msgs::Float64 depth_msg;
497448

498449
// Define publishers and subscribers
499450
// Publishes depth
500-
// Subscribes to battery voltages, thruster microseconds, device statuses, status message, and positions
451+
// Subscribes to battery voltages, thruster microseconds, device statuses, status message, and tether status
501452
ros::Publisher DEPTH("/sensors/depth/z", &depth_msg);
502453
ros::Subscriber<auv_msgs::ThrusterMicroseconds> sub("/propulsion/microseconds", &commandCb);
503454
ros::Subscriber<std_msgs::Float32> BATT1("/display/batteries/voltage/1", &batt1MessageCallback);
@@ -510,10 +461,7 @@ ros::Subscriber<std_msgs::Int32> DEVICEACT("/sensors/actuator/status", &devicesA
510461
ros::Subscriber<std_msgs::Int32> DEVICEFC("/sensors/front_camera/status", &devicesFCMessageCallback);
511462
ros::Subscriber<std_msgs::Int32> DEVICEDC("/sensors/down_camera/status", &devicesDCMessageCallback);
512463
ros::Subscriber<std_msgs::String> STATUSMESSAGE("/mission_display", &statusMessageCallback);
513-
ros::Subscriber<std_msgs::Float32> POSITIONYAW("/state/theta/z", &positionYAWMessageCallback);
514-
ros::Subscriber<std_msgs::Float32> POSITIONX("/state/x", &positionXMessageCallback);
515-
ros::Subscriber<std_msgs::Float32> POSITIONY("/state/y", &positionYMessageCallback);
516-
ros::Subscriber<std_msgs::Float32> POSITIONZ("/state/z", &positionZMessageCallback);
464+
ros::Subscriber<std_msgs::Int32> TETHER("/tether/status", &tetherStatusMessageCallback);
517465

518466
// Function to calculate and publish depth
519467
void publish_depth() {
@@ -532,7 +480,7 @@ void setup() {
532480

533481
// Initialize display
534482
tft.begin();
535-
tft.setRotation(ILI9341_ROTATION_90);
483+
tft.setRotation(ILI9341_ROTATION_270);
536484
tft.setTextColor(BLACK);
537485
tft.setTextSize(2);
538486
tft.setCursor(10, 10);
@@ -556,10 +504,7 @@ void setup() {
556504
nh.subscribe(DEVICEFC);
557505
nh.subscribe(DEVICEDC);
558506
nh.subscribe(STATUSMESSAGE);
559-
//nh.subscribe(POSITIONYAW);
560-
//nh.subscribe(POSITIONX);
561-
//nh.subscribe(POSITIONY);
562-
//nh.subscribe(POSITIONZ);
507+
nh.subscribe(TETHER);
563508

564509
// Advertise ROS publisher
565510
nh.advertise(DEPTH);
@@ -585,9 +530,8 @@ void loop() {
585530
thrusters(Sthrusters[0], Sthrusters[1], Sthrusters[2], Sthrusters[3], Sthrusters[4], Sthrusters[5], Sthrusters[6], Sthrusters[7]);
586531
devices(devices_new[0], devices_new[1], devices_new[2], devices_new[3], devices_new[4], devices_new[5], devices_new[6]);
587532
status(status_new);
588-
//positions(positions_new[0], positions_new[1], positions_new[2], positions_new[3]);
533+
tether_dual_battery(tether_new, batt_voltage_1_new, batt_voltage_2_new);
589534

590535
// Delay for stability
591536
delay(10);
592537
}
593-

0 commit comments

Comments
 (0)