9
9
#include < std_msgs/Float64.h>
10
10
#include < std_msgs/Int32.h>
11
11
#include < std_msgs/String.h>
12
- #include < cmath>
13
12
14
13
// Define pin configurations
15
14
#define TFT_DC 9
@@ -59,7 +58,7 @@ float batt_voltage_2_new = 0;
59
58
int thrusters_new[] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
60
59
int devices_new[] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 };
61
60
String status_new = " I am Douglas!" ;
62
- float positions_new[] = { 0 , 0 , 0 , 0 } ;
61
+ int tether_new = 0 ;
63
62
64
63
// Define global variables for display functions
65
64
// Maintains version of variables on screen
@@ -69,7 +68,8 @@ uint16_t batt_colours[] = { WHITE, WHITE };
69
68
float thrusters_old[] = { -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 };
70
69
float devices_old[] = { -1 , -1 , -1 , -1 , -1 , -1 , -1 };
71
70
String status_old = " " ;
72
- String positions_old[] = { " " , " " , " " , " " };
71
+ int tether_old = -1 ;
72
+ int dual_batt_old = -1 ;
73
73
74
74
// Status of batteries
75
75
boolean BATT1_EMPTY = false ;
@@ -148,21 +148,10 @@ void initMainScreen() {
148
148
tft.drawLine (0 , HEIGHT / 3 + 40 + 45 , WIDTH, HEIGHT / 3 + 40 + 45 , BLACK);
149
149
tft.drawLine (0 , HEIGHT - 41 , WIDTH, HEIGHT - 41 , BLACK);
150
150
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);
166
155
}
167
156
168
157
// Draws full rectangle on edges
@@ -345,63 +334,41 @@ void status(String status) {
345
334
status_old = temp_status;
346
335
}
347
336
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 } ;
351
340
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;
360
342
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];
369
345
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);
378
347
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;
386
355
}
387
356
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 ;
389
359
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] ;
392
362
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);
395
364
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 );
402
367
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;
405
372
}
406
373
}
407
374
@@ -472,32 +439,16 @@ void statusMessageCallback(const std_msgs::String& msg) {
472
439
status_new = msg.data ;
473
440
}
474
441
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 ;
493
444
}
494
445
495
446
// Define publisher message variable
496
447
std_msgs::Float64 depth_msg;
497
448
498
449
// Define publishers and subscribers
499
450
// 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
501
452
ros::Publisher DEPTH (" /sensors/depth/z" , &depth_msg);
502
453
ros::Subscriber<auv_msgs::ThrusterMicroseconds> sub (" /propulsion/microseconds" , &commandCb);
503
454
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
510
461
ros::Subscriber<std_msgs::Int32> DEVICEFC (" /sensors/front_camera/status" , &devicesFCMessageCallback);
511
462
ros::Subscriber<std_msgs::Int32> DEVICEDC (" /sensors/down_camera/status" , &devicesDCMessageCallback);
512
463
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);
517
465
518
466
// Function to calculate and publish depth
519
467
void publish_depth () {
@@ -532,7 +480,7 @@ void setup() {
532
480
533
481
// Initialize display
534
482
tft.begin ();
535
- tft.setRotation (ILI9341_ROTATION_90 );
483
+ tft.setRotation (ILI9341_ROTATION_270 );
536
484
tft.setTextColor (BLACK);
537
485
tft.setTextSize (2 );
538
486
tft.setCursor (10 , 10 );
@@ -556,10 +504,7 @@ void setup() {
556
504
nh.subscribe (DEVICEFC);
557
505
nh.subscribe (DEVICEDC);
558
506
nh.subscribe (STATUSMESSAGE);
559
- // nh.subscribe(POSITIONYAW);
560
- // nh.subscribe(POSITIONX);
561
- // nh.subscribe(POSITIONY);
562
- // nh.subscribe(POSITIONZ);
507
+ nh.subscribe (TETHER);
563
508
564
509
// Advertise ROS publisher
565
510
nh.advertise (DEPTH);
@@ -585,9 +530,8 @@ void loop() {
585
530
thrusters (Sthrusters[0 ], Sthrusters[1 ], Sthrusters[2 ], Sthrusters[3 ], Sthrusters[4 ], Sthrusters[5 ], Sthrusters[6 ], Sthrusters[7 ]);
586
531
devices (devices_new[0 ], devices_new[1 ], devices_new[2 ], devices_new[3 ], devices_new[4 ], devices_new[5 ], devices_new[6 ]);
587
532
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 );
589
534
590
535
// Delay for stability
591
536
delay (10 );
592
537
}
593
-
0 commit comments