void handle_cmd(void) { S8 speed[MSG_SIZE]; //reception du message nx_bt_stream_read((U8 *)speed, MSG_SIZE); while (!quit && nx_bt_stream_data_read() < 1) { detect_obstacle(); vForwardUntilWall(&pos1Global,&pos2Global); vForwardUntilWhite(&pos1Global,&pos2Global); nx_systick_wait_ms(10); nx_display_cursor_set_pos(0, 5); nx_display_string("boucle"); } if (speed[0] > 100 || speed[0] < -100 || speed[1] > 100 || speed[1] < -100) speed[0] = speed[1] = 0; nx_motors_rotate_time(LEFT_MOTOR, speed[0], MOVE_TIME, FALSE); nx_motors_rotate_time(RIGHT_MOTOR, speed[1], MOVE_TIME, FALSE); return; }
void tests_tachy(void) { int i; hello(); nx_motors_rotate_angle(0, 80, 1024, TRUE); nx_motors_rotate_time(1, -80, 3000, FALSE); nx_motors_rotate(2, 80); for (i=0; i<30; i++) { nx_display_clear(); nx_display_cursor_set_pos(0,0); nx_display_clear(); nx_display_cursor_set_pos(0,0); nx_display_string("Tachymeter test\n" "----------------\n"); nx_display_string("Tach A: "); nx_display_hex(nx_motors_get_tach_count(0)); nx_display_end_line(); nx_display_string("Tach B: "); nx_display_hex(nx_motors_get_tach_count(1)); nx_display_end_line(); nx_display_string("Tach C: "); nx_display_hex(nx_motors_get_tach_count(2)); nx_display_end_line(); nx_display_string("Refresh: "); nx_display_uint(i); nx_display_end_line(); nx_systick_wait_ms(250); } nx_motors_stop(2, TRUE); goodbye(); }
void main() { /* On bootup, all the motors are stopped. Let's start one in * continuous mode. In this mode, the motor will continue at the * given speed until explicitely told to stop or do something else. */ nx_motors_rotate(0, 100); wait(); /* Speed control goes from -100 (full reverse) to 100 (full * forward). Let's reverse the motor's direction. */ nx_motors_rotate(0, -100); wait(); /* Now, stop the motor. There are two options here. Either don't * apply brakes, which lets the motor continue for a short while on * its inertia, or apply braking, which forcefully tries to bring * the motor to a halt as fast as possible. The following will * demonstrate both stop modes. First, a braking stop. */ nx_motors_stop(0, TRUE); wait(); nx_motors_rotate(0, 100); wait(); /* And here, a coasting stop. */ nx_motors_stop(0, FALSE); wait(); /* You can also request rotation by a given angle, instead of just * blazing the motor on without limits. Note that there is no * precise feedback control built into the motor driver (yet), which * can cause it to overshoot the target angle because of its own * inertia. Let's rotate 90 degrees, with a braking finish. */ nx_motors_rotate_angle(0, 100, 90, TRUE); wait(); /* Finally, rotation can be set to stop after a given time. The * function call returns immediately, and the motor driver will take * care of stopping the motor after the specified time has * elapsed. Let's rotate in reverse, for 1 second, with a braking * finish. */ nx_motors_rotate_time(0, -100, 1000, TRUE); wait(); /* Finally, if this information has any value to you, you can query * the motor's current rotational position relative to its position * when it booted up. What you actually get here is the raw value of * the motor's tachymeter, which you should modulo 360 to get a more * sensible angular value. */ nx_display_uint(nx_motors_get_tach_count(0)); wait(); }