This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 1 voto(s) - 3 Media
  • 1
  • 2
  • 3
  • 4
  • 5
CONSULTA Clasificación por peso con Braccio
#1
Hola tengo un problema. Tengo 2 sketch que funcionan bien por separado, pero no consigo hacer que funcionen bien juntos.  Estoy intentado clasificar piezas con un brazo robotico de arduino (Braccio) según su peso.  He hecho una bascula con arduino y peso las piezas y me da un valor correcto. Por otra parte consigo que el robot ponga las piezas en distintos cajones dependiendo del valor que le asigno a cada pieza. Pero no consigo hacer que el valor de cada pieza venga determinado por el peso de la balanza.
Os dejo los códigos de cada parte por separado y el que intento que funcione en común. 

Código de la balanza



Código:
//-------------------------------------------------------------------------------------

// HX711_ADC.h

// Arduino master library for HX711 24-Bit Analog-to-Digital Converter for Weigh Scales

// Olav Kallhovd sept2017

// Tested with      : HX711 asian module on channel A and YZC-133 3kg load cell

// Tested with MCU  : Arduino Nano

//-------------------------------------------------------------------------------------

// This is an example sketch on how to use this library

// Settling time (number of samples) and data filtering can be adjusted in the HX711_ADC.h file



#include <HX711_ADC.h>



//HX711 constructor (dout pin, sck pin)

HX711_ADC LoadCell(6, 7);



long t;



void setup() {

 Serial.begin(9600);

 Serial.println("Wait...");

 LoadCell.begin();

 long stabilisingtime = 2000; // tare preciscion can be improved by adding a few seconds of stabilising time

 LoadCell.start(stabilisingtime);

 LoadCell.setCalFactor(9000.0); // user set calibration factor (float)

 Serial.println("Startup + tare is complete");

}



void loop() {

 //update() should be called at least as often as HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS

 //longer delay in scetch will reduce effective sample rate (be carefull with delay() in loop)

 LoadCell.update();



 //get smoothed value from data set + current calibration factor

 if (millis() > t + 250) {

   float i = LoadCell.getData();

   Serial.print("Load_cell output val: ");

   Serial.println(i);

   t = millis();

 }



 //receive from serial terminal

 if (Serial.available() > 0) {

   float i;

   char inByte = Serial.read();

   if (inByte == 't') LoadCell.tareNoDelay();

 }



 //check if last tare operation is complete

 if (LoadCell.getTareStatus() == true) {

   Serial.println("Tare complete");

 }



}



Codigo Braccio


Código:
/*

 takethesponge.ino



This example commands to the Braccio to take a sponge from the table and it shows to the user



Created on 18 Nov 2015

by Andrea Martino



This example is in the public domain.

*/



#include <Braccio.h>

#include <Servo.h>





Servo base;

Servo shoulder;

Servo elbow;

Servo wrist_rot;

Servo wrist_ver;

Servo gripper;





void setup() {  

 //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

   Braccio.begin();

   Serial.begin(9600);



}



void loop (){

  /*

 Step Delay: a milliseconds delay between the movement of each servo.  Allowed values from 10 to 30 msec.

 M1=base degrees. Allowed values from 0 to 180 degrees

 M2=shoulder degrees. Allowed values from 15 to 165 degrees

 M3=elbow degrees. Allowed values from 0 to 180 degrees

 M4=wrist vertical degrees. Allowed values from 0 to 180 degrees

 M5=wrist rotation degrees. Allowed values from 0 to 180 degrees

 M6=gripper degrees. Allowed values from 10 to 73 degrees. 10: the toungue is open, 73: the gripper is closed.

 */

  //Starting position

                     //(step delay  M1 , M2 , M3 , M4 , M5 , M6);

 Braccio.ServoMovement(20,           0,  45, 180, 180,  90,  10);

 

 //Wait 2 second

 delay(1000);

 

 //The braccio moves to the sponge. Only the M2 servo will moves

 Braccio.ServoMovement(20,           0,  90, 180, 180,  90,   10);



 // wait 2 second

 delay(2000);

 //Close the gripper to take the sponge. Only the M6 servo will moves

 Braccio.ServoMovement(10,           0,  90, 180, 180,  90,  73 );



 //Brings the sponge upwards.

 Braccio.ServoMovement(20,         0,   45, 180,  180,  90, 70);



 //Show the sponge. Only the M1 servo will moves

 Braccio.ServoMovement(20,         90,  45, 180,  180,  90,  70);



 // Wait 1 second

 delay(1000);

 

 //Open the gripper

 Braccio.ServoMovement(20,         90,   45, 180,  180,  90, 10 );

 

 //Return to the start position.

 Braccio.ServoMovement(20,         0,   45, 180,  180,  90, 10);



 //Open the gripper

 Braccio.ServoMovement(20,         0,   45, 180,  180,  90, 10 );

 
}[size=undefined]



Y el que intento que sea el codigo para separar por peso.


Código:
/*

 takethesponge.ino



This example commands to the Braccio to take a sponge from the table and it shows to the user



Created on 18 Nov 2015

by Andrea Martino



This example is in the public domain.

*/



#include <Braccio.h>

#include <Servo.h>



#include <HX711_ADC.h>



//HX711 constructor (dout pin, sck pin)

HX711_ADC LoadCell(6, 7);



long t;

int pieza1=0;

float c;



Servo base;

Servo shoulder;

Servo elbow;

Servo wrist_rot;

Servo wrist_ver;

Servo gripper;





void setup() {  

 //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

   

 Serial.begin(9600);

 Serial.println("Wait...");

 LoadCell.begin();

 long stabilisingtime = 1000; // tare preciscion can be improved by adding a few seconds of stabilising time

 LoadCell.start(stabilisingtime);

 LoadCell.setCalFactor(9000.0); // user set calibration factor (float)

 Serial.println("Startup + tare is complete");

   

   Braccio.begin();

}







void loop (){

  /*

 Step Delay: a milliseconds delay between the movement of each servo.  Allowed values from 10 to 30 msec.

 M1=base degrees. Allowed values from 0 to 180 degrees

 M2=shoulder degrees. Allowed values from 15 to 165 degrees

 M3=elbow degrees. Allowed values from 0 to 180 degrees

 M4=wrist vertical degrees. Allowed values from 0 to 180 degrees

 M5=wrist rotation degrees. Allowed values from 0 to 180 degrees

 M6=gripper degrees. Allowed values from 10 to 73 degrees. 10: the toungue is open, 73: the gripper is closed.

 */

 LoadCell.update();



 //get smoothed value from data set + current calibration factor

 if (millis() > t + 250) {

   float c = LoadCell.getData();

   Serial.print("Load_cell output val: ");

   Serial.println©;

   t = millis();

 }

 

   if (c>175) pieza1=1;

   delay(2000);

  //Starting position

                     //(step delay  M1 , M2 , M3 , M4 , M5 , M6);

 Braccio.ServoMovement(20,           0,  45, 180, 180,  90,  10);

 

 //Wait 2 second

 delay(1000);

 

   if (pieza1=1)

   {

   //The braccio moves to the sponge. Only the M2 servo will moves

 Braccio.ServoMovement(20,           0,  90, 180, 180,  90,   10);



 // wait 2 second

 delay(2000);

 

 //Close the gripper to take the sponge. Only the M6 servo will moves

 Braccio.ServoMovement(10,           0,  90, 180, 180,  90,  73 );



 //Brings the sponge upwards.

 Braccio.ServoMovement(20,         0,   45, 180,  180,  90, 70);



 //Show the sponge. Only the M1 servo will moves

 Braccio.ServoMovement(20,         90,  45, 180,  180,  90,  70);



 // Wait 1 second

 delay(1000);

 

 //Open the gripper

 Braccio.ServoMovement(20,         90,   45, 180,  180,  90, 10 );

 

 //Return to the start position.

 Braccio.ServoMovement(20,         0,   45, 180,  180,  90, 10);



 //Open the gripper

 Braccio.ServoMovement(20,         0,   45, 180,  180,  90, 10 );}

 

 

  if (pieza1=0)

   {

   //The braccio moves to the sponge. Only the M2 servo will moves

 Braccio.ServoMovement(20,           0,  90, 180, 180,  90,   10);



 // wait 2 second

 delay(2000);

 

 //Close the gripper to take the sponge. Only the M6 servo will moves

 Braccio.ServoMovement(10,           0,  90, 180, 180,  90,  73 );



 //Brings the sponge upwards.

 Braccio.ServoMovement(20,         0,   45, 180,  180,  90, 70);



 //Show the sponge. Only the M1 servo will moves

 Braccio.ServoMovement(20,         90,  45, 180,  180,  90,  70);



 // Wait 1 second

 delay(1000);

 

 //Open the gripper

 Braccio.ServoMovement(20,        120,   45, 180,  180,  90, 10 );

 

 //Return to the start position.

 Braccio.ServoMovement(20,         0,   45, 180,  180,  90, 10);



 //Open the gripper

 Braccio.ServoMovement(20,         0,   45, 180,  180,  90, 10 );}

 

 

 
}[size=undefined]


Mi problema es que la bascula no me da lecturas de peso correctas, entra como en un bucle en el que se va incrementando el peso de forma constante.

A ver si alguien me puede ayudar. Gracias[/size]
[/size]
  Responder
#2
Cita: //get smoothed value from data set + current calibration factor

if (millis() > t + 250) {

float c = LoadCell.getData();

Serial.print("Load_cell output val: ");

Serial.println©;

t = millis();

}

La verdad es que es un código un poco largo para analizar así... Pero vamos a intentarlo. Arregla ese println para que te.muestre el valor de C y mira el puerto serie a ver si está leyendo bien.

Cita:if (c>175) pieza1=1;

delay(2000);

//Starting position

//(step delay M1 , M2 , M3 , M4 , M5 , M6);

Braccio.ServoMovement(20, 0, 45, 180, 180, 90, 10);



//Wait 2 second

delay(1000);

No veo los { } de ese if...olvídalo está bien, me he liado, conviene poner los corchetes siempre y tabular bien para que se lea más claro (alt + t creo que te lo hace auto).


La variable pieza1, la defines como variable global y l pones a 0 al principio del programa.
Pero una vez entras en el loop, no veo que la resetees en ningún sitio, una vez que se ponga a 1, siempre será 1.
Al final del if(pieza1==1) deberías resetear, pieza1=0;
  Responder