AMPS-N:
In below code i am trying to run motor for Every 1 min . Here i am attaching algorithm, calculation parts and code for understanding.
Question : how to run actuator exact 1 min.It should move 0.9091 mm per minute as mentioned. Let me know what mistake i done.
Well, you have to time it. You have a variable called h, and one called m. hours and minutes? Possibly, but hard to tell. Meaningful variable names are best. Anyway, you have another variable, TS, that looks like it is calculated from h and m, but nowhere do I see anything that sets any sort of time into h and m.
What makes m increase, and how often do you think it increases? You need to use something like a real-time clock, or millis() to get any sort of meaningful increments for time variables. You call calc_min() evey time through loop(). That is going to happen VERY quickly, considering that at 16MHz an Arduino has a cycle time of 62.5 nanoseconds.
Read the Blink Without Delay sketch in the examples directory of the IDE. You can use those techniques to time any events.
AMPS-N:
In below code i am trying to run motor for Every 1 min . Here i am attaching algorithm, calculation parts and code for understanding.
Question : how to run actuator exact 1 min.It should move 0.9091 mm per minute as mentioned. Let me know what mistake i done.
Well, you have to time it. You have a variable called h, and one called m. hours and minutes? Possibly, but hard to tell. Meaningful variable names are best. Anyway, you have another variable, TS, that looks like it is calculated from h and m, but nowhere do I see anything that sets any sort of time into h and m.
What makes m increase, and how often do you think it increases? You need to use something like a real-time clock, or millis() to get any sort of meaningful increments for time variables. You call calc_min() evey time through loop(). That is going to happen VERY quickly, considering that at 16MHz an Arduino has a cycle time of 62.5 nanoseconds.
Read the Blink Without Delay sketch in the examples directory of the IDE. You can use those techniques to time any events.
Practically i am using Ds1307 RTC . For testing I created fake time Here So that time get incremented for Every 5 min.Yes H means hour and m means minute.TS variable used to calculate time in Seconds.
I find your code almost impenetrable but I would be very suspicious of this if((Desired_pos-Actual_pos)==0.0)Both the variables are floats, so the likelihood of the subtraction equalling exactly 0.0 is small, particularly when you have statements like this Actual_pos=Actual_pos+6.4;and this Actual_pos=Actual_pos-6.4; in the code.
UKHeliBob:
I find your code almost impenetrable but I would be very suspicious of this if((Desired_pos-Actual_pos)==0.0)Both the variables are floats, so the likelihood of the subtraction equalling exactly 0.0 is small, particularly when you have statements like this Actual_pos=Actual_pos+6.4;and this Actual_pos=Actual_pos-6.4;in the code.
ya we can make it has +/- 1 degree. so that it goto stow position and stops.And have you found any error in actuator position image attached why it is varying??
And in program i am saying move forward and reverse. But i wanted to actuate for only 2 second
calculation of HDEC value calculation.Since motor runs for 1 min it has to calculate no of minutes elapsed and that has to get multiplied by 0.909
2)turn on/off of actuator.
AMPS-N:
Question : how to run actuator exact 1 min.It should move 0.9091 mm per minute as mentioned. Let me know what mistake i done.
Note the current value of millis(). Start running the actuator.
Read the return value of millis() repeatedly. After each reading, subtract the start value to get the elapsed time. When the elapsed time exceeds 60,000 ms, stop running the actuator. The blink without delay example sketch demonstrates doing this.