Small two-wheel differential chassis robot realizes wireless remote control function

1. Function description

      The functions implemented in the example of this article are: using  the Explorer Birdmen handle expansion board and the Explorer NRF wireless communication module to remotely control the R023 prototype small two-wheel differential chassis to make forward, backward and steering movements.

 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) x2

expanding board

Bigfish2.1 expansion board x1

Birdmen handle expansion board x1

communication

NRF wireless communication module x2

Battery 7.4V lithium battery

3. Function implementation

      Programming environment: Arduino 1.8.19

3.1 Download firmware

      Download master_.ino and slave_.ino to two Basra main control boards respectively (software analysis: master_.ino is the upper computer program, slave_.ino is the lower computer program).

      Note: Do not stack NRF wireless communication modules first, because it will occupy the serial port and cause download failure.

① Reference routine (master_.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-21 https://www.robotway.com/

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

int _ABVAR_1_A0Value = 0 ;

int _ABVAR_2_A1Value = 0 ;

void ADGet();

void SerialPrint();

void setup()

{

  Serial.begin(9600);

}

void loop()

{

  ADGet();

  SerialPrint();

  delay( 100 );

}

void SerialPrint()

{

  if (( ( ( _ABVAR_1_A0Value ) == ( 0 ) ) && ( ( _ABVAR_2_A1Value ) == ( 1 ) ) ))

  {

    Serial.print("1");

    Serial.println();

  }

  if (( ( ( _ABVAR_1_A0Value ) == ( 1 ) ) && ( ( _ABVAR_2_A1Value ) == ( 0 ) ) ))

  {

    Serial.print("2");

    Serial.println();

  }

  if (( ( ( _ABVAR_1_A0Value ) == ( 1 ) ) && ( ( _ABVAR_2_A1Value ) == ( 1 ) ) ))

  {

    Serial.print("3");

    Serial.println();

  }

  if (( ( ( _ABVAR_1_A0Value ) == ( 1 ) ) && ( ( _ABVAR_2_A1Value ) == ( 2 ) ) ))

  {

    Serial.print("4");

    Serial.println();

  }

  if (( ( ( _ABVAR_1_A0Value ) == ( 2 ) ) && ( ( _ABVAR_2_A1Value ) == ( 1 ) ) ))

  {

    Serial.print("5");

    Serial.println();

  }

}

void ADGet()

{

  _ABVAR_1_A0Value = analogRead(14) ;

  _ABVAR_2_A1Value = analogRead(15) ;

  _ABVAR_1_A0Value = map ( _ABVAR_1_A0Value , 0 , 1024 , 0 , 3 )   ;

  _ABVAR_2_A1Value = map ( _ABVAR_2_A1Value , 0 , 1024 , 0 , 3 )   ;

}

② Reference routine (slave_.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-21 https://www.robotway.com/

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

int _ABVAR_1__data = 0 ;

int _ABVAR_2__data_his = 0 ;

int _ABVAR_3_0 = 0 ;

void Right();

void Select();

void Left();

void Stop();

void Forward();

void Back();

void setup()

{

  Serial.begin(9600);

  pinMode( 5 , OUTPUT);

  pinMode( 6 , OUTPUT);

  pinMode( 9 , OUTPUT);

  pinMode( 10 , OUTPUT);

  _ABVAR_1__data = 3 ;

  _ABVAR_2__data_his = 3 ;

}

void loop()

{

  _ABVAR_1__data = Serial.parseInt() ;

  if (( ( _ABVAR_1__data ) > ( 0 ) ))

  {

    Select();

  }

  else

  {

    _ABVAR_1__data = _ABVAR_2__data_his ;

    Select();

  }

  _ABVAR_2__data_his = _ABVAR_1__data ;

  _ABVAR_1__data = _ABVAR_3_0 ;

  delay( 50 );

}

void Left()

{

  digitalWrite( 5 , LOW );

  digitalWrite( 6 , HIGH );

  digitalWrite( 9 , HIGH );

  digitalWrite( 10 , LOW );

}

void Stop()

{

  digitalWrite( 5 , LOW );

  digitalWrite( 6 , LOW );

  digitalWrite( 9 , LOW );

  digitalWrite( 10 , LOW );

}

void Back()

{

  digitalWrite( 5 , LOW );

  digitalWrite( 6 , HIGH );

  digitalWrite( 9 , LOW );

  digitalWrite( 10 , HIGH );

}

void Forward()

{

  digitalWrite( 5 , HIGH );

  digitalWrite( 6 , LOW );

  digitalWrite( 9 , HIGH );

  digitalWrite( 10 , LOW );

}

void Select()

{

  if (( ( _ABVAR_1__data ) == ( 1 ) ))

  {

    Forward();

  }

  if (( ( _ABVAR_1__data ) == ( 2 ) ))

  {

    Back();

  }

  if (( ( _ABVAR_1__data ) == ( 3 ) ))

  {

    Stop();

  }

  if (( ( _ABVAR_1__data ) == ( 4 ) ))

  {

    Left();

  }

  if (( ( _ABVAR_1__data ) == ( 5 ) ))

  {

    Right();

  }

}

void Right()

{

  digitalWrite( 5 , HIGH );

  digitalWrite( 6 , LOW );

  digitalWrite( 9 , LOW );

  digitalWrite( 10 , HIGH );

}

3.2 Hardware connection

     ① Stack the Birdmen handle expansion board onto the Basra main control board with master_.ino downloaded, and then stack the NRF wireless communication module.

     ② Stack the Bigfish expansion board onto the Basra main control board with slave_.ino downloaded, and then stack the NRF wireless communication module.

③ Connect the DC motor of the small two-wheel differential chassis to the motor interface of the Bigfish expansion board.

④ Use the joystick on the right side of the master to remotely control the slave, and adjust the wiring of the motor until the movement of the joystick matches the movement of the car.

For details on program source code download, please see Small Two-Wheel Differential Chassis-Wireless Remote Control

Guess you like

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