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

Create distance & angle counters overwritten #190

Open
Jammo2000 opened this issue Jul 14, 2023 · 0 comments
Open

Create distance & angle counters overwritten #190

Jammo2000 opened this issue Jul 14, 2023 · 0 comments

Comments

@Jammo2000
Copy link

Jammo2000 commented Jul 14, 2023

The set_create_distance and set_create_total_angle functions occasionally set the angle counters to extreme values.
When I run the code below, the create will turn back and forth for a while, but eventually it will either miss a rotation going counterclockwise or rotate clockwise forever. In both cases, the displayed value for get_create_total_angle will be around 18000. I'm not sure if it is the same value every time, but it's always in the same ballpark.

The issue is fairly rare, it usually takes a couple minutes of turning before I see it with the code below, but that is often enough to occur in about 1/4 of my runs.

A similar issue exists for set_create_distance, but I haven't looked into that one as much. The value the bug sets create_distance to is about 6000.

void create_turn_in_place(int degrees, int speed){
    int cached_angle;
    speed = abs(speed);
    set_create_total_angle(0);
    if(degrees>0){
        create_spin_CCW(speed);
        cached_angle = get_create_total_angle();
        while(cached_angle<degrees){
            cached_angle = get_create_total_angle();
            display_printf(0, 0, "%d    ", cached_angle);
            msleep(10);
        }
    }
    else{
        create_spin_CW(speed);
        cached_angle = get_create_total_angle();
        while(cached_angle>degrees){
            display_printf(0, 0, "%d     ", cached_angle);
            msleep(10);
            cached_angle = get_create_total_angle();
        }
    }
    create_stop();
}

int main(){
    create_connect();
    while(1){
        create_turn_in_place(180, 100);
        create_turn_in_place(-180, -100);
    }
}

Also, I've tried using these wrappers, but they didn't help. That might suggest that the bug is somewhere besides the actual set functions, but I'm not sure where else it could be.

void set_create_total_angle_fixed(int angle){
    do{
    	set_create_total_angle(angle);
    }while(get_create_total_angle()!=angle);
}
void set_create_distance_fixed(int dist){
    do{
    	set_create_distance(dist);
    }while(get_create_distance()!=dist);
}
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