View unanswered posts | View active topics It is currently Mon Oct 20, 2014 6:51 pm






Reply to topic  [ 5 posts ] 
robotic arm with 2 degrees of freedom must draw a line 
Author Message
Rookie

Joined: Mon Mar 10, 2014 7:57 pm
Posts: 3
Post robotic arm with 2 degrees of freedom must draw a line
Hello everyone,

i am new in this forum and i recently registered because i need help with a task.
As the title says, i have this robotic arm and i want it to draw a straight line but i cannot figure out how to do it. I am using the Robot C to do this and this is the code i am working on so far but it seems so wrong.

Code:
task main()
{
  int i;
  for (i=0; i<50; i++)
  {
      nMotorEncoder[motorA] = 0;                // Reset the Motor Encoder of Motor A.
     nMotorEncoderTarget[motorA] = 8;        // Set the  target for Motor Encoder of Motor A to 360.
     motor[motorA] = -100;                       // Motor A is run at a power level of 75.
     while(nMotorRunState[motorA] != runStateIdle && nMotorRunState[motorB] != runStateIdle)
      // While Motor A is still running (haven't yet reached their target):
      {
        // Do not continue.
      }
      motor[motorA] = 0;                       // Motor A is stopped at a power level of 0.

      //--------------------------------------------------------------------------------------------------------------

      nMotorEncoder[motorB] = 0;                // Reset the Motor Encoder of Motor B.
      nMotorEncoderTarget[motorB] = 8;        // Set the  target for Motor Encoder of Motor B to 360.
      motor[motorB] = -100;                       // Motor B is run at a power level of 75.
      while(nMotorRunState[motorB] != runStateIdle)
      // While Motor B is still running (haven't yet reached their target):
      {
        // Do not continue.
      }
      motor[motorB] = 0;                       // Motor B is stopped at a power level of 0.

      wait1Msec(500);       //the program waits 4000 milliseconds before running further code
  }
}


Image


Mon Mar 10, 2014 8:12 pm
Profile
Expert
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 136
Post Re: robotic arm with 2 degrees of freedom must draw a line
With your code, you won't get a perfectly straight line. What you're doing right now is moving one motor a little bit, the other motor a little bit, and so on for 50 iterations. Is that what it's supposed to be doing? Or, if both motors running simultaneously is what you're going for, you'll need a slight reconfiguration of your code.

_________________
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
FTC Team 7468 Blue Chariots of Fire - Mentor (2014-2015)
Check out our team website at http://cof7468.weebly.com/.


Mon Mar 10, 2014 9:58 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: robotic arm with 2 degrees of freedom must draw a line
By the look of your setup and simple trigonometry, it should draw a straight line if both motors are turning at the same rate. So you should be able to use the "Sync motor" feature of RobotC to achieve that. Please watch this video for how to do that.
http://www.education.rec.ri.cmu.edu/pre ... inth8.html


Tue Mar 11, 2014 3:55 am
Profile
Rookie

Joined: Mon Mar 10, 2014 7:57 pm
Posts: 3
Post Re: robotic arm with 2 degrees of freedom must draw a line
i have corrected my code as much as i could and i managed to make the arm draw a straight line.

here is a video. https://www.youtube.com/watch?v=1M53Y45ZiUY

could someone tell me how i could make this arm draw a square?

Code:
task main()
{
  int i;
  for (i=0; i<22; i++)
  {
      nMotorEncoder[motorA] = 0;                // Reset the Motor Encoder of Motor A.
     nMotorEncoderTarget[motorA] = 3;        // Set the  target for Motor Encoder of Motor A to 3.
     motor[motorA] = 5;                       // Motor A is run at a power level of 5.

     nMotorEncoder[motorB] = 0;                // Reset the Motor Encoder of Motor B.
      nMotorEncoderTarget[motorB] = 7;        // Set the  target for Motor Encoder of Motor B to 7.
      motor[motorB] = 5;                       // Motor B is run at a power level of 5.

      while(nMotorRunState[motorA] != runStateIdle && nMotorRunState[motorB] != runStateIdle && nMotorRunState[motorB] != runStateIdle)
      // While Motor A is still running (haven't yet reached their target):
      {
        // Do not continue.
      }

  }
}


Image


Tue Mar 11, 2014 3:18 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: robotic arm with 2 degrees of freedom must draw a line
Your code doesn't really draw a straight line. Notice it curved upward towards the left end. It is because the two motors are running at slightly different rates probably because towards the end, the shoulder motor has higher load than the elbow motor. If you use the Synchronized motors feature of RobotC, you will probably draw a better straight line. If you are going to have the robot draw different shapes, you are better off modularizing the code. For example, write code for the following functions:
void MoveTo(int x, int y)
void DrawLine(int x1, int y1, int x2, int y2)
Since I don't know what level you are at, I don't know if I should assume you know trigonometry well enough. This involves simple trigonometry. Basically, the arm forms an isosceles triangle. Assuming the length of each segment of the arm is L (i.e. length from shoulder to elbow and length from elbow to pen). To make things simpler, let's assume when the arm is completely collapsed (i.e. the pen is closest to the base of the shoulder motor), that's your home position (0, 0). Going to a coordinate (x, y), the arm will form an isosceles triangle with two equal sides of length L, the length of the line will be the base of the triangle B = sqrt(x*x + y*y). The angle the shoulder has to turn is Ashoulder = atan(y/x). The angle the elbow has to turn is Aelbow = asin(B/2/L)*2.
Once you use these formulae to implement MoveTo, there are two ways to implement DrawLine. One is to incrementally calculate the coordinates along the line between (x1, y1) and (x2, y2) and calling the MoveTo function drawing many small line segments. The other way is to actually calculate the motor turn rates for the shoulder and elbow so you can draw a straight line from (x1, y1) to (x2, y2) changing the motor rate along the way. This is more complex (and more math) than the "calling MoveTo" method.


Tue Mar 11, 2014 5:04 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.