Year 2 project, Robot Arm(week2)


Friday, February 8, 2019
Week 2:

As a pre-lab preparation, we had a deep research for some necessary library documents for programming the Arduino such as 'ps2x_lib.h' and servo.h'.

In the lab session, we connected all contral wires to there pins which allows us to test the motors. Meanwhile, our first problem appeared as the car can not move quickly because of the small friction between the wheels and the ground surface, the demonstrator asked us to add more weight on the car to increase the frction. Next we started with writing basic codes, the combination between the codes written by arm group and car group was a big problem and additionally we need to combine all codes to the ps2 controller. furthere more , the arm codes are not finished as there is some problems regarding the gripper because it was not working so we need to test the parameters by changing the code.


Video above illustrate the movement of the car




Codes to combine variables:
#include "PS2X_lib.h"
#include <Wire.h>
#include <Servo.h>

#define PS2_DAT        6
#define PS2_CMD        5
#define PS2_SEL        4
#define PS2_CLK        3

#define pressures   true
#define rumble      true

PS2X ps2x; .

int error = 0;
byte type = 0;
byte vibrate = 0;

int lx = 0;
int ly=  0;
int L_Speed = 0;
int R_Speed = 0;

Servo myservo1,myservo2,myservo3,myservo4;  // create servo object to control a servo
const int SERVOS = 4;

const int ACC = 10; // the accurancy of the potentiometer value before idle starts counting
int  value[SERVOS], idle[SERVOS], currentAngle[SERVOS], MIN[SERVOS], MAX[SERVOS], INITANGLE[SERVOS], previousAngle[SERVOS],ANA[SERVOS];

int Left_motor=8;
int Left_motor_pwm=9;

int Right_motor_pwm=10;
int Right_motor=11;


void setup(){
  Serial.begin(57600);

   myservo1.attach(2);
   myservo2.attach(7);
   myservo3.attach(12);
   myservo4.attach(13);


  pinMode( 8, OUTPUT);
  pinMode( 9, OUTPUT);
  pinMode( 10, OUTPUT);
  pinMode( 11, OUTPUT);
  stop();

  MIN[0] = 10;
  MAX[0] = 50;
 INITANGLE[0] = 30;



  MIN[1] = 10;
  MAX[1] = 140;
  INITANGLE[1] = 90;


  MIN[2] = 40;
  MAX[2] = 170;
  INITANGLE[2] = 90;


  MIN[3] = 0;
  MAX[3] = 170;
  INITANGLE[3] = 90;

Car coding

void forward()
{
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);

  digitalWrite(11, LOW);
  digitalWrite(10, HIGH);
}

void right()
{
   digitalWrite(8, LOW);
  digitalWrite(9, HIGH);

  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
}

void back()
{
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);

  digitalWrite(11, HIGH);
  digitalWrite(10, HIGH);
}

void left()
{
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);

  digitalWrite(11, LOW);
  digitalWrite(10, HIGH);
}

void stop()
{
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);

  digitalWrite(11, LOW);
  digitalWrite(10, LOW);
}

Ps2 controller coding :
Serial.print("Up held this hard: ");
      Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);
      forward();

    }else if(ps2x.ButtonReleased(PSB_PAD_UP))  {
        stop(); 
    }
    if(ps2x.Button(PSB_PAD_DOWN))
    {       
      Serial.print("DOWN held this hard: ");
      Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);
      back();
    }
    else if(ps2x.ButtonReleased(PSB_PAD_DOWN))
    {
        stop();
    }
    if(ps2x.Button(PSB_R1)){                     
      R_Speed = 0;           
    }
    if(ps2x.Button(PSB_L1)){                     
      L_Speed = 0;         
    }
    if(ps2x.Button(PSB_PAD_LEFT))
    {                     
      left();
    }else if(ps2x.ButtonReleased(PSB_PAD_LEFT))
    {
       stop();
    }
    if(ps2x.Button(PSB_PAD_RIGHT))
    {             
      Serial.println(ps2x.Analog(PSB_PAD_RIGHT));
        right();
    }
    else if(ps2x.ButtonReleased(PSB_PAD_RIGHT))
    {

      stop();
    }
    vibrate = ps2x.Analog(PSAB_CROSS);

    {

    }

Next week aim is to fix the gripper.



Comments

Popular posts from this blog

Year 2 project, robot arm(week1)

Year 2 project, Robot Arm(week3)