Results 1 to 10 of 10

Thread: How does the RadToServo function work in nuke code?

  1. Question 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:
    int radToServo(float rads){ float val = (rads*100)/51 * 100;
    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. #2
    Join Date
    Dec 2012
    Location
    Los Angeles, CA
    Posts
    858
    Images
    25
    Rep Power
    88

    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. 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:
    Click image for larger version. 

Name:	1.jpg 
Views:	219 
Size:	24.2 KB 
ID:	5857
    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:
    Click image for larger version. 

Name:	2.JPG 
Views:	199 
Size:	11.6 KB 
ID:	5858
    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. #4
    Join Date
    Sep 2010
    Location
    ಠ_ಠ
    Posts
    2,300
    Images
    27
    Rep Power
    278

    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.
    Please pardon the pedantry... and the profanity... and the convoluted speech pattern...
    "You have failed me, Brain!"
    bleh
    more bleh

  5. #5
    Join Date
    Dec 2012
    Location
    Los Angeles, CA
    Posts
    858
    Images
    25
    Rep Power
    88

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

    Quote Originally Posted by maynight View Post
    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. #6
    Join Date
    Dec 2012
    Location
    Los Angeles, CA
    Posts
    858
    Images
    25
    Rep Power
    88

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

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

  7. 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
    int radToServo(float rads){ float val = rads * @RAD_TO_SERVO_RESOLUTION;
    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. #8
    Join Date
    Dec 2012
    Location
    Los Angeles, CA
    Posts
    858
    Images
    25
    Rep Power
    88

    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. #9
    Join Date
    Sep 2010
    Location
    ಠ_ಠ
    Posts
    2,300
    Images
    27
    Rep Power
    278

    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.
    Please pardon the pedantry... and the profanity... and the convoluted speech pattern...
    "You have failed me, Brain!"
    bleh
    more bleh

  10. 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.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Question(s) 3DOF Hexapod with towerpro 995 servos, how i can get it to work, is there ready code for this?
    By robotnick in forum Robotics General Discussion
    Replies: 3
    Last Post: 08-09-2014, 09:19 PM
  2. The CM-900 code, and how to work around itT
    By jwatte in forum Arbotix, Microcontrollers, Arduino
    Replies: 30
    Last Post: 02-24-2014, 06:40 PM
  3. Calculating frame rate and function time
    By TXBDan in forum Software and Programming
    Replies: 13
    Last Post: 05-22-2013, 03:05 PM
  4. Nuke code for airsoft help request
    By lumpen5 in forum Mech Warfare
    Replies: 1
    Last Post: 04-02-2013, 08:57 PM
  5. PWM to Phidget Servo position function
    By Alex in forum Arbotix, Microcontrollers, Arduino
    Replies: 2
    Last Post: 08-13-2007, 05:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •