I have a car that needs to stop at a place whenever I press a key on keyboard. So if I press 1, it should stop at coordinate X = 140 and coordinate Y = 50. On this code, the speed goes up and down with UP and DOWN arrow. I may to insert if statement under case 1. I need your help.
/
/ GPS
WbDeviceTag gps;
double gps_coords[3] = {0.0, 0.0, 0.0};
double gps_speed = 0.0;
// misc variables
double speed = 0.0;
double steering_angle = 0.0;
int manual_steering = 0;
bool autodrive = true;
void print_help() {
printf("You can drive this car!\n");
printf("Select the 3D window and then use the cursor keys to:\n");
printf("[LEFT]/[RIGHT] - steer\n");
printf("[UP]/[DOWN] - accelerate/slow down\n");
}
void set_autodrive(bool onoff) {
if (autodrive == onoff)
return;
autodrive = onoff;
switch (autodrive) {
case false:
printf("switching to manual drive...\n");
printf("hit [A] to return to auto-drive.\n");
break;
case true:
if (has_camera)
printf("switching to auto-drive...\n");
else
printf("impossible to switch auto-drive on without camera...\n");
break;
}
}
void check_keyboard() {
int key = wb_keyboard_get_key();
switch (key) {
case WB_KEYBOARD_UP:
set_speed(speed + 5.0);
break;
case WB_KEYBOARD_DOWN:
set_speed(speed - 5.0);
break;
case WB_KEYBOARD_RIGHT:
change_manual_steer_angle(+1);
break;
case WB_KEYBOARD_LEFT:
change_manual_steer_angle(-1);
break;
case 'A':
set_autodrive(true);
break;
case '1':
[b]if (gps_coords[X] == "104.9" && gps_coords[Z] == "48.9") {
set_speed(speed - speed);[/b]
}
break;
}