Integer Array?
Posted: Wed Jul 27, 2011 1:46 pm
Hello,
I would like to implement an integer array using Flowcode. Initially I provided a byte array by defining a string variable Data[250] and this worked fine. To simply accommodate large numbers I can obviously use two byte arrays in parallel, one for the high byte, one for the low byte. however, the reason I wish to use an integer is to accommodate negative numbers.
Unless there is a simple solution to the above then let me illustrate the problem I'm trying to solve, as more experienced programmers than I may have an alternative suggestion as to how to solve the problem.
I have a line follower robot, each iteration of the 'sense line-move' iterative line following process has the outcome stored in an array.
I then carry out trend analysis on the array to move the program into a predictive level of operation.
The above works reasonably well using a byte array but any level of analysis became unduly complicated.
I therefore had in mind storing a value of -X for move to the left, 0 for straight ahead and X for move to the right. Simply adding up the preceding set of N values from the array would immediately tell me if there was a net change in direction and conveniently screen out the randomness associated with line detection. The problem being that the byte based method simply looked for blocks of the same movement, which was easily upset by the odd 'random' deviation from course.
A first thought was to use two's complement numbers in the byte array. But I don't understand the underlying maths enough to know if using (1 for 1, 128 for -1 and 0 for 0 would allow me to add up all the bytes into an integer variable and still get a nett result, presumably not. Or should I convert each signed byte to an integer and then do the maths? If so is there a neat way of doing this?
Thanks for any input in advance. Whilst the question is mostly related to Formula Flowcode the underlying issue is a programming one, hence I have put it in this part of the forum.
I would like to implement an integer array using Flowcode. Initially I provided a byte array by defining a string variable Data[250] and this worked fine. To simply accommodate large numbers I can obviously use two byte arrays in parallel, one for the high byte, one for the low byte. however, the reason I wish to use an integer is to accommodate negative numbers.
Unless there is a simple solution to the above then let me illustrate the problem I'm trying to solve, as more experienced programmers than I may have an alternative suggestion as to how to solve the problem.
I have a line follower robot, each iteration of the 'sense line-move' iterative line following process has the outcome stored in an array.
I then carry out trend analysis on the array to move the program into a predictive level of operation.
The above works reasonably well using a byte array but any level of analysis became unduly complicated.
I therefore had in mind storing a value of -X for move to the left, 0 for straight ahead and X for move to the right. Simply adding up the preceding set of N values from the array would immediately tell me if there was a net change in direction and conveniently screen out the randomness associated with line detection. The problem being that the byte based method simply looked for blocks of the same movement, which was easily upset by the odd 'random' deviation from course.
A first thought was to use two's complement numbers in the byte array. But I don't understand the underlying maths enough to know if using (1 for 1, 128 for -1 and 0 for 0 would allow me to add up all the bytes into an integer variable and still get a nett result, presumably not. Or should I convert each signed byte to an integer and then do the maths? If so is there a neat way of doing this?
Thanks for any input in advance. Whilst the question is mostly related to Formula Flowcode the underlying issue is a programming one, hence I have put it in this part of the forum.