Skip to content

Instantly share code, notes, and snippets.

@rkrishnasanka
Forked from nro-bot/2013Oct11-robotarm.ino
Created November 26, 2013 05:52

Revisions

  1. @nouyang nouyang revised this gist Oct 15, 2013. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions 2013Oct11-robotarm.ino
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    Servo servo1;
    Servo servo2;
    float theta1; // target angles as determined through IK
    float theta1;
    float theta2;
    int pot1 = 0;
    int pot2 = 1;
    @@ -13,7 +13,6 @@ void setup() {
    servo2.attach(3,750,2200);
    servo1.write(90);
    servo2.write(90);
    pinMode(13,OUTPUT);
    }

    void loop() {
  2. @nouyang nouyang revised this gist Oct 15, 2013. 1 changed file with 2 additions and 4 deletions.
    6 changes: 2 additions & 4 deletions 2013Oct11-robotarm.ino
    Original file line number Diff line number Diff line change
    @@ -4,13 +4,11 @@ Servo servo1;
    Servo servo2;
    float theta1; // target angles as determined through IK
    float theta2;
    int theta1prev; //old targets for error correction
    int theta2prev;
    int pot1 = 0;
    int pot2 = 1;

    void setup() {
    Serial.begin(9600);
    // Serial.begin(9600);
    servo1.attach(2,750,2200);
    servo2.attach(3,750,2200);
    servo1.write(90);
    @@ -21,7 +19,7 @@ void setup() {
    void loop() {
    theta1 = analogRead(pot1);
    theta2 = analogRead(pot2);
    // Serial.print(theta1); Serial.print(","); Serial.println(theta2);
    // Serial.print(theta1); Serial.print(","); Serial.println(theta2);
    theta1 = -(theta1/1023)*220+200;
    theta2 = -(theta2/1023)*220+200;
    if(theta1 < 0) theta1 = 0;
  3. @nouyang nouyang revised this gist Oct 11, 2013. 1 changed file with 0 additions and 7 deletions.
    7 changes: 0 additions & 7 deletions 2013Oct11-robotarm.ino
    Original file line number Diff line number Diff line change
    @@ -2,26 +2,19 @@

    Servo servo1;
    Servo servo2;
    Servo servo3;
    float theta1; // target angles as determined through IK
    float theta2;
    int theta1prev; //old targets for error correction
    int theta2prev;
    int buf;
    int pot1 = 0;
    int pot2 = 1;
    unsigned long time; //time is really long!
    int writingposition = 140;
    int idleposition = 170;

    void setup() {
    Serial.begin(9600);
    servo1.attach(2,750,2200);
    servo2.attach(3,750,2200);
    //servo3.attach(2,500,2400);
    servo1.write(90);
    servo2.write(90);
    //servo3.write(idleposition);
    pinMode(13,OUTPUT);
    }

  4. @nouyang nouyang renamed this gist Oct 11, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @nouyang nouyang revised this gist Oct 11, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions 2013Oct11-robotarm
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    #include <Servo.h>

    Servo servo1;
    Servo servo2;
    Servo servo3;
  6. @nouyang nouyang created this gist Oct 11, 2013.
    45 changes: 45 additions & 0 deletions 2013Oct11-robotarm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #include <Servo.h>
    Servo servo1;
    Servo servo2;
    Servo servo3;
    float theta1; // target angles as determined through IK
    float theta2;
    int theta1prev; //old targets for error correction
    int theta2prev;
    int buf;
    int pot1 = 0;
    int pot2 = 1;
    unsigned long time; //time is really long!
    int writingposition = 140;
    int idleposition = 170;

    void setup() {
    Serial.begin(9600);
    servo1.attach(2,750,2200);
    servo2.attach(3,750,2200);
    //servo3.attach(2,500,2400);
    servo1.write(90);
    servo2.write(90);
    //servo3.write(idleposition);
    pinMode(13,OUTPUT);
    }

    void loop() {
    theta1 = analogRead(pot1);
    theta2 = analogRead(pot2);
    // Serial.print(theta1); Serial.print(","); Serial.println(theta2);
    theta1 = -(theta1/1023)*220+200;
    theta2 = -(theta2/1023)*220+200;
    if(theta1 < 0) theta1 = 0;
    if(theta2 < 0) theta2 = 0;
    if(theta1 > 180) theta1 = 180;
    if(theta2 > 180) theta2 = 180;
    drive_joints();
    }

    /* drive_joints() simply moves servos 1 and 2 */
    void drive_joints() {
    servo1.write(theta1);
    servo2.write(theta2);
    delay(30);
    }