Well start by thinking about happens on the seventh time around the loop, your arrays overflow. Let me look a little more, not sure why you are even using arrays.
You have a large delta time, 1000, you should probably be thinking in terms of 10mS. With such a large delta time the integration will not be very accurate.
There is no need to use an array.
What units do you want the final velocity to be in? perhaps meters per second. So what units should the acceleration be in perhaps m/s^2. If so then convert from milli G into m/s^2 first.
Will integers be able to handle the units for acceleration and velocity, perhaps think about using double.
here’s perhaps some psuedo code.
while( 1 )
{
read acceleration
convert acceleration to correct units
multiply acceleration by delta time (0.01) then add to current value of velocity
wait 10mS
Every hundred times around the loop print results.
}
I don’t really know anything about easyC, but I can point you to a ROBOTC page that might help. The language is different, but the logic should be the same. Here’s the link: ROBOTC
I hope that you get it working.
The example uses tasks, which is probably the best way to do it, the closest thing to tasks in EasyC is the RegisterRepeatingTimer function.
Quoting from another thread
“RegisterRepeatingTimer(RepeatTimeMS, FunctionToBeCalled); uses a low priority timer based interrupt service routine. You can have upto 4 of these running at a time.”
There seems to be more questions about programming in EasyC than RobotC, or am I wrong. Anyone know what percentage of users are on which dev environment?
so from what i’ve gathered, the RegisterRepeatingTimer is the best way to go about this instead of using an array to store values?
By using an array (since it stores previous values), I wanted to have a few consistent negative velocity readings before the robot is told to do anything further. Is this still achievable by using RegisterRepeatingTimer?
for example, if the robot reads a negative velocity for x amount of milliseconds, it would run some code to correct for the negative velocity ie, drive motors forward.
I cant seem to find it in the function blocks, do I just add it in via the code method?