リモコン移動作業ロボット:ソースコード:WheelSupport.cpp

//copyryght 2024- https://robot-creation-diary.com/

#include "WheelSupport.h"

CWheelSupport::CWheelSupport(){
    // put your setup code here, to run once:
  pinMode(L_MOTOR_FORWARD_PIN, OUTPUT);
  pinMode(L_MOTOR_BACK_PIN, OUTPUT);
  Stop(L_MOTOR_FORWARD_PIN, L_MOTOR_BACK_PIN);
  pinMode(R_MOTOR_FORWARD_PIN, OUTPUT);
  pinMode(R_MOTOR_BACK_PIN, OUTPUT);
  Stop(R_MOTOR_FORWARD_PIN, R_MOTOR_BACK_PIN);

  //信号線に電力を送る
  pinMode(SIGNAL_POWER_PIN, OUTPUT);
  digitalWrite(SIGNAL_POWER_PIN, HIGH);  

}

CWheelSupport::~CWheelSupport(){
}
 void CWheelSupport::SetWheelData(int l_wheel, int r_wheel){
  if(50 < l_wheel){
    CWheelSupport::Forward(L_MOTOR_FORWARD_PIN,L_MOTOR_BACK_PIN);
  }else if (l_wheel < -50){
      CWheelSupport::Back(L_MOTOR_FORWARD_PIN,L_MOTOR_BACK_PIN);
  }else{
      CWheelSupport::Stop(L_MOTOR_FORWARD_PIN,L_MOTOR_BACK_PIN);
  }
  if(50 < r_wheel){
    CWheelSupport::Forward(R_MOTOR_FORWARD_PIN,R_MOTOR_BACK_PIN);
  }else if (r_wheel < -50){
      CWheelSupport::Back(R_MOTOR_FORWARD_PIN,R_MOTOR_BACK_PIN);
  }else{
      CWheelSupport::Stop(R_MOTOR_FORWARD_PIN,R_MOTOR_BACK_PIN);
  }
 }


void CWheelSupport::Forward(uint8_t forward_pin, uint8_t back_pin){
  digitalWrite(forward_pin, HIGH);
  digitalWrite(back_pin, LOW);
}
void CWheelSupport::Back(uint8_t forward_pin, uint8_t back_pin){
  digitalWrite(back_pin , HIGH);
  digitalWrite(forward_pin, LOW);
}
void CWheelSupport::Stop(uint8_t forward_pin, uint8_t back_pin){
  digitalWrite(forward_pin, LOW);
  digitalWrite(back_pin, LOW);
}
void CWheelSupport::TurnRigh(){
  digitalWrite(L_MOTOR_FORWARD_PIN , HIGH);
  digitalWrite(R_MOTOR_BACK_PIN , HIGH);
}
void CWheelSupport::TurnLeft(){
  digitalWrite(R_MOTOR_FORWARD_PIN , HIGH);
  digitalWrite(L_MOTOR_BACK_PIN , HIGH);
}