Really sorry for the late reply, I had set the forum to notify me by email when I get a response but I never received anything.
Thank you for your replies however. I am going to try to answer all your questions so hopefully we can reach a solution.
Are you mixing up integers and floating point values in your maths?
I tried to do it both ways, it still Doesn’t seem to work. What happens is… say the setpoint is 2 and the next setpoint is 3. In this case, the program works nicely and proportionally increases with time to 3 (using the straight line equation). However, if the setpoint is 2 and the next is 4. The program skip from 2 to 3, then proportionally increases from 3 to 4 in a straight line, rather than increasing from 2 to 4 within the time gap.
The next problem is, the gradient should automatically become negative as the setpoint decreases, however that doesnt work and I needed to add the same equation again with a - in front.
So have we, it’s not in code tags! You could have read the documentation for this part of the forum. There is say Read this before posting …
Try reading the documentation for sizeof.
Sorry about that Mark, I have just noticed that. I will change it.
The sizeof is not the problem, that part of the code does the job required and counts the number of data points inside the array correctly. However, maybe it is the problem… are you seeing something I am not?
(SetpointInterval / TimeInterval)
That’s integer division. Integer division gives wrong results since the result is truncated
to an integer. 5 / 2 gives 2.
Declare SetpointInterval as float and it’ll work.
Tried it mate, still not working as I expect it to.
No, it isn’t. SetpointInterval and TimeInterval were declared “double”, so that is not the problem.
@omario93: The following declaration may not be doing what you expect. Did you intend to declare SetpointInterval and TimeInterval as functions of j? If so, the #define macro can accomplish that.
As defined below, SetpointInterval and TimeInterval are initialized to 2.0 and 4000.0 and will not change thereafter.
int j; // The term number in the arrays;
// Variables used to change the setpoint;
double SetpointInterval = (SetpointArray [j+1] - SetpointArray [j]);
double TimeInterval = (SetpointTimeArray [j+1] - SetpointTimeArray [j]);
Yes I think you are right! :D… this is the most reasonable explanation as I have noticed that the gradient and time interval do not change! I am going to look at how to incorporate the #Define function… but I will also post a simplified version of the code and you can show me where you add it if you have time.
int DataPoints = (((sizeof(SetpointTimeArray)) / 4) - 1); // Counts the number of data points inside the time array. The sizeof function give the number of bits inside the array;
The SetpointTimeArray array type is int, so why are you dividing by 4?
Why does SerpointTimeArray need “Array” in the name? Aren’t the enough to remind you that it is an array?
Why are you subtracting 1?
The way I see it, sizeof(SetpointTimeArray) will return 16, so DataPoints will be 3. I fail to see how 3 is a useful number, given that there are 8 values in the array.
I am dividing by 4 because in the array each data point adds 4 to the overall output the sizeof function. So if I have 7 data points the sizeof function will return 28.
So, I divide by 4 that gives me 7. I then subtract by 1 because the first value counts as 0 in the array… so when j = 6, this refers to the 7th value.
I hope that helps.
As for why I put array in the name of an array, good question lol… I am not writing this code for myself but for a supervisor and future research assistants. We are working on a tensile testing machine that will be used in medical hospitals to check the condition of living tissue.
Kind regards and many thanks,