예제 #1
0
/**
 * Measure time between two lightbariers. Afterwards computes weight and duty cycle for shooting action
 * @param shoot - 0 if we meassure just reference weight
 * 				  1 if we want also shoot and compute weight
 */
float measure_time_weight(int8_t shoot)
{
	float weight;
	uint32_t shoot_duty = 0;

	if (check_temperatur(MAX_TEMP)) // check if temperatur is not too high
		return 0;

	TIM_Cmd(LPC_TIM0, DISABLE);
	TIM_ResetCounter(LPC_TIM0 );

	PWM_MatchUpdate(LPC_PWM1, pwm_channel, 0, PWM_MATCH_UPDATE_NOW);
	delay_ms(500);
	if (shoot)
	{
		printf("Waiting for up wall time and shooting, ");
	}
	else
	{
		printf("Waiting for up wall time ");
	}
	uint32_t duty_measure = (uint32_t) roundNo((float) period * 0.61);

	up_wall_passed = 0;
	down_wall_passed = 0;

	PWM_MatchUpdate(LPC_PWM1, pwm_channel, duty_measure, PWM_MATCH_UPDATE_NOW);
	while (up_wall_passed == 0)
		;
	unsigned long measured_tick = time_wall_up - time_wall_down;

	//shooting procedure
	if (shoot == 1)
	{
		weight = (measured_tick - reference_time) / time_one_gram; //compute weight
		shoot_duty = get_duty_shoot(weight);
		PWM_MatchUpdate(LPC_PWM1, pwm_channel, shoot_duty, PWM_MATCH_UPDATE_NOW);
		delay_ms(100);
	}

	PWM_MatchUpdate(LPC_PWM1, pwm_channel, 0, PWM_MATCH_UPDATE_NOW);

	up_wall_passed = 0;
	down_wall_passed = 0;
	LPC_SC ->EXTINT = EINT0; /* clear interrupt */
	LPC_SC ->EXTINT = EINT1; /* clear interrupt */

	printf(", tick %lu , shoot_duty: %ld ,hard c. table:%d, temp:%g \n", measured_tick, shoot_duty, hard_coded_table, compute_temperatur());

	if (!shoot)
	{
		weight = measured_tick;
		calibration_temp = compute_temperatur();
	}

	return weight;
}
예제 #2
0
/**
 * Get duty necesary for specific shootingdistance based on meassured weight
 */
uint16_t get_duty_shoot(float weight)
{
	uint16_t duty_rounded = 0;
	if (hard_coded_table)
	{
		int index = roundNo(weight) - 1;
		duty_rounded = shoot_duty_table[index];
	}
	else
	{
		float duty = 24.9792 * weight + 290.15;
		if (roundNo(weight) == 6)
		{
			duty = 420;
		}
		duty_rounded = roundNo(duty);
	}

	return duty_rounded;

}
예제 #3
0
파일: cneod.c 프로젝트: fgau/cneo
void
reply_to_get_brightness(DBusMessage* msg, DBusConnection* conn)
{
	DBusMessage* reply;
	DBusMessageIter args;
	dbus_int32_t level = 0;
//	FILE* f = fopen(NETBOOK_BRIGHTNESS_FILE, "w");
//	const char *path;

	reply = dbus_message_new_method_return(msg);

	dbus_message_iter_init_append(reply, &args);

	if (strcmp(DBUS_PATH, "/org/cneo/Netbook") == 0) {
		level = roundNo(get_sys_path_value(NETBOOK_ACT_BRIGHTNESS_FILE) * 100.0 /
			get_sys_path_value(NETBOOK_MAX_BRIGHTNESS_FILE));
	}

	else if (strcmp(DBUS_PATH, "/org/cneo/GTA02") == 0) {
		level = roundNo(get_sys_path_value(GTA02_ACT_BRIGHTNESS_FILE) * 100.0 /
			get_sys_path_value(GTA02_MAX_BRIGHTNESS_FILE));
	}

	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT32, &level)) {
		fprintf(stderr, "Out Of Memory!\n");
		return;
	}

	if (!dbus_connection_send(conn, reply, NULL)) {
		fprintf(stderr, "Out Of Memory!\n");
		return;
	}

	dbus_connection_flush(conn);
	dbus_message_unref(reply);
}