Enkoder measurements

Could an incremental encoder be coded into the arduino to get velocity, force and power and their averages?

I think it's actually used in some commercially available devices.

For example, chronojump has an open source software, can I get data from an encoder with this software via ardunio?

yes

Hi izoli,
Do you have the arduino and the encoder? (what type?) I have the code for the position, it will be necessary to add a little calculation for the velocity (what speed of rotation do you envisage? the speed will be stable?) to calculate the force and power, it will be necessary to have other parameters.

Fine ! did you already connect them ? or not yet ?

ok, you're well on your way; can you show your code ?

(use the </> icon on the top of the message window, and copy your code between the tags)

great.
to know the velocity, you have to make a time window, collect the position at the beginning and end of the window, and then you can calculate the velocity during the time of the window. The size of this window depends on the stability (or not) of the positional variation.
I am giving you an example.

Hi, @izoli
What is your project?
What do you want to measure those parameters from?
Rotary or linear motion?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

So we can get the angular velocity w from knowing the position at two points in time; I'm assuming that's what OP means by the velocity when he says:

So far so good. But that's not going to convert to force or power. To get the power you need the torque (P=Tw) and to get the torque you need to measure it somehow. That's the tricky part.

Pal of mine did his PhD in exactly that in 1986- his particular interest at the time was the knee during a golf swing. One of his colleagues in another department designed a thingy for the golfer (I hesitate to use the word "athlete" here :wink: ) to stand on while swinging and it captured whatever. It's in the thesis library at our alma mater, but according to the catalog I don't see it as having been digitized. Maybe you can get it thru ILL.

edit-

Absolutely correct, hence his being able to get a PhD out of that. His undergrad was physics; his M level work (late 70s) was on the maths of brain waves. This guy was (I say was, sadly now late) was a total boffin on this stuff.

Thanks, if i get velocity data continuously i hope to get other data with some formulas.

Actually, I just read a project (the following link). Actually, the codes in this project can work for me in the "velocity" variable. If I create graphics in this project, at least I will have made a way for this variable.

I doubt it: you can't get the other data from the velocity, you need to get it in its own right. You could infer the torque perhaps from the geometry, or (as in the case of the golf swing example) measure it on a brake.

You have 3 variables in the equation P=Tw, so you need to have 2 to get the other one. If you want power, you need the torque and the angular velocity. To get the torque you could measure the force (or know the mass of the dumbell) and the arm; that's largely a matter of geometry.

All the encoder is going to give you is position, from which (with time) you can get the angular velocity. The other one will need to be obtained from other means.

And in that case, the mass and the geometry are known or measurable.

There's a reason that thing costs 4 salaries and why there are PhDs behind there to understand (edit: and implement) the physics.

What has a simple encoder got to do with the guy and that huge bar anyway? Where would you attach it and what position are you thinking to measure?

I'm thinking that that this thing:

image

... has some vision in it to map the movements over time. The mass is known. The rest is just sums.

I'll send you a link to my mate's PhD library entry if you like; perhaps you can ILL it through your institute or local library.

You do need to know the physics here, I have no doubt about that.

The velocity is raw, i.e. it is not calibrated in m/s or angular velocity... you have to calculate it, now! according to your encoder.

the time window is 400 ms long (0.4s), and you can modify it with the serial terminal:
1 200 1 [enter]

the first value (1) is a divisor, for later calculation

the second value (200) is the time window

the third value allows you to display either the encoder position (enter 0) or its speed (enter 1)

try it:
1 100 1 [enter]
or
1 500 1 [enter]
or
1 500 0 [enter] to display the position

Encoder myEnc(2, 3);                                          //   avoid using pins with LEDs attached
long oldPosition  = -999;

long          firstStep;                                      // 1rst step of the time window
long          lasttStep;                                      // last step of the time window
unsigned long prevmillis;                                     // 
long          rawVelocity;                                    // 
int           durationWindow = 400;                           // xxx ms (time window)
int           divisor = 1;                                    //
int           velOrSteps = 1;                                 // 1= print velocity     0= print steps


void setup() {
  Serial.begin(9600);                                         // or 115200, and fix the serial monitor accordingly !
  Serial.println("Basic Encoder Test:");
}



void loop() {
  long newPosition = myEnc.read();                            // like your previous code
  if (newPosition != oldPosition) oldPosition = newPosition;  // like your previous code


  
  if (millis() - prevmillis > durationWindow) {               // start a time window (length=durationWindow, in ms)
    prevmillis  = millis();                                   //         
    lasttStep = newPosition;                                  //

    rawVelocity = (firstStep - lasttStep) / divisor;          // first-last    for CW printing...
    
    firstStep = newPosition;                                  // start a new calculation

    if (velOrSteps == 1) Serial.println(rawVelocity);         //
    if (velOrSteps == 0) Serial.println(newPosition);         //
  }                                                           //
   processMessage();                                          // modify dynamicaly some variables, whith serial monitor
}




                                              
void processMessage() {                                       // code to process messages from the serial port
  if (Serial.available() > 0) {                               // type val1 val21 val3 [enter]
                                                              // val1=1..10     val2=10..1000     val3=0..1
    divisor        = Serial.parseInt();                       // first variable to be modified
    durationWindow = Serial.parseInt();                       // second one
    velOrSteps     = Serial.parseInt();                       // third one

    if (Serial.read() == '\n') {                              // print the modifications (after "enter" touch)
      Serial.println("---------------------");
      Serial.print("durationWindow = ");   Serial.println(durationWindow);
      Serial.print("divisor = ");              Serial.println(divisor);    

      if (velOrSteps == 1)                 Serial.println("RawVelocity"); 
      if (velOrSteps == 0)                 Serial.println("Steps"); 
      Serial.println("---------------------");   
    }
  }  
}

I'm not sure why anyone is talking about torque.

The commercial device that the OP is trying to duplicate is in the yellow circle in the image below.

A string connects the device to the barbell. String payout and pay-in can be used to measure the barbell linear displacement and the associated linear velocity and acceleration.

If the motion is primarily vertical, then the associated force and power needed to move the mass can be calculated.

A rotary encoder connected to a spool of string that has a spring to help the string retract (like a vacuum cleaner cord) , could be used to measure the string linear payout and pay-in, and the associated linear velocity, acceleration, force, power, etc.

But torque isn't a factor in those calculations (except the spring needs to have enough torque to ensure the string retracts properly...and that's a completely different issue).

Obviously the angular position returned by the encoder needs to be translated into linear displacement; that's a function of the radius to the string (and also has nothing to do with torque).

Spool design may be a bit tricky to ensure consistent results.

image

Hi,
I agree with @DaveEvans.
With the pull wire you are measuring the change height of the mass, that is distance travelled from squat to extension.
You know the mass being moved so you can work out the change in potential energy, this is work done.
Work done = Force x distance.

I think I got that right.

Tom.... :smiley::+1: :coffee: :australia:

1 Like

Because until the OP gave some detail and that pic, and was talking about encoders, it seemed to me that the motion being considered was rotational, like someone lifting a weight by bending their elbow.

It took to post 17 for the OP to show that the movement was essentially vertical. I didn't see the sting thingy until you circled it, and that's why I asked about the photo:

Yes now it's clear that the encoder is simply to measure the string going out to get the map of distance moved vs time. OP had never yet mentioned what the encoder was for.

The OP's question could have been:

Can I use an encoder on a shaft to measure the velocity of the surface of the shaft (so that I can know the velocity of a string on a spool)?

The use of those numbers is incidental: that they are used to let us know how quickly a mass is lifted vertically and to calculate power, is neither here nor there.

It's still true of course to say:

The physics of that is trivial: simple early high school science is all that's needed.

W=Fd=mgh
P=W/t

right, octopirate, DaveEvans & TomGeorge. With a linear motion, the calculation is simpler, because you need a distance (encoder steps), a time (the arduino knows how to do it), the velocity derived from these two parameters, and finally the mass to move. For other complex movements, the torque may be necessary, it's more complicated but izoli, you can start with the simplest! you know how the recorder presented in the photo works? how it specifies the mass, and how it delivers its data? I guess it records the efforts of the athlete, then we will connect it to a computer in which we specify, a posteriori, the mass.

For the current tests, I suggest you configure the Serial.begin in 115200 Bauds (and the terminal too, when you open it); and to try the curve plotting function in the IDE of the arduino: here is my encoder velocity (1440 steps) with my code above :
.
.
izoli

1 Like

Hi izoli, how are you doing with this project? No difficulties?

I saw the video and loaded PLX-DAQ, to understand; but I am under Linux, and cannot try this Windows function; maybe someone here knows how to do the acquisition under Excell? you're close to a good result

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