Pcom: Midterm Janken (Rock-Paper-Scissor) Robotic Hand – Tong Wu and Nick Wallace

  1. Final Presentation:

    Our midterm project, “Jaken Robotic Hand”, is an interactive installation that allows people to play “Rock-Paper-Scissors” with a robotic hand by wearing a glove with flex sensors attached on it.

  2. Process:

    (1) 3D printing Robotic Hand & Forearm

    To build the hand and the forearm of the robotic hand, we used the models from InMoov, an open source model library for 3D printed life-size robot. We used superglue and 3mm filaments to connect finger joints, 3d printed bolts to connect between the forearm and the hand, and used fishing lines and servos to control finger movements.

02-3DPrinting04-3DPrinting05-3DPrinting

07-Servos

 

           (2) Flex Sensitive Glove

               We designed a flex sensitive glove for this installation. There are two flex sensors, a “start the game” button, and a “throw” button, all sewed to a right-hand glove and connected to a Arduino Nano board, which has a nRF24L01 wireless transceiver that talks to the other same-kind transceiver from the robotic hand part.

               To play the game, player would put on the glove, press the “start the game” button, then press the “throw” button twice, and make a hand gesture indicating his/her choice of rock, paper or scissors.

RPS-player_bb

09-Sewing sensors and other components10-Sewing the glove

 

 

           (3) Robotic Hand & Forearm Assembly

12-Assembling the hand+forearm13-Assembling the hand+forearm

Arduino Code for both the player part and the robot part:


RPS-Player:

// include SPI and radio libs
#include 
#include 
#include 

// define flex sensor pins
#define sensorPointer A0
#define sensorPinkie A1

// define button pins
#define startButton 2
#define tapButton 3

// initialize button variables
int gameState = 0;
int lastGameState = 0;
int throwInput = 0;
int lastThrowInput = 0;
int throwCount = 0;
int computerStart = 4;
int playerChoice = 0;

// initialize radio and variables
RF24 radio(8, 9);
int msg[1];
const uint64_t pipe = 0xE8E8F0F0E1LL;

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

  // start radio transmitter on channel 115
  radio.begin();
  radio.setChannel(115);
  radio.openWritingPipe(pipe);
  radio.stopListening();

  // set sensor inputs
  pinMode(sensorPointer, INPUT);
  pinMode(sensorPinkie, INPUT);

  // set button inputs
  pinMode(startButton, INPUT);
  pinMode(tapButton, INPUT);

}

void loop() {
  // has the player triggered the game to start
  gameState = digitalRead(startButton);
  if (gameState == HIGH && lastGameState == LOW) {
    Serial.println("Game started!");

    // tell computer to start game
    msg[0] = computerStart;
    radio.write(msg, 1);
    Serial.println("Sent start game to computer");
    computerStart++;

    // wait till player throws 2 times
    while (throwCount != 2) {
      throwInput = digitalRead(tapButton);
      delay(100);
      
      // increase the count after each tap
      if (throwInput == HIGH) {
        throwCount++;
        Serial.print("Throw count: ");
        Serial.println(throwCount);

        // send update to computer
        msg[0] = computerStart++;
        radio.write(msg, 1);
        
        delay(100);
      }
    }
    delay(10);

    // reset throw variables
    throwCount = 0;
    computerStart = 4;
    
    // get user input
    userChoice();
    Serial.print("Player choice: ");
    Serial.println(playerChoice);
    Serial.println("paper = 1, scissors = 2, rock = 3");
    Serial.println();

    msg[0] = playerChoice;
    radio.write(msg, 1);
  }
  
  // reset game state
  lastGameState = gameState;
  
}

void userChoice() {
  // get player choice based on sensors
  int pinkieSensor = analogRead(sensorPinkie);
  pinkieSensor = map(pinkieSensor, 650, 460, 0, 100);   // map values 0-100
  Serial.print("Pinkie sensor: ");
  Serial.println(pinkieSensor);
  if ( pinkieSensor > 40) {   // finger is bent
    pinkieSensor = 1;
  } else {
    pinkieSensor = 0;
  }
  int pointerSensor = analogRead(sensorPointer);
  pointerSensor = map(pointerSensor, 550, 400, 0, 100);   // map values 0-100
  Serial.print("Pointer sensor: ");
  Serial.println(pointerSensor);
  if ( pointerSensor > 40) {  // finger is bent
    pointerSensor = 1;
  } else {
    pointerSensor = 0;
  }

  // no sensors flex = paper, pinkie flexed = scisors, both flexed = rock
  if (pinkieSensor == 1 && pointerSensor == 1) {    //rock
    playerChoice = 3;
  } else if (pinkieSensor == 1 & pointerSensor == 0) {   //scisors
    playerChoice = 2;
  } else {    // paper
    playerChoice = 1;
  }
}

————–
RPS-Computer

// include SPI, radio, and servo libs
#include 
#include 
#include 
#include 

// define servo finger pins
#define servoThumb 6
#define servoPointer 5
#define servoMiddle 4
#define servoRing 3
#define servoPinkie 2

// setup radio
RF24 radio(7, 8);

// initialize servo fingers
Servo thumbFinger, pointerFinger, middleFinger, ringFinger, pinkieFinger;

// initialize game variables
int aiChoice = 0;
int playerChoice = 0;

// initialize radio variables
int msg[1];
const uint64_t pipe = 0xE8E8F0F0E1LL;

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

  // attach the servos
  thumbFinger.attach(servoThumb);
  pointerFinger.attach(servoPointer);
  middleFinger.attach(servoMiddle);
  ringFinger.attach(servoRing);
  pinkieFinger.attach(servoPinkie);

  // set fingers straight
  thumbFinger.write(0);
  pointerFinger.write(0);
  middleFinger.write(0);
  ringFinger.write(0);
  pinkieFinger.write(0);

  // start the radio receiver on channel 115
  radio.begin();
  radio.setChannel(115);
  radio.openReadingPipe(1, pipe);
  radio.startListening();

  // generate seed for random function via floating pin
  randomSeed(analogRead(A2));
}

void loop() {

  // wait to receive start code from player
  while (msg[0] != 4) {
    radio.read(msg, 1);
    Serial.println("Waiting to start game...");
  }

  Serial.println();
  Serial.println("----------------------------------");
  Serial.println("Game started!");
  aiChoice = random(300); // generate psuedo-random number 0-300
  aiChoice = map(aiChoice, 0, 300, 1, 3);

  while (msg[0] != 5) {
    radio.read(msg, 1);
  }
  // count to one
  Serial.println("Moving fingers to 1...");
  pinkieFinger.write(180);
  ringFinger.write(180);
  middleFinger.write(180);
  thumbFinger.write(180);
  delay(100);

  while (msg[0] != 6) {
    radio.read(msg, 1);
  }
  // count to two
  Serial.println("Moving fingers to 2...");
  middleFinger.write(0);
  Serial.println();
  delay(100);

  // move robot hand per computer choice
  switch (aiChoice) {
    case 1:   // paper
      // leave all fingers open
      thumbFinger.write(180);
      pointerFinger.write(180);
      middleFinger.write(180);
      ringFinger.write(180);
      pinkieFinger.write(180);
      delay(200);
      Serial.println("Computer choice: paper");
      break;
    case 2:   // scissors
      // move thumb, ring, and pinkie fingers
      pinkieFinger.write(180);
      ringFinger.write(180);
      thumbFinger.write(180);
      delay(200);
      Serial.println("Computer choice: scissors");
      break;
    case 3:   // rock
      // move all fingers
      pinkieFinger.write(180);
      ringFinger.write(180);
      middleFinger.write(180);
      pointerFinger.write(180);
      thumbFinger.write(180);
      delay(200);
      Serial.println("Computer choice: rock");
      break;
  }
  Serial.println();

  // wait for choice from player
  while (msg[0] != 1 && msg[0] != 2 && msg[0] != 3) {
    radio.read(msg, 1);
    Serial.println("Waiting for player choice");
  }
  playerChoice = msg[0];
  Serial.println();
  Serial.print("Player choice: ");
  Serial.println(playerChoice);
  Serial.println("paper = 1, scissors = 2, rock = 3");
  Serial.println();

  // compare choices to see who wins
  if (playerChoice == aiChoice) {   // tie game
    // countdown code and throw again code here
    //break;
    Serial.println("Tie game!");

  } else {
    switch (aiChoice) {

      // computer chooses paper
      case 1:
        switch (playerChoice) {
          case 2: // player chooses scissors
            // player wins!
            Serial.println("Player wins!");
            // scissors cuts paper
            break;
          case 3: //player chooses rock
            // computer wins!
            Serial.println("Computer wins!");
            // paper wraps rock
            break;
        }
        break;

      // computer chooses scissors
      case 2:
        switch (playerChoice) {
          case 1: // player chooses paper
            // computer wins!
            Serial.println("Computer wins!");
            // scissors cuts paper
            break;
          case 3: // player chooses rock
            // player wins!
            Serial.println("Player wins!");
            // rock crushes scissors
            break;
        }
        break;

      // computer chooses rock
      case 3:
        switch (playerChoice) {
          case 1: // player chooses paper
            // player wins!
            Serial.println("Player wins!");
            // paper covers rock
            break;
          case 2: // player chooses scissors
            // computer wins!
            Serial.println("Computer wins!");
            // rock crushes scissors
            break;
        }
        break;
    }
  }
  Serial.println("----------------------------------");
  Serial.println();

  // reset game variables
  playerChoice = 0;
  aiChoice = 0;

  delay(200);
}
1 reply on “ Pcom: Midterm Janken (Rock-Paper-Scissor) Robotic Hand – Tong Wu and Nick Wallace ”
Leave a Reply

Your email address will not be published. Required fields are marked *