Clock Hand - Gravity Swoop using MoToStepper

Hi all,

I have a particularly challenging task (for me anyway) and it's to perform what I call a "Gravity Swoop" with a clock hand using the following set up:
Arduino Nano
TMC2208 Stepper drivers x 2
BKA30D-R5 Dual Shafted Stepper motor, with 3D printed clock hands on it

I have used the excellent MobaTools library / MoToStepper functionality to replace the limitations that Accelstepper presented which gives me the following options:

  1. SpeedSteps - Which goes up to 25,000 and basically controls the speed of the stepper motor
  2. RampLen - The length of the starting and finishing 'Ramp' to give a smooth start and stop motion, rather than a sudden movement.

My challenge is:

  1. To start moving the stepper motor (aka Clock Hand) slowly at first/ at last (using RampLen) - easy, I have done this :slight_smile:
  2. To then control the acceleration/deceleration of the 'middle' movement dependant on position of the clock hand, in particular if it was moving downhill or uphill - very much not easy!

For example, if I were to look at a regular clock face. If the hand was at the 12 position (and had a metal weight on it) it would gather much more momentum moving downwards until it got to 6 and then gradually slow down until it got back upwards (up the hill) to 12 - completing a revolution.
3. The last permutation of this would be that, if the hand was at the 3 position when I moved it, the time for 'Gravity Swoop / super acceleration' would be 1/2 that of what it would have been if it started from 12, as gravity would have 50% less time to act.

Obviously, I will keep trying to get my head around this but I am hoping that there is either a simple way (which my simpler head cannot understand) or the geniuses that frequent this site can help point me to :wink:

Thanks all, I am appreciative of any support.

TK :slight_smile:

Wouldn't you just extend the accel and decel period and eliminate the middle part ?

So if there are 200 steps per rev, and starting from 12 o'clock position, accel for 100 steps then decel for 100 steps.

1 Like

My approach would be to use a simple STEP/DIR motor driver. For a (seconds) clock hand and a 200 step per revolution stepper, the step time is constant, 1 step per 60/200 seconds. Call that base time, Vb = 60.0/200.0.

Thinking of the clock hand as an inverted pendulum, gravity would cause an angular acceleration (decrease in step time, increase in speed) proportional to sin(theta), where theta is the angle from vertical.

If stepper position 0 is vertical,

V = Vb - constant*sin(step_number*PI/200)

This program prints a table of the step time and velocity as a function of step, for constant = 0.2 You will notice that the hand is going fastest (short times per step) at step 100, then slows down as it returns to upright (200).

void setup()
{
  Serial.begin(115200);
  while (!Serial); //wait for connection
  float Vb = 60.0 / 200.0; //base step rate (time per step)
  float K = 0.2; //arbitrary constant

  // print table of step times
  for (int i = 0; i <= 200; i++) {
    float rate = Vb - K * sin(i * PI / 200);
    Serial.print(i);
    Serial.print(", time/step= ");
    Serial.print(rate);
    Serial.print(", speed = ");
    Serial.println(1 / rate);
  }

}

void loop()
{}

If you want to make it so that the clock hand still does one revolution in 60 seconds, then both the base step time and the constant have to be adjusted so that the average step time is 1 step per 60/200 seconds.

1 Like

Counterbalance the "hand".

Hi TK,
I don't think you want to move the hands in real Clock time? The basic approach could be something like @bobcousins suggested. But maybe it looks better if you have a short range with constant speed around the 6 o'clock position.
Here is a very basic WokWi simulation where you can experiment with:

1 Like

Good idea, however, the answer may be a bit more nuanced. For example, the hand may not alway be starting from the 12 position, so if it started from the 7 O'clock position, then it would speed uphill and slow down downhill.

I also am using the max speed, as I am using the highest step rate. By lowering the step rate, that will help to further accelerate the hand but the less smooth the motion will be.

I will play around and see where I get and report back

Thank you very much

:slight_smile:

For full disclosure:

  1. I am not making an analogue clock per se and am not using a second hand. Instead, I am using clock hands to make cool patterns
  2. I will need to study your suggestion in more detail before giving it the response it deserves. However, I will do that.

Again, worth mentioning that the Gravity Swoop motion is a movement feature that I want to be able to turn on/off in my code, so when I make a display of moving hands, I can enable or disable this functionality at will. Importantly, the rule will need some conditions, which I need to draw up, such as "only apply gravity swoop, if the hand is between 12 and 3 when it starts moving and the finishing position is at least 8 hour positions, or further, in the same movement.

Thank you

This made me smile. The gravity swoop is what I want to achieve :slight_smile:

Wow!,

I didn't know about that simulator website - thanks for that. It's exactly the motion I am after. As I have said in my reply to Bob, I think the mistake I made what setting up my stepper motion driver to move 11250 steps per revolution, to make the movement as smooth as my stepper driver (TMC2208) would allow me, so full speed (SpeedSteps=25000) still didn't move the hand as fast as you might imagine. However, I will reduce the stepping from 1/16 to 1/8 and try again to see what the motion looks like.

Thank you so much, I am learning lots here and really enjoying it.

I am not sure if you are saying that is what you want or not. You suggested a couple of specific examples, I provided an answer for one of them, I hoped that you could apply the method generally.

My understanding was that 12 is the "top" of the gradient and 6 "the bottom". Therefore a hand starting at 7 would "fall" to 6, then move up to 5.

A general solution is to calculate the number of steps between the start position and end position, call it N. Then accelerate for N/2 steps and decelerate for N/2 steps. That works with stepper libraries which support a fixed and symmetrical accel/decel.

If you need a non-linear acceleration, or asymmetric acceleration and deceleration, then you would probably need to implement your own stepping code.

At least with MoToStepper you don't need to E.g. if you want asymmetric acceleration and deceleration, you ca easily change the ramplen while the motor moves. And you can check at any time at which position the motor is, to decide when to change the ramplength or speed.

Apologies Bob,
If I’ve not been clear or don’t sound appreciative, which I am.

My requirements have evolved the more thought I give them. That said, I think I’m there, or nearly there.
I think I’m going to plan the movement from each starting position or only allow the Gravity Swoop motion if the clock hand is in one of 3 positions (1, 2 or 3pm) when starting, that should reduce the complexity.

Many thanks and kind regards

Hi,
I had to seek help from my newest friend, GPT, so help explain your statement (see below) but yes, that does the trick, perfectly :slight_smile: - thank you

This statement is describing a phenomenon where the force of gravity influences the speed of rotation of an object. Here's an explanation:

  1. Angular Acceleration: Angular acceleration refers to the rate of change of angular velocity. In this context, it means how quickly the rotational speed of an object changes over time.
  2. Proportional to sin(theta): The angular acceleration is said to be proportional to the sine of the angle theta. Theta represents the angle between the vertical axis (typically straight up) and the direction of rotation.
  3. Gravity's Influence: When an object rotates, the force of gravity can affect its speed of rotation. The closer the angle theta is to 90 degrees (perpendicular to the ground), the stronger the effect of gravity on the rotation. At this position, the sine of theta is at its maximum value of 1.0, meaning the angular acceleration is highest.
  4. Sinusoidal Relationship: The statement implies that the relationship between the angle and the angular acceleration follows a sinusoidal pattern. As the object rotates, the angle changes, leading to variations in angular acceleration. This variation follows the sinusoidal curve, with maximum acceleration occurring at certain angles and minimum acceleration occurring at others.

In summary, the statement suggests that the force of gravity affects the rotational speed of an object, with the acceleration being highest when the object is at certain angles relative to the vertical axis, as described by the sine function.

Introductory physics and math are pretty useful if you wish to accurately model the effect of gravity.

Agreed!, every day is a school day right? :slight_smile: - thanks again

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.