Skip to content

set_polar() vs set_position() #16

@P3nguin-M

Description

@P3nguin-M

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions