Ejemplo n.º 1
0
static stat_t _homing_error_exit(int8_t axis)
{
	// Generate the warning message. Since the error exit returns via the homing callback
	// - and not the main controller - it requires its own display processing
	cmd_reset_list();

	if (axis == -2) {
		cmd_add_conditional_message((const char_t *)"*** WARNING *** Homing error: Specified axis(es) cannot be homed");;
	} else {
		char message[CMD_MESSAGE_LEN];
		sprintf_P(message, PSTR("*** WARNING *** Homing error: %c axis settings misconfigured"), cm_get_axis_char(axis));
		cmd_add_conditional_message((char_t *)message);
	}
	cmd_print_list(STAT_HOMING_CYCLE_FAILED, TEXT_INLINE_VALUES, JSON_RESPONSE_FORMAT);

	// clean up and exit
	mp_flush_planner(); 						// should be stopped, but in case of switch closure
												// don't use cm_request_queue_flush() here
	cm_set_coord_system(hm.saved_coord_system);	// restore to work coordinate system
	cm_set_units_mode(hm.saved_units_mode);
	cm_set_distance_mode(hm.saved_distance_mode);
	cm_set_feed_rate(hm.saved_feed_rate);
	cm_set_motion_mode(MODEL, MOTION_MODE_CANCEL_MOTION_MODE);
	cm.cycle_state = CYCLE_OFF;
	cm_cycle_end();
	return (STAT_HOMING_CYCLE_FAILED);			// homing state remains HOMING_NOT_HOMED
}
Ejemplo n.º 2
0
static stat_t _homing_axis_start(int8_t axis)
{
	// get the first or next axis
	if ((axis = _get_next_axis(axis)) < 0) { 				// axes are done or error
		if (axis == -1) {									// -1 is done
			return (_set_homing_func(_homing_finalize_exit));
		} else if (axis == -2) { 							// -2 is error
			cm_set_units_mode(hm.saved_units_mode);
			cm_set_distance_mode(hm.saved_distance_mode);
			cm.cycle_state = CYCLE_OFF;
			cm_cycle_end();
			return (_homing_error_exit(-2));
		}
	}
	// trap gross mis-configurations
	if ((fp_ZERO(cm.a[axis].search_velocity)) || (fp_ZERO(cm.a[axis].latch_velocity))) {
		return (_homing_error_exit(axis));
	}
	if ((cm.a[axis].travel_max <= 0) || (cm.a[axis].latch_backoff <= 0)) {
		return (_homing_error_exit(axis));
	}

	// determine the switch setup and that config is OK
	hm.min_mode = get_switch_mode(MIN_SWITCH(axis));
	hm.max_mode = get_switch_mode(MAX_SWITCH(axis));

	if ( ((hm.min_mode & SW_HOMING_BIT) ^ (hm.max_mode & SW_HOMING_BIT)) == 0) {// one or the other must be homing
		return (_homing_error_exit(axis));					// axis cannot be homed
	}
	hm.axis = axis;											// persist the axis
	hm.search_velocity = fabs(cm.a[axis].search_velocity);	// search velocity is always positive
	hm.latch_velocity = fabs(cm.a[axis].latch_velocity);	// latch velocity is always positive

	// setup parameters homing to the minimum switch
	if (hm.min_mode & SW_HOMING_BIT) {
		hm.homing_switch = MIN_SWITCH(axis);				// the min is the homing switch
		hm.limit_switch = MAX_SWITCH(axis);					// the max would be the limit switch
		hm.search_travel = -cm.a[axis].travel_max;			// search travels in negative direction
		hm.latch_backoff = cm.a[axis].latch_backoff;		// latch travels in positive direction
		hm.zero_backoff = cm.a[axis].zero_backoff;

	// setup parameters for positive travel (homing to the maximum switch)
	} else {
		hm.homing_switch = MAX_SWITCH(axis);				// the max is the homing switch
		hm.limit_switch = MIN_SWITCH(axis);					// the min would be the limit switch
		hm.search_travel = cm.a[axis].travel_max;			// search travels in positive direction
		hm.latch_backoff = -cm.a[axis].latch_backoff;		// latch travels in negative direction
		hm.zero_backoff = -cm.a[axis].zero_backoff;
	}
    // if homing is disabled for the axis then skip to the next axis
	uint8_t sw_mode = get_switch_mode(hm.homing_switch);
	if ((sw_mode != SW_MODE_HOMING) && (sw_mode != SW_MODE_HOMING_LIMIT)) {
		return (_set_homing_func(_homing_axis_start));
	}
	// disable the limit switch parameter if there is no limit switch
	if (get_switch_mode(hm.limit_switch) == SW_MODE_DISABLED) { hm.limit_switch = -1;}
	hm.saved_jerk = cm.a[axis].jerk_max;					// save the max jerk value
	return (_set_homing_func(_homing_axis_clear));			// start the clear
}
Ejemplo n.º 3
0
void cm_init()
{
	memset(&cm, 0, sizeof(cm));			// reset canonicalMachineSingleton
	memset(&gn, 0, sizeof(gn));			// clear all values, pointers and status
	memset(&gf, 0, sizeof(gf));
	memset(&gm, 0, sizeof(gm));

	// set gcode defaults
	cm_set_units_mode(cfg.units_mode);
	cm_set_coord_system(cfg.coord_system);
	cm_select_plane(cfg.select_plane);
	cm_set_path_control(cfg.path_control);
	cm_set_distance_mode(cfg.distance_mode);
}
Ejemplo n.º 4
0
static stat_t _homing_finalize_exit(int8_t axis)			// third part of return to home
{
	mp_flush_planner(); 									// should be stopped, but in case of switch closure.
															// don't use cm_request_queue_flush() here

	cm_set_coord_system(hm.saved_coord_system);				// restore to work coordinate system
	cm_set_units_mode(hm.saved_units_mode);
	cm_set_distance_mode(hm.saved_distance_mode);
	cm_set_feed_rate(hm.saved_feed_rate);
	cm_set_motion_mode(MODEL, MOTION_MODE_CANCEL_MOTION_MODE);
	cm.cycle_state = CYCLE_OFF;								// required
	cm_cycle_end();
	return (STAT_OK);
}
Ejemplo n.º 5
0
static void _set_defa(nvObj_t *nv)
{

	cm_set_units_mode(MILLIMETERS);				// must do inits in MM mode
	for (nv->index=0; nv_index_is_single(nv->index); nv->index++) {
		if (GET_TABLE_BYTE(flags) & F_INITIALIZE) {
			nv->value = GET_TABLE_FLOAT(def_value);
			strncpy_P(nv->token, cfgArray[nv->index].token, TOKEN_LEN);
			nv_set(nv);
			nv_persist(nv);
		}
	}
	sr_init_status_report();					// reset status reports
	rpt_print_initializing_message();			// don't start TX until all the NVM persistence is done
}
Ejemplo n.º 6
0
static stat_t _homing_finalize_exit(int8_t axis)	// third part of return to home
{
	mp_flush_planner(); 							// should be stopped, but in case of switch closure.
													// don't use cm_request_queue_flush() here

	cm_set_coord_system(hm.saved_coord_system);		// restore to work coordinate system
	cm_set_units_mode(hm.saved_units_mode);
	cm_set_distance_mode(hm.saved_distance_mode);
	cm_set_feed_rate(hm.saved_feed_rate);
	cm_set_motion_mode(MODEL, MOTION_MODE_CANCEL_MOTION_MODE);
	cm.homing_state = HOMING_HOMED;
	cm.cycle_state = CYCLE_OFF;						// required
	cm_cycle_end();
//+++++ DIAGNOSTIC +++++
//	printf("Homed: posX: %6.3f, posY: %6.3f\n", (double)gm.position[AXIS_X], (double)gm.target[AXIS_Y]);
	return (STAT_OK);
}
Ejemplo n.º 7
0
stat_t cm_homing_cycle_start(void)
{
	// save relevant non-axis parameters from Gcode model
	hm.saved_units_mode = gm.units_mode;
	hm.saved_coord_system = gm.coord_system;
	hm.saved_distance_mode = gm.distance_mode;
	hm.saved_feed_rate = gm.feed_rate;

	// set working values
	cm_set_units_mode(MILLIMETERS);
	cm_set_distance_mode(INCREMENTAL_MODE);
	cm_set_coord_system(ABSOLUTE_COORDS);	// homing is done in machine coordinates
	hm.set_coordinates = true;

	hm.axis = -1;							// set to retrieve initial axis
	hm.func = _homing_axis_start; 			// bind initial processing function
	cm.cycle_state = CYCLE_HOMING;
	cm.homing_state = HOMING_NOT_HOMED;
	return (STAT_OK);
}
Ejemplo n.º 8
0
/************************************************************************************
 * config_init() - called once on hard reset
 *
 * Performs one of 2 actions:
 *	(1) if persistence is set up or out-of-rev load RAM and NVM with settings.h defaults
 *	(2) if persistence is set up and at current config version use NVM data for config
 *
 *	You can assume the cfg struct has been zeroed by a hard reset.
 *	Do not clear it as the version and build numbers have already been set by tg_init()
 *
 * NOTE: Config assertions are handled from the controller
 */
void config_init()
{
	nvObj_t *nv = nv_reset_nv_list();
	char *P_str_axis[3] = {"x","y", "z"};
	config_init_assertions();

#ifdef __ARM
// ++++ The following code is offered until persistence is implemented.
// ++++ Then you can use the AVR code (or something like it)
	cfg.comm_mode = JSON_MODE;					// initial value until EEPROM is read
	_set_defa(nv);
#endif
#ifdef __AVR
	cm_set_units_mode(MILLIMETERS);				// must do inits in millimeter mode
	nv->index = 0;								// this will read the first record in NVM

	read_persistent_value(nv);
	if (nv->value != cs.fw_build) {				// case (1) NVM is not setup or not in revision
//	if (fp_NE(nv->value, cs.fw_build)) {
		_set_defa(nv);
	} else {									// case (2) NVM is setup and in revision
		rpt_print_loading_configs_message();
		for (nv->index=0; nv_index_is_single(nv->index); nv->index++) {
			if (GET_TABLE_BYTE(flags) & F_INITIALIZE) {
				strncpy_P(nv->token, cfgArray[nv->index].token, TOKEN_LEN);	// read the token from the array
				read_persistent_value(nv);
				nv_set(nv);
			}
		}
		sr_init_status_report();
	}
#endif
#ifdef __RX
// ++++ The following code is offered until persistence is implemented.
// ++++ Then you can use the AVR code (or something like it)
	cm_set_units_mode(MILLIMETERS);				// must do inits in millimeter mode
	nv->index = 0;								// this will read the first record in NVM

	spiffs_DIR sf_dir;
	struct spiffs_dirent e;
	struct spiffs_dirent *pe = &e;

	spiffs_file *fd = &uspiffs[0].f;
	spiffs *fs = &uspiffs[0].gSPIFFS;

	R_FlashDataAreaAccess(0xFFFF,0xFFFF);
	checkifParFlashed = (char *)(0x00100000);
	if (SPIFFS_opendir(fs, "/", &sf_dir) == NULL)
	{

	}
	pe = SPIFFS_readdir(&sf_dir, pe);
	*fd = SPIFFS_open(fs, "config.met", SPIFFS_RDWR | SPIFFS_DIRECT, 0);
	SPIFFS_close(fs, *fd);
	if (*fd == SPIFFS_ERR_NOT_FOUND && strcmp(checkifParFlashed,checkParPhrase)) {				// case (1) NVM is not setup or not in revision
		*fd = SPIFFS_open(fs, "config.met", SPIFFS_CREAT | SPIFFS_RDWR | SPIFFS_DIRECT, 0);
		SPIFFS_close(fs, *fd);
		R_FlashEraseRange(0x00100000,0x20);
		R_FlashWrite(0x00100000,(uint32_t)checkParPhrase, 0x20);
		_set_defa(nv);
	} else {									// case (2) NVM is setup and in revision
		rpt_print_loading_configs_message();
		for (nv->index=0; nv_index_is_single(nv->index); nv->index++) {
			if (GET_TABLE_BYTE(flags) & F_INITIALIZE) {
				strncpy_P(nv->token, cfgArray[nv->index].token, TOKEN_LEN);	// read the token from the array
				read_persistent_value(nv);
				nv_set(nv);


			}
		}
		sr_init_status_report();
	}
	z_step_pulse = (M1_TRAVEL_PER_REV*M1_STEP_ANGLE)/(360*M1_MICROSTEPS);
#endif
}