View unanswered posts | View active topics It is currently Thu May 24, 2018 4:13 am

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Optimisation of moving an arm to a specific coordinate.
Author Message
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Optimisation of moving an arm to a specific coordinate.
I have created an NXT printer before using .pbm files, where the file is read on the nxt and then printed out.
http://en.wikipedia.org/wiki/Netpbm_format

However, now I am trying to instead print pixels, print strokes.
I have created a C++ that parses the pbm file into commands for the nxt in the format
D (lower pen)
U (lift pen)
5 9
5 10
5 11 (coordinates)

I did try to do this in RobotC and it did work, but as I increased the resolution, the array became too large to fit in the NXT's flash memory so I resorted to doing it on the pc.

However, the issue now is for the arm to move to a specific coordinate.
Always, I come back to this issue and sometimes it gets better, sometimes, worse.

Here is the code for the function of moving it to a coordinate. It seems fine to me, yet the movements are always innacurate by up to 1cm (note that my gearing for the two joints are 56:1, 120:1).
/* Functions for a SCARA robot
Some of these variables may seem useless (for example a1 and a2) as I have used them in the past but then realised I didn't need them
but may need them in the future.
*/

const int speed = 50; //speed
const float mm = 1; //mm per pixel
const float arm1 = 15.2*7.95*mm, //Length of arm1 in m
arm2 = 14*7.95*mm, //Length of arm2 in mm
arm1R = 56, //Gear ratios
arm2R = -120;
int asign1,asign2;
float s1,s2; //speed of motors
float t; //time to move to coordinate(in some form of measurement that I don't know)
long a1,a2; //the amount still needed to move to the angle
long target1,target2; //targets for the motor to move to

long encoderBBegin = (arm1R*90), //The start numbers of the motor encoders (90 and 180 degrees so the arm forms a straight line)
encoderCBegin = (arm2R*180);

void moveToAngle(float angle1, float angle2){ //function to move the arm to a certain position (using two angles)
target1 = ceil(angle1 * arm1R - encoderBBegin);
a1 = target1;

target2 = ceil(angle2 * arm2R - encoderCBegin);
a2 = target2;

// find t (time in s)
asign1=1;
asign2=1;
if(a1<0){
a1*=-1;
asign1 = -1;
}
if(a2<0){
a2*=-1;
asign2 = -1;
}
if(a1>a2){
t=a1/speed;
}
else{
t=a2/speed;
}
if(t<0){
t *= -1;
}
// find speeds
s1 = ceil(asign1*a1/t);
s2 = ceil(asign2*a2/t);

nxtDisplayTextLine(3,"%f - %d",angle1,target1);
nxtDisplayTextLine(4,"%f - %d",angle2,target2);
if(target1==0 && target2==0){
return;
}
else if(target1==0){
nMotorEncoderTarget[motorC] = target2; // set the target for Motor Encoder of Motor C
motor[motorC] = s2;
while(nMotorRunState[motorC] != runStateIdle){}
motor[motorC] = 0; // motor B is stopped at a power level of 0
}
else if(target2==0){
nMotorEncoderTarget[motorB] = target1; // set the target for Motor Encoder of Motor C
motor[motorB] = s1;
while(nMotorRunState[motorB] != runStateIdle){}
motor[motorB] = 0; // motor B is stopped at a power level of 0
}
else{
nMotorEncoderTarget[motorB] = target1; // set the target for Motor Encoder of Motor B
nMotorEncoderTarget[motorC] = target2; // set the target for Motor Encoder of Motor C
motor[motorB] = s1;
motor[motorC] = s2;

while(nMotorRunState[motorB] != runStateIdle || nMotorRunState[motorC] != runStateIdle){}
motor[motorB] = 0; // motor B is stopped at a power level of 0
motor[motorC] = 0; // motor C is stopped at a power level of 0
}
encoderBBegin = (arm1R*90) + nMotorEncoder[motorB];
encoderCBegin = (arm2R*180) + nMotorEncoder[motorC];

}

void ikinematics(int xx,int yy,float arm1,float arm2){ //function to calculate the angles required
float B = sqrt(pow(xx,2)+pow(yy,2));
float t = atan2(yy,xx);

float theta = (t-acos((pow(arm1,2)+pow(B,2)-pow(arm2,2))/(2*arm1*B)))*180/PI;
float alpha = (acos((pow(arm1,2)-pow(B,2)+pow(arm2,2))/(2*arm1*arm2)))*180/PI;
//move motor B and C to position
alpha=360-alpha;
nxtDisplayTextLine(6,"Target: %d x %d",xx,yy);
moveToAngle(theta,alpha);
}

Fri Sep 28, 2012 1:38 am
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 197
Re: Optimisation of moving an arm to a specific coordinate.
inverse kinematics, a real robotic goal, that is nice for a change.

neat. I see that scara robots can be purchased, the only price I saw was \$20,000 or so. So we want to make a NXT perform similar .... a robust goal indeed. (ie http://robots.epson.com/?googleppc)

I think you may need to scale the resolution down, by quite a bit - just a wild guess and I'd say \$20,000 vs \$250 - so probably around 100 to 1? i.e. 100 pixels = 1 pixel. At least as a starting point (start coarse; draw a box, build up detail when it starts working as expected).

If i understand correctly you need to move two arms, both somewhere around 112mm? quick math 1 degree at 112mm = around 2mm. so a slop of +/- 2 degrees would be about +/- 4mm (per arm)? that doesn't sound too bad for 1 arm, a little worse for 2 arms.

I have never done IK, but it does sound like a fun thing. Unfortunately I do not know if your formulas are correct. Can you at least add something to your code that prints the target encoder values, then again prints the actual values when the motors enter the idle state? it will give you an idea of how much it may have missed by. If they are not missing by much, then I would look more at the IK formulas.

I suspect you might end up having to write your own motor control PID to get more accuracy. The good news is you can probably develop that independently of this code so you can test and debug it fully before incorporating it into this code. You may want to look at the source for 'motor control' (http://www.mindstorms.rwth-aachen.de/tr ... torControl) to get an idea of what has to happen. there are several relevant links on that page as well. You may even be able to use motor control as is, although I never could get it to work.

You are into a detailed area of the NXT few have ventured, but it IS possible, it just needs some pioneering.

_________________
Mike aka Spiked3
http://www.spiked3.com

Fri Sep 28, 2012 11:10 am
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Re: Optimisation of moving an arm to a specific coordinate.
I am very sure my calculations are correct. It uses very simple algebra and some trigonometry.
At the moment, it can draw any picture with about 1cm accuracy. This is usually in the areas where the arm changes in direction so friction builds up between the paper and the pen. I have seen the NXT portrayed bot by Daniele Benedettelli and it is very impressive. However, the drawing area of my robot is larger so it will probably be less accurate. The robto is designed to draw on an A5 paper. The conclusion I've come up with is that I need a better method of controlling the motors, but I just don't know how.

Fri Sep 28, 2012 9:16 pm
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 197
Re: Optimisation of moving an arm to a specific coordinate.
good to know you are comfortable with your formulas - i'll bookmark them for when I get into IK eventually. In that case, I think the links I gave for motor control may be what you are needing. Let me know if you go down that path, I probably would like to join you if you do as it IS an area I'm interested in learning/improving in.

edit: I just looked at the Daniele Benedettelli portrayer - very cool. I would be interested in working on a project like that, if you are interested.

http://robotics.benedettelli.com/portrayer.htm for everyone else who has not seen it

_________________
Mike aka Spiked3
http://www.spiked3.com

Fri Sep 28, 2012 10:04 pm
Rookie

Joined: Thu Sep 13, 2012 9:43 am
Posts: 47
Re: Optimisation of moving an arm to a specific coordinate.
 brianchen11 wrote:I am very sure my calculations are correct. It uses very simple algebra and some trigonometry.At the moment, it can draw any picture with about 1cm accuracy. This is usually in the areas where the arm changes in direction so friction builds up between the paper and the pen. I have seen the NXT portrayed bot by Daniele Benedettelli and it is very impressive. However, the drawing area of my robot is larger so it will probably be less accurate. The robto is designed to draw on an A5 paper. The conclusion I've come up with is that I need a better method of controlling the motors, but I just don't know how.

I did wheelchair mounted robot arm at Uni (many years ago.) I used PID control for each joint's position and it worked pretty well so long as the sampling speed was fast enough. The PID algorithm was tuned with a PRBS (pseudo-random binary signal) input which was very quick and effective compared to other tuning methods. The PID algorithm was based on theory from Integrated Electrical and Electronic Engineering for Mechanical Engineers [Hardcover]
C.J. Fraser (Author), J.S. Milne (Author) which generally had a way of explaining stuff without being, well, full of it!

I didn't get as far as the inverse kinematics (which scared the hell out of me lol).

Wed Oct 10, 2012 6:25 am
Rookie

Joined: Tue Jul 03, 2012 5:16 am
Posts: 43
Re: Optimisation of moving an arm to a specific coordinate.
I haven't even gone to uni yet. Still have a lot to learn.

Sun Oct 21, 2012 3:08 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 6 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning