09-20-2022 04:09 AM
hello everyone,
This is a difficult algorithm, I must say at first. At least it is for me.
I have an AC servo motor. I calculated one complete revolution of the motor and mapped it between 0-360 degrees.The motor goes to the given position in the -/+ direction.
If I give -/+ values between 0 and 360 degrees to the motor after mapping, it will act accordingly.
For example:
If I give -20 degrees the Motor will move in CCW direction and go up to 20 degrees.
If I give +20 degrees, the motor goes 20 degrees to the right.
Note: Here it goes to the absolute position of the digit sent.
The situation I want to create and have a problem with is as follows.
No matter how many turns the motor turns, it should go to the real compass position entered between 0-360 degrees and calculate the shortest path with compass logic.
It's just a question of creating algorithms.
Below is an example that is causing the problem I created.
Can anyone help with this?
Any opinion given is worthy of respect.
Solved! Go to Solution.
09-20-2022 04:25 AM
@constructionworker wrote:For example:
If I give -20 degrees the Motor will move in CCW direction and go up to 20 degrees.
If I give +20 degrees, the motor goes 20 degrees to the right.
Note: Here it goes to the absolute position of the digit sent.
That's quite confusing...
CCW is one direction, to the right the other (CW?). I'd stick with CCW and CW, to the left\right is ambiguous with angles (unless you specify if the bottom or top goes to the left\right).
This calculates the difference between the 2 angles, and gives the shortest dAngle to that position.
09-20-2022 08:40 AM
Thanks for your reply wiebe@CARYA
Yes, let me explain the situation again in some detail, as sticking to the CW and CCW would be a bit more confusing.
This is the AC servo I am currently using. The motor moves with absolute position information.
If I send a 20 degree rotation position pulse to the motor it will rotate 20 degrees in the "CW" direction. And again if I send -10 it will return and after reaching 0 it will turn in CCW direction and it will actually go to -10' which corresponds to 350 degrees.
What I want to create is to write numbers between 0-360 degrees, but it doesn't matter whether - position or + position goes to the motor, what matters is that it goes to real compass degrees.
The example you gave does not meet the situation I described above.
because it sends a positive number again after it passes -179 degrees.If I send 180 degrees to the motor after -170, -179 degrees, the motor will return from the CCW position it went to, and after reaching the 0 position, it will go 180 degrees in the CW direction.
I hope I explained well.
09-20-2022 08:53 AM - edited 09-20-2022 08:54 AM
Your example does not make a lot of sense, especially since you are using a greedy loop and only one indicator and one control.
You need a control for the desired new position
You need an indicator (or control when testing) for the current position. (In real life, the current position is given by the hardware)
You need an indicator that shows the +/- angle required to go to the desired position.
Your loop needs a wait.
I am sure that you can start with Wiebe's example and get it to do what you want with a few tweaks. I am sure you don't need that birds nest of code of your original.
09-20-2022 11:57 AM
@constructionworker wrote:
Thanks for your reply wiebe@CARYA
Yes, let me explain the situation again in some detail, as sticking to the CW and CCW would be a bit more confusing.
This is the AC servo I am currently using. The motor moves with absolute position information.
If I send a 20 degree rotation position pulse to the motor it will rotate 20 degrees in the "CW" direction. And again if I send -10 it will return and after reaching 0 it will turn in CCW direction and it will actually go to -10' which corresponds to 350 degrees.
What I want to create is to write numbers between 0-360 degrees, but it doesn't matter whether - position or + position goes to the motor, what matters is that it goes to real compass degrees.
If you just want to convert an angle, + or - to a 0-360 deg. angle, simply do the modulus 360...
09-20-2022 02:09 PM
@constructionworker wrote:
Thanks for your reply wiebe@CARYA
Yes, let me explain the situation again in some detail, as sticking to the CW and CCW would be a bit more confusing.
This is the AC servo I am currently using. The motor moves with absolute position information.
If I send a 20 degree rotation position pulse to the motor it will rotate 20 degrees in the "CW" direction. And again if I send -10 it will return and after reaching 0 it will turn in CCW direction and it will actually go to -10' which corresponds to 350 degrees.
What I want to create is to write numbers between 0-360 degrees, but it doesn't matter whether - position or + position goes to the motor, what matters is that it goes to real compass degrees.
The example you gave does not meet the situation I described above.
because it sends a positive number again after it passes -179 degrees.If I send 180 degrees to the motor after -170, -179 degrees, the motor will return from the CCW position it went to, and after reaching the 0 position, it will go 180 degrees in the CW direction.
I hope I explained well.
Maybe this is what you are looking for, give it a try . Thanks to wiebe@CARYA for most of the code.
09-20-2022 02:32 PM
wiebe@CARYA wrote:
This calculates the difference between the 2 angles, and gives the shortest dAngle to that position.Careful there. The difference can be anywhere between -359 and +359.
09-20-2022 03:43 PM
@altenbach wrote:
Your example does not make a lot of sense, especially since you are using a greedy loop and only one indicator and one control.
You need a control for the desired new position
You need an indicator (or control when testing) for the current position. (In real life, the current position is given by the hardware)
You need an indicator that shows the +/- angle required to go to the desired position.
Your loop needs a wait.
I am sure that you can start with Wiebe's example and get it to do what you want with a few tweaks. I am sure you don't need that birds nest of code of your original.
Thanks for everyone's reply.
Actually, I'm sure there is no need for this bird's nest, but I have tried every possible way. I probably tried 200 algorithm methods, but I couldn't get exactly what I wanted 🙂
I have examined and tested the example you have created here, but here it sends the engine how far it needs to move from the normal position. What is required is absolute position information to the engine.
This is what I tried to explain above. So if I send -350 to the motor, the motor goes to -350 degrees in the CCW direction and stops. The motor is doing absolute positioning.
The main problem here is not the difference, I need to send the location directly.
I've been testing it thoroughly but couldn't find a way. That's why I can't answer very quickly.
09-20-2022 05:17 PM
As wiebe already answered back in msg #5, the modulus function can be used to map any positive or negative value into your desired compass degree range [0,360).
-Kevin P
09-20-2022 05:56 PM - edited 09-20-2022 05:57 PM
@constructionworker wrote:I have examined and tested the example you have created here, but here it sends the engine how far it needs to move from the normal position. What is required is absolute position information to the engine.
This is what I tried to explain above. So if I send -350 to the motor, the motor goes to -350 degrees in the CCW direction and stops. The motor is doing absolute positioning.
So now I am confused, if the servo is at 0deg and you want it to go to 270deg do you send it 270 or -90, or something else?