Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_polar() vs set_position() #16

Open
P3nguin-M opened this issue Oct 9, 2020 · 0 comments
Open

set_polar() vs set_position() #16

P3nguin-M opened this issue Oct 9, 2020 · 0 comments

Comments

@P3nguin-M
Copy link

P3nguin-M commented Oct 9, 2020

Wondering why the speed on these two functions are different. set_position has much quicker capabilities. The source for set_polar() shows:
`static enum uarm_protocol_e uarm_cmd_g2201(char *payload){ // <! polar coord
uint8_t rtn = 0;
char s_str[10], r_str[10], h_str[10], f_str[10];
if( rtn = sscanf(payload, "S%[0-9-+.]R%[0-9-+.]H%[0-9-+.]F%[0-9-+.]", s_str, r_str, h_str, f_str) < 4 ){
DB_PRINT_STR( "sscanf %d\r\n", rtn );
return UARM_CMD_ERROR;
}else{
float length = 0, angle = 0, high = 0, speed = 0;
float target[3] = {0};
if( !read_float(s_str, NULL, &length) ){ return false; }
if( !read_float(r_str, NULL, &angle) ){ return false; }
if( !read_float(h_str, NULL, &high) ){ return false; }
if( !read_float(f_str, NULL, &speed) ){ return false; }

	angle = (angle - 90.0) / RAD_TO_DEG;	
	target[X_AXIS] = length * cos(angle); 
	target[Y_AXIS] = length * sin(angle);
	target[Z_AXIS] = high; 		

	return mc_line( 1, target, speed, false );
}

}

and source for set_position()
`static enum uarm_protocol_e uarm_cmd_g2204(char *payload){ // <! coord offset
uint8_t rtn = 0;
char x_str[10], y_str[10], z_str[10], f_str[10];
if( rtn = sscanf(payload, "X%[0-9-+.]Y%[0-9-+.]Z%[0-9-+.]F%[0-9-+.]", x_str, y_str, z_str, f_str ) < 4 ){
DB_PRINT_STR( "sscanf %d\r\n", rtn );
return UARM_CMD_ERROR;
}else{
float x = 0, y = 0, z = 0, speed = 0;
float target[3];
if( !read_float(x_str, NULL, &x) ){ return false; }
if( !read_float(y_str, NULL, &y) ){ return false; }
if( !read_float(z_str, NULL, &z) ){ return false; }
if( !read_float(f_str, NULL, &speed) ){ return false; }

	step_to_coord( uarm.target_step[X_AXIS], uarm.target_step[Y_AXIS], uarm.target_step[Z_AXIS], 
								 &target[X_AXIS], &target[Y_AXIS], &target[Z_AXIS] );
	coord_arm2effect( &target[X_AXIS], &target[Y_AXIS], &target[Z_AXIS] );
	target[X_AXIS] += x;
	target[Y_AXIS] += y;
	target[Z_AXIS] += z;

	return mc_line( 1 , target, speed, false );
}

}

Not the greatest at this trig, but i diffed it and found that it ends up decrementing and incrementing on the other while calling these two calculation functions:
void coord_arm2effect(float *x, float *y, float *z){
float anglec;

if( *x == 0 ){
	if(*y > 0){
		anglec = 90 / RAD_TO_DEG;
	}else{
		anglec = -90 / RAD_TO_DEG;
	}
}else if(*x < 0){
	anglec = NAN;	// <! cann't arrive
}else{
	anglec = atan(*y / *x);
}	

*x += uarm.param.front_offset * cos(anglec); 
*y += uarm.param.front_offset * sin(anglec);
*z -= uarm.param.high_offset;	

}

void coord_effect2arm(float *x, float *y, float *z){
float anglec;

if( *x == 0 ){
	if(*y > 0){
		anglec = 90 / RAD_TO_DEG;
	}else{
		anglec = -90 / RAD_TO_DEG;
	}
}else if(*x < 0){
	anglec = NAN;	// <! cann't arrive
}else{
	anglec = atan(*y / *x);
}	

*x -= uarm.param.front_offset * cos(anglec); 
*y -= uarm.param.front_offset * sin(anglec);
*z += uarm.param.high_offset;		

}

`
Any help making set_polar just as fast as set_position?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant