Right now I have 2D stack array that stores information about motor speeds. I’d like to make it dynamic because I suspect that its sheer size is why our robot code crashes all the time.
The purpose of the 2D array is to allow the motors to accelerate to their target speed. Each array within the 2D array stores the speed values recently applied to a specific motor. Each time
motorSet()
is called on that motor, the program updates the array and sets the motor’s speed to the average of the array values. My program is basically an implementation of this.
Because the values in
data
are generated in real-time, loading the data from an external source is, unfortunately, not an option.
As jpearman said a static array would serve you much then a dynamic array. When iterating through the static array to store your values pay special attention to your iterator to make sure you stay within bounds. Something like this would work:
/*
* opcontrol.c
*/
void opcontrol(){
int motorHistory[MOTOR_HISTORY_SIZE];
int i = 0;
while(1){
// opcontrol code
motorHistory* = COMMANDED_POWER;
i++;
delay(20);
}
}
From your application it also sounds like a slew rate control function on the power values sent to the motors would give you the same desired result.*