View unanswered posts | View active topics It is currently Sat Oct 31, 2020 6:31 pm

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
robotic arm with 2 degrees of freedom must draw a line
Author Message
Rookie

Joined: Mon Mar 10, 2014 7:57 pm
Posts: 3
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  }}

Mon Mar 10, 2014 8:12 pm
Professor

Joined: Sat Aug 31, 2013 9:15 am
Posts: 256
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://bluechariotsoffire.com/.

Mon Mar 10, 2014 9:58 pm
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Rookie

Joined: Mon Mar 10, 2014 7:57 pm
Posts: 3
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.

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

Tue Mar 11, 2014 3:18 pm
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 5 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