mrRobot
Published © GPL3+

Line follower Robot [calliope mini]

2 Motoren + 1 Fahrgestell + 2 Infrarotsensoren + 1 Calliope mini = selbstfahrender, einer weißen Linie folgender Roboter

IntermediateFull instructions provided5 hours950
Line follower Robot [calliope mini]

Things used in this project

Hardware components

Calliope mini
Calliope mini
×1
Laqiya 2WD Smart Roboter Auto Chassis Kit
Hier funktioniert natürlich jedes Chassis mit zwei 4,5V Motoren.
×1
IR Sensor Module
×2

Story

Read more

Schematics

lineFollower - Verschaltung

Code

lineFollower

Typescript
MakeCode
let vmax = 0
let fCalib = 0
let go = 0
let mright_before = 0
let mleft_before = 0
let irright = 0
let mright = 0
let irleft = 0
let fConfig = 0
let mleft = 0

input.onButtonPressed(Button.A, () => {
  mleft = 0
  mright = 0
  mleft_before = 0
  mright_before = 0
  if (go == 0) {
    go = 1
    fCalib = 0
    basic.showIcon(IconNames.Happy)
  } else {
    go = 0
    fCalib = 0
    motors.motorCommand(MotorCommand.Coast)
    motors.dualMotorPower(Motor.AB, 0)
  }
})

input.onButtonPressed(Button.B, () => {
  mleft = 0
  mright = 0
  mleft_before = 0
  mright_before = 0
 if (fCalib == 0) {
    fCalib = 1
    go = 0
  } else {
    fCalib = 0
    go = 0
  }
  motors.motorCommand(MotorCommand.Coast)
  motors.dualMotorPower(Motor.AB, 0)
})

fConfig = 0
mleft = 0
mright = 0
mleft_before = 0
mright_before = 0
irleft = 0
irright = 0
fCalib = 0
go = 0
vmax = 50
pins.setPull(DigitalPin.P0, PinPullMode.PullUp)
pins.setPull(DigitalPin.C19, PinPullMode.PullUp)

basic.forever(() => {
  irleft = pins.digitalReadPin(DigitalPin.P0)
  irright = pins.digitalReadPin(DigitalPin.C19)
  
  if (go == 1) {
    if (irleft == 1 && irright == 1) {
      mleft = vmax
      mright = vmax
    } else if (irleft == 0 && irright == 1) {
      mleft = 0
      mright = vmax
    } else if (irleft == 1 && irright == 0) {
      mleft = vmax
      mright = 0
    } else {
      mleft = 0
      mright = 0
    }
  } else if (fCalib == 1) {
    if (irleft == 1 && irright == 1) {
      basic.showArrow(ArrowNames.North)
    } else if (irleft == 0 && irright == 1) {
      basic.showArrow(ArrowNames.West)
    } else if (irleft == 1 && irright == 0) {
      basic.showArrow(ArrowNames.East)
    } else {
      basic.showIcon(IconNames.No)
    }
  } else {
    basic.showIcon(IconNames.Yes)
  }
  
  if (mleft != mleft_before || mright != mright_before) {
    motors.dualMotorPower(Motor.A, mleft)
    motors.dualMotorPower(Motor.B, mright)
  }
  mleft_before = mleft
  mright_before = mright
})

Credits

mrRobot

mrRobot

1 project • 2 followers

Comments