1. Vacuum Tube
Join Date
Oct 2014
Location
[email protected]
Posts
22
Rep Power
18

## How does the RadToServo function work in nuke code?

Hi everyone:
Can I ask a question about how the RadToServo function work in nuke code? We are using nuke code for hexapod phantom X MarkII. The function says this:
return (int) val;
}

And it is used as follows:
ans.coxa = radToServo(atan2(X,Y)); //which transform the actual angle(in radian) into some intermediate value
then:
servo = 368 + sol.coxa; //which transform the intermediate value to the actual servo angle(from 0 to 1024)

I also notice that different servos have different transformations like
servo = 524 + sol.femur;
servo = 354 + sol.tibia;

We are trying to implement this code on a dynamixel pro motor so we want to know how radToServo works and how those numbers(like 368, 524, 354,etc) are created?
Thank you!

2. ## Re: How does the RadToServo function work in nuke code?

It's radians to servo ticks as you know. The 524 and 354 are simple offsets added due to servos orientation in the legs. Offsets in servo ticks...

3. Vacuum Tube
Join Date
Oct 2014
Location
[email protected]
Posts
22
Rep Power
18

## Re: How does the RadToServo function work in nuke code?

Hi:
Thank you for your quick reply. Let's use the right-front leg as an example. This is the coxa angle of this leg:

Since atan2 function returns this angle, the range should be between -1.57~1.57 rad. After going over (rads*100/51)*100 the range becomes -616~616, which has a range 2*616=1232. This is a diagram for ax-12a motor:

I am pretty sure that the servo ticks is 0(0 degrees)~1023(300 degrees), which doesn't correspond to 1232. Even after you add the offset, the range doesn't get changed. This is one place which confuse us.
Also, do you have geometric diagrams to indicate where the 0 positions of each leg is set to as well as how you define the positive direction of each angle? We need to rewrite this part so it would be really helpful if you have some diagrams. We can be much more confident about our understanding of the code you provide.
Thank you again for your help!

4. ## Re: How does the RadToServo function work in nuke code?

What version of pypose are you using and where did you get it? Using anything older than the github version is a bad idea and leads to having the same discussions over and over because there are plenty of known issues in the defunct googlecode archives. Anywho, the newer versions use constant float values resulting from '(1024÷300)×(180÷PI)' or '(4096÷360)×(180÷PI)', instead of a series of integer operations to approximate it { ((1.57*100)/51*100) = ~308 servo ticks}.
Last edited by tician; 03-29-2015 at 05:04 AM.

5. ## Re: How does the RadToServo function work in nuke code?

Originally Posted by maynight
I am pretty sure that the servo ticks is 0(0 degrees)~1023(300 degrees), which doesn't correspond to 1232. Even after you add the offset, the range doesn't get changed. This is one place which confuse us.
Also, do you have geometric diagrams to indicate where the 0 positions of each leg is set to as well as how you define the positive direction of each angle? We need to rewrite this part so it would be really helpful if you have some diagrams. We can be much more confident about our understanding of the code you provide.
Thank you again for your help!
Just to be clear I don't work for Trossen... I just keep the forums spam free.

Now with that being said 512 is 0 degrees on most of Trossen's kits but on some of the new ones they mount the servos with slight offsets in the legs for better range at the start position. Please refer to their assembly documentation for more info.

This is how I do it in my code. Note I use MX-64's.
Code:
```RAD_TO_MX_RESOLUTION = ( MX_CENTER_VALUE*2 ) / ( PI*2 );

goal_pos_[FIRST_COXA_ID   + leg_index] = MX_CENTER_VALUE + round( legs.leg[leg_index].coxa * RAD_TO_MX_RESOLUTION );
goal_pos_[FIRST_FEMUR_ID  + leg_index] = MX_CENTER_VALUE + round( legs.leg[leg_index].femur * RAD_TO_MX_RESOLUTION );
goal_pos_[FIRST_TIBIA_ID  + leg_index] = MX_CENTER_VALUE + round( legs.leg[leg_index].tibia * RAD_TO_MX_RESOLUTION );
goal_pos_[FIRST_TARSUS_ID + leg_index] = MX_CENTER_VALUE + round( legs.leg[leg_index].tarsus * RAD_TO_MX_RESOLUTION );```

6. ## Re: How does the RadToServo function work in nuke code?

To clarify, this essentially gives you a -150 to 150 degrees rotation range.

7. Vacuum Tube
Join Date
Oct 2014
Location
[email protected]
Posts
22
Rep Power
18

## Re: How does the RadToServo function work in nuke code?

Hi:
We are using nuke code from http://learn.trossenrobotics.com/10-...enix-code.html and I realize that it's a very old code which is no longer showing up on that page. The code you provide is in python which I am not too familiar with, do you have a pure C++ version of this code?
For example, the function
return (int) val;
}
I search over all the files and I cannot find where @RAD_TO_SERVO_RESOLUTION is defined (Although I think it should be 1024÷300×(180÷PI), but similar issue may come out in other places)
Thank you!
Last edited by maynight; 03-29-2015 at 02:51 PM.

8. ## Re: How does the RadToServo function work in nuke code?

You are using the phoenix code? The page you linked is to the phoenix code not nuke code.

9. ## Re: How does the RadToServo function work in nuke code?

RAD_TO_SERVO_RESOLUTION is defined in tools->NukeEditor.py at about line 503 and is invoked only when modifying the template files into the arduino sketch files. The version of RadToServo used during setup/testing when running PyPose/NUKE is in tools->models->lizard3->lizard3.py.

10. Vacuum Tube
Join Date
Oct 2014
Location
[email protected]
Posts
22
Rep Power
18

## Re: How does the RadToServo function work in nuke code?

No there's a link in that page which gives nuke code. I am not pretty sure where exactly do we find our nuke code but it's in that Mark-II phantom X product page.

There are currently 1 users browsing this thread. (0 members and 1 guests)