Braccio Robot & Pressure Sensor

Hello! I am working on a project for school that uses the Braccio robotic arm. We replaced the gripper on the end with our own design and added the SparkFun robotic finger sensor v2 (attached below). The issue we're having is that when we write the if statement (in void loop) for controlling the gripper servo positions based on pressure being applied to the object picking it up, it ignores the if statement when the Braccio library or any of the servos from the Braccio are called to move.

The pressure code with the two servos in the gripper works when it's in its own code.

The two servos in the gripper work with the Braccio simplemovements pre-written code.

It does not work when the if statement is written in and I have no idea why. Is someone able to help? I am fairly new to Arduino and am trying my best. I feel like I'm just missing something simple. Any help will be greatly appreciated. I attached the codes below.
Here is the sensor: Robotic Finger Sensor v2 - SPX-14687 - SparkFun Electronics

Pressure Code w/out Braccio: Works

#include <Servo.h>
#include <Wire.h> 
#include "SparkFun_LPS25HB_Arduino_Library.h" 
#include "SparkFun_VCNL4040_Arduino_Library.h"

LPS25HB pressureSensor; 
VCNL4040 proximitySensor; 

const int pressureThreshold = 415; 
const int proximityThreshold = 12000; 

// Initialize servo objects
Servo thumb;
Servo finger;

const int thumbMaxAngle = 80; 
const int thumbMinAngle = 0; 

const int fingerMaxAngle = 180; 
const int fingerMinAngle = 110; 


void setup() {
  // Attach servo motors to pins
  finger.attach(7);
  thumb.attach(4);
  
  // Set initial positions of servo motors
  
  finger.write(fingerMaxAngle); // Set to 90 degrees
  thumb.write(thumbMaxAngle); // Set to 90 degrees
  
  pressureSensor.begin();
  proximitySensor.begin();
 
  // Initialize serial communication
  Serial.begin(9600);
  Wire.begin();
  Wire.setClock(400000);
}

void loop() {

  // Read proximity sensor value
  int proximityValue = proximitySensor.getProximity();

  // Read pressure sensor value
  int pressureValue = pressureSensor.getPressure_hPa();

  // Check if both thresholds are met
  if (proximityValue < proximityThreshold && pressureValue < pressureThreshold) {
    // Decrease servo angles
    int currentAngle;

    // Decrease finger servo angle
    currentAngle = finger.read();
    if (currentAngle > fingerMinAngle) {
      finger.write(currentAngle - 2); // Decrease angle by 2 degrees
    }

    // Decrease thumb servo angle
    currentAngle = thumb.read();
    if (currentAngle > thumbMinAngle) {
      thumb.write(currentAngle - 3); // Decrease angle by 2 degrees
    }
  } 
  else {
    delay (2000); 
  thumb.write(thumbMaxAngle);
  finger.write(fingerMaxAngle); 
  }
  // Print sensor values (for debugging purposes)
  Serial.print("Proximity: ");
  Serial.print(proximityValue);
  Serial.print(" Pressure: ");
  Serial.println(pressureValue);

  delay(100); // Delay for stability
}

Braccio Arm Code w/ pressure code (supposed to turn the gripper servo motors): Does NOT work

#include <Wire.h>
#include <Braccio.h>
#include <Servo.h>
#include "SparkFun_LPS25HB_Arduino_Library.h" 
#include "SparkFun_VCNL4040_Arduino_Library.h"

LPS25HB pressureSensor; 
VCNL4040 proximitySensor; 

const int pressureThreshold = 415; 
const int proximityThreshold = 13000; 

Servo base;
Servo shoulder;
Servo elbow;
Servo wrist_rot;
Servo wrist_ver;
Servo gripper;

Servo thumb;
Servo finger;

const int thumbMaxAngle = 80; 
const int thumbMinAngle = 0; 

const int fingerMaxAngle = 180; 
const int fingerMinAngle = 110; 

void setup() {

     // Attach servo motors to pins
  finger.attach(7);
  thumb.attach(4);
  Braccio.begin();
  
  // Set initial positions of servo motors
  finger.write(fingerMaxAngle); // Set to 90 degrees
  thumb.write(thumbMaxAngle); // Set to 90 degrees

  pressureSensor.begin();
  proximitySensor.begin();
 
  // Initialize serial communication
  Serial.begin(9600);
  Wire.begin();
  Wire.setClock(400000);

  //Initialization functions and set up the initial position for Braccio
  //All the servo motors will be positioned in the "safety" position:
  //Base (M1):90 degrees
  //Shoulder (M2): 45 degrees
  //Elbow (M3): 180 degrees
  //Wrist vertical (M4): 180 degrees
  //Wrist rotation (M5): 90 degrees
  //gripper (M6): 10 degrees
  
}

void loop() {

  //BASE MOVES 
     Braccio.ServoMovement(20,     0,  95, 105, 90, 90,  10);  
  //Wait 1 second
  delay(1000);
  Braccio.ServoMovement(20,        180,  95, 105, 90, 90,  10);  
  delay(1000);

  // Read proximity sensor value
  int proximityValue = proximitySensor.getProximity();

  // Read pressure sensor value
  int pressureValue = pressureSensor.getPressure_hPa();

  // Check if both thresholds are met
  if (proximityValue < proximityThreshold && pressureValue < pressureThreshold) {
    // Decrease servo angles
    int currentAngle;

    // Decrease finger servo angle
    currentAngle = finger.read();
    if (currentAngle > fingerMinAngle) {
      finger.write(currentAngle - 2); // Decrease angle by 2 degrees
    }

    // Decrease thumb servo angle
    currentAngle = thumb.read();
    if (currentAngle > thumbMinAngle) {
      thumb.write(currentAngle - 3); // Decrease angle by 3 degrees
    }

    delay(1500); // Delay after servo movement

  } else {
    // Reset servos to max angles
    delay(2000); 
    
    //BASE MOVES 
     Braccio.ServoMovement(20,     0,  95, 105, 90, 90,  10);  
  //Wait 1 second
  delay(1000);
  Braccio.ServoMovement(20,        180,  95, 105, 90, 90,  10);  
  delay(1000);
  
    thumb.write(thumbMaxAngle);
    finger.write(fingerMaxAngle); 
    
    delay(1500); // Delay after servo movement
  }

  
  
  // Print sensor values (for debugging purposes)
  Serial.print("Proximity: ");
  Serial.print(proximityValue);
  Serial.print(" Pressure: ");
  Serial.println(pressureValue);

  delay(100); // Delay for stability
}

Braccio Simple Joint Movements w/ gripper servo motors (no pressure sensor): Works

#include <Braccio.h>
#include <Servo.h> 

Servo base;
Servo shoulder;
Servo elbow;
Servo wrist_rot; 
Servo wrist_ver;
Servo gripper;
Servo finger;
Servo thumb; 

int fingerOpen = 180;
int fingerclosed = 110; 

int thumbopen = 80;
int thumbclosed = 30; 

void setup()
{
   //starts stopped
  Serial.begin(9600); 
  pinMode(2, INPUT);
  finger.write(fingerOpen); 
  finger.attach(7);
  thumb.attach(4); 
   Braccio.begin(); 
}

void loop()
{
  
   //code you always run here; you can leave this section blank if you want the entire program to stop and start, or add code here if you want it to always run

   //check button press here and if it is pressed then toggle run variable between 0 and 255; REQUIRED!
finger.write(fingerOpen);
thumb.write(thumbopen); 
  
  if(digitalRead(2) == HIGH) //funcitons based off of button pulling input pin LOW
 {

finger.write(fingerOpen);
thumb.write(thumbopen);
delay(100);
finger.write(fingerclosed);
thumb.write(thumbclosed);
delay(2500); 
finger.write(fingerOpen);
thumb.write(thumbopen);
delay (1000);
  
   // the arm is aligned upwards  and the gripper is closed
                     //(step delay, M1, M2, M3, M4, M5, M6);
                   
//BASE MOVES 
     Braccio.ServoMovement(20,     0,  95, 105, 90, 90,  10);  
  //Wait 1 second
  delay(1000);
  Braccio.ServoMovement(20,        180,  95, 105, 90, 90,  10);  
  delay(1000);
   
//SHOULDER MOVES
  //Wait 1 second
  Braccio.ServoMovement(20,        180, 95,105,90,90,10);
  delay(1000); 
  Braccio.ServoMovement(20,        180, 120, 105, 90, 90,10); 
  delay(1000); 

//ELBOW MOVES
  Braccio.ServoMovement(20,        180, 95, 105, 90,90, 10);
  delay(1000);
  Braccio.ServoMovement(20,        180, 95, 150, 90, 90, 10);
  delay(1000);
  
//WRIST MOVES
  Braccio.ServoMovement(20,        180, 95, 105, 150, 90, 10);
  delay(1000);
  Braccio.ServoMovement(20,        180, 95, 105, 90, 90, 10);
  delay(1000);

//WRIST PITCH MOVES
  Braccio.ServoMovement(20,        180, 95, 105, 90, 0, 10);
  delay(1000);
  Braccio.ServoMovement(20,        180, 95, 105, 90, 90, 10);
  delay(1000);

//RETURN TO START
  Braccio.ServoMovement(20, 180, 95, 105, 90,90, 10);
  delay(1000);
  }
}

Your writing is unclear. What ever could "works when it is in its own code" mean?

The two servos in the gripper work with the Braccio simplemovements pre-written code.

This makes perfect sense, because you did not yet make a mess of the working code.

Here is how to fix whatever you have broken.

  1. What works?
  2. How is #1 to be used in the final project?
  3. What do you wish to be added to #1?
  1. I labeled next to each code which one works and which one doesn't.
  2. The first code is the code that runs our gripper and ensures its not crushing objects when it picks them up.
  3. I would like to add the movement of the Braccio arm into the first code. I have tried this and it does not work.

"works when its in its own code" means the pressure code w/out the braccio does what it is intended to do. It reads the pressure & proximity values and decreases the servos until the thresholds are met, waits 2 seconds and opens again.

I want to embed that code into a Braccio arm code but it does not work.

Try to avoid "it" unless you have one subject. You have three chunks of code in different states of functionality.

I understand that you have a Braccio arm that functions. Very good.
I understand that you have a touch sensor.
I understand that you have a proximity sensor.

My guess is that you want the reading from the proximity sensor to provide information in determining where to make the arm move to grip an object while reading the touch sensor for pressure on the object. Then do something for two seconds, then release the object, then probably move away.

Do you have the exact location of the object programmed in the working Braccio code?

Do you have the touch sensor working with just the gripper to measure pressure and close the grip until the pressure arrives at a maximum allowable threashold? Identify the minimal/least/smallest touch sensor code you need... that is to say, with only your Arduino and the pressure sensor, make the arduino "stop" when the maximum allowable pressure is achieved. It will be easier to fit into the servo code of the Braccio arm.

The proximity sensor only senses when "something" is within the programmed distance and will not distinguish among the target object, a surface or the arm itself. The proximity sensor will not "guide" the arm to a position.

There are products that might give "object identification" but those will be more work than a few servos and a pressure sensor. 1. ESP32-CAM 2. HUSKEY LENS

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.