@@ -37,70 +37,69 @@ int main(void) {
37
37
position_finder = Position_finder_create ();
38
38
uart_commands_manager = UART_commands_manager_create ();
39
39
40
- CyGlobalIntEnable ; /* Enable global interrupts. */
41
- /*
42
- USB_Serial_Start(0, USB_Serial_5V_OPERATION);
43
- while(!USB_Serial_GetConfiguration());
44
- USB_Serial_CDC_Init();
45
-
46
- USB_Serial_PutString("START\n");
47
- while(USB_Serial_CDCIsReady() == 0u);
48
- CyDelay(1);
49
-
50
- CyDelay(3000);
51
-
52
- USB_Serial_PutString("INIT\n");
53
- while(USB_Serial_CDCIsReady() == 0u);
54
- CyDelay(1);*/
55
-
56
- // Beacon position
57
- Position3D beacon_position ;
58
- beacon_position .x = BEACON_COORD_X ;
59
- beacon_position .y = BEACON_COORD_Y ;
60
- beacon_position .z = BEACON_COORD_Z ;
61
-
62
- beacon_position .alpha = BEACON_COORD_ALPHA ;
63
- beacon_position .beta = BEACON_COORD_BETA ;
64
- beacon_position .gamma = BEACON_COORD_GAMMA ;
40
+ CyGlobalIntEnable ;
65
41
66
42
// Initialization
67
- Position_finder_init (position_finder , & beacon_position , LED_COORD_HEIGHT , tracker_led_offset );
68
- VIVE_sensors_init (vive_sensors );
69
43
UART_commands_manager_init (uart_commands_manager );
44
+ UART_commands_manager_register_command (uart_commands_manager , "SBPOS" , callback_set_beacon_position );
45
+ UART_commands_manager_register_command (uart_commands_manager , "AYR" , callback_are_you_ready );
46
+ UART_commands_manager_register_command (uart_commands_manager , "GPOS" , callback_send_position );
47
+
48
+ VIVE_sensors_init (vive_sensors );
49
+ while (beacon_position_initialized == false) // Wait until beacon position is initialized
50
+ UART_commands_manager_check_commands (uart_commands_manager );
51
+
52
+ Position_finder_init (position_finder , & beacon_position , LED_COORD_HEIGHT , tracker_led_offset );
70
53
71
- UART_commands_manager_register_command ( uart_commands_manager , "GETPOS" , callback_get_position ) ;
54
+ configured = true ;
72
55
73
56
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
74
- /*
75
- USB_Serial_PutString("READY\n");
76
- while(USB_Serial_CDCIsReady() == 0u);*/
77
57
78
58
for (;;) {
79
59
UART_commands_manager_check_commands (uart_commands_manager );
80
60
81
- if (VIVE_pulses_decoded ) {
82
- VIVE_pulses_decoded = 0 ;
83
- vive_sensors_data = VIVE_sensors_process_pulses (vive_sensors );
84
- Position_finder_find_position (position_finder , vive_sensors_data );
85
-
86
- /*
87
- char buffer[512];
88
- sprintf(buffer, "HEADING %f\n", position_finder->current_position.a);
89
- USB_Serial_PutString(buffer);
90
- while(USB_Serial_CDCIsReady() == 0u);*/
61
+ if (configured ) {
62
+ if (VIVE_pulses_decoded ) {
63
+ VIVE_pulses_decoded = 0 ;
64
+ vive_sensors_data = VIVE_sensors_process_pulses (vive_sensors );
65
+ Position_finder_find_position (position_finder , vive_sensors_data );
66
+ }
91
67
}
92
68
}
93
69
}
94
70
95
- void callback_get_position () {
71
+ void callback_set_beacon_position () {
72
+ // Beacon position
73
+ beacon_position .x = atof (UART_commands_manager_get_next_token (uart_commands_manager ));
74
+ beacon_position .y = atof (UART_commands_manager_get_next_token (uart_commands_manager ));
75
+ beacon_position .z = atof (UART_commands_manager_get_next_token (uart_commands_manager ));
76
+
77
+ beacon_position .alpha = atof (UART_commands_manager_get_next_token (uart_commands_manager ));
78
+ beacon_position .beta = atof (UART_commands_manager_get_next_token (uart_commands_manager ));
79
+ beacon_position .gamma = atof (UART_commands_manager_get_next_token (uart_commands_manager ));
80
+
81
+ beacon_position_initialized = true;
82
+ }
83
+
84
+ // callback functions
85
+ void callback_are_you_ready () {
86
+ if (configured )
87
+ UART_commands_manager_send_command (uart_commands_manager , "READY" , "" );
88
+ }
89
+
90
+ void callback_send_position () {
96
91
// Send back the current position
92
+ bool is_valid = false;
97
93
char buffer [192 ];
98
94
Position2D * position = position_finder -> current_position ;
95
+
99
96
float x = (float ) position -> x ;
100
97
float y = (float ) position -> y ;
101
98
float a = (float ) position -> a ;
102
- sprintf (buffer , "%.6f %.6f %.6f" , x , y , a );
103
- UART_commands_manager_send_command (uart_commands_manager , "POS" , buffer );
99
+
100
+ sprintf (buffer , "%d %.6f %.6f %.6f" , is_valid , x , y , a );
101
+
102
+ if (configured == true) // If not configured, don't send the position
103
+ UART_commands_manager_send_command (uart_commands_manager , "POS" , buffer );
104
104
}
105
-
106
105
/* [] END OF FILE */
0 commit comments