Ejemplo n.º 1
0
void motor_execute_cli_command(int argc, const char* argv[])
{
	if (motor_is_running()) {
		lowsyslog("Unable to execute CLI command now\n");
		return;
	}

	chMtxLock(&_mutex);
	if (argc >= 0 && argv != NULL) {
		motor_rtctl_execute_cli_command(argc, argv);
	} else {
		assert(0);
	}
	chMtxUnlock();
}
Ejemplo n.º 2
0
static void cmd_startstop(BaseSequentialStream *chp, int argc, char *argv[])
{
	static const int TTL_MS = 5000;

	if (argc == 0) {
		motor_stop();
		puts("Usage:\n"
			"  startstop <number of cycles> [duty cycle = 0.1]");
		return;
	}

	motor_stop();

	const int num_cycles = (int)atoff(argv[0]);
	const float dc = (argc > 1) ? atoff(argv[1]) : 0.1;

	int current_cycle = 0;

	for (; current_cycle < num_cycles; current_cycle++) {
		printf("Cycle %d of %d, dc %f...\n", current_cycle + 1, num_cycles, dc);

		// Waiting for the motor to spin down
		sleep(3);
		if (!motor_is_idle()) {
			puts("NOT STOPPED");
			break;
		}

		// Starting with the specified duty cycle
		motor_set_duty_cycle(dc, TTL_MS);

		// Checking if started and stopping
		sleep(3);
		if (!motor_is_running()) {
			puts("NOT RUNNING");
			break;
		}

		motor_stop();
	}

	printf("Finished %d cycles of %d\n", current_cycle, num_cycles);
}