Small two-wheel differential chassis realizes cliff inspection function

1. Function description

      The example in this article will implement the cliff inspection function of the small two-wheel differential chassis of the R023 prototype. A detection device is installed on a small two-wheel differential chassis, which can be composed of a  near-infrared sensor  and a grayscale sensor . The near-infrared sensor can identify the desktop, and the grayscale sensor can identify the "cliff", allowing the robot to patrol along the "cliff" without moving away or falling.

2. Electronic hardware

In this example, we use the following hardware, please refer to it:

Main control board

Basra main control board (compatible with Arduino Uno )

expanding board

Bigfish2.1 expansion board‍

sensor

near infrared sensor

Grayscale sensor

Battery 7.4V lithium battery

Circuit connection:

      ① The near-infrared sensor is connected to the A0 port of the Bigfish expansion board; the grayscale sensor is connected to the A4 port of the Bigfish expansion board.

      ② The two DC motors are connected to interfaces 9 and 10 and interfaces 5 and 6 of the Bigfish expansion board respectively.

3. Function implementation

Programming environment: Arduino 1.8.19

The following provides a reference routine for cliff inspection of a small two-wheel differential chassis (Cliff_avoidance_robot.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-07-19 https://www.robotway.com/
  ------------------------------*/
/*************************************************************************************************************************************************
实验需求:
实现悬崖巡检机器人
实现思路:
程序的整体思路为:用近红外来检测停放小车的桌面,用灰度来检测悬崖。
当近红外持续触发时,说明小车在桌面,小车保持前进,如果灰度传感器触发,说明小车遇到悬崖,
小车先后退350毫秒,在左转350毫秒远离悬崖。如果近红外没有触发,说明小车也检测到了悬崖。否则,小车前进。
*************************************************************************************************************************************************/


/******************************************************************
实验接线:
近红外传感器接到A0(即14引脚);
灰度传感器接到A4(即18引脚);
直流电机1接5,6引脚;
直流电机2接9,10引脚;
******************************************************************/

int _ABVAR_1_Near_infrared_sensor = 0 ;
int _ABVAR_2_Grayscale_sensor = 0 ;
boolean __ardublockDigitalRead(int pinNumber)
{
  pinMode(pinNumber, INPUT);
  return digitalRead(pinNumber);
}



void forward();
void back();
void Cliff();
void left();

void setup()
{
  pinMode( 10, OUTPUT);
  pinMode( 6, OUTPUT);
  pinMode( 5, OUTPUT);
  pinMode( 9, OUTPUT);
  _ABVAR_1_Near_infrared_sensor = 14 ;

  _ABVAR_2_Grayscale_sensor = 18 ;

}

void loop()
{
  if (__ardublockDigitalRead(_ABVAR_1_Near_infrared_sensor))
  {
    Cliff();   //如果近红外没有触发,说明小车检测到了悬崖。
  }
  if (!( __ardublockDigitalRead(_ABVAR_2_Grayscale_sensor) ))
  {
    Cliff();   //如果灰度传感器触发,说明小车遇到悬崖,小车先后退350毫秒,在左转350毫秒远离悬崖。
  }
  else
  {
    forward();
  }
}

void back()
{
  analogWrite(5 , 0);
  analogWrite(6 , 100);
  analogWrite(9 , 0);
  analogWrite(10 , 100);
}

void forward()
{
  analogWrite(5 , 100);
  analogWrite(6 , 0);
  analogWrite(9 , 80);
  analogWrite(10 , 0);
}

void Cliff()
{
  back();
  delay( 350 );
  left();
  delay( 350 );
}

void left()
{
  analogWrite(5 , 100);
  analogWrite(6 , 0);
  analogWrite(9 , 0);
  analogWrite(10 , 100);
}


 Cliff Inspection - For details of the program source code, see Small Two-wheel Differential Chassis - Cliff Inspection

Guess you like

Origin blog.csdn.net/Robotway/article/details/132394135