Skip to content

Create distance & angle counters overwritten #190

@Jammo2000

Description

@Jammo2000

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);
}

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