5自由度串联机械臂实现颜色分拣功能

1. 功能描述

      本文提供的示例所实现的功能为:实现5自由度串联机械臂按颜色分拣的功能。将红、蓝两种颜色的工件分别放置在传感器上时,机械臂会根据检测到的颜色,将红色工件搬运至右侧区域;将蓝色工件搬运至左侧区域。

2. 电子硬件

在这个示例中,我们采用了以下硬件,请大家参考:

主控板

Basra主控板(兼容Arduino Uno)‍

扩展板

Bigfish2.1扩展板‍

传感器

TCS3200颜色识别传感器

电池 7.4V锂电池

在5自由度串联机械臂底座上安装一个 TCS3200颜色识别传感器 ,用于检测工件的RGB值。

3. 功能实现

编程环境:Arduino 1.8.19

下面提供一个实现5自由度串联机械臂按颜色分拣的参考程序(colour.ino):

/*------------------------------------------------------------------------------------

  版权说明:Copyright 2023 Robottime(Beijing) Technology Co., Ltd. All Rights Reserved.

           Distributed under MIT license.See file LICENSE for detail or copy at

           https://opensource.org/licenses/MIT

           by 机器谱 2023-08-24 https://www.robotway.com/

  ------------------------------*/

#include 

#include 

#include 

ECT_IA02S device;

String serialString = "";

boolean serialComplete = false;

char stringBuf[100];

void setup()

{

  Serial.begin(9600);

  Colour_set();

  serialString = "1@0:act.write(75);@";

  StringDeal();

  serialString = "1@1:act.write(90);@";

  StringDeal();

  delay(1000);

  serialString = "2@0:act.write(100);@";

  StringDeal();

  serialString = "2@1:act.write(90);@";

  StringDeal();  

  delay(1000);

  serialString = "3@0:act.write(45);@";

  StringDeal();

  serialString = "3@1:act.write(90);@";

  StringDeal();

}

void loop()

{

  int c = Get_colour();

  Serial.println(c);

  if(c<2)

     device.startShoal(0, c, 7000);

  delay(2000);

}

void StringDeal()

{

      String outString;

      static int stringlength;

      serialString = serialString.substring(0,serialString.length()-1);

      serialString+="*";

      serialString+=serialString.length()-1;

      serialString+="\n";

      stringlength=serialString.length();

     

     

      //split the string to certain part, each part as 30 char, send parts one by one

      for(int i=0;i<((stringlength/30)+1);i++){

        outString = serialString.substring(0,min(serialString.length(),30));

        outString.toCharArray(stringBuf, outString.length()+1);

        serialString=serialString.substring(min(serialString.length(),30),serialString.length()+1);

     

        Wire.beginTransmission(1);

        Wire.write(stringBuf);                   

        Wire.endTransmission();       

      }

}


颜色分拣-程序源代码资料内容详见 5自由度串联机械臂-颜色分拣

你可能感兴趣的:(机器人)