Go Down

Topic: Both motors are not working properly  (Read 328 times) previous topic - next topic

Karabet

Hi Guy's,

I need your help Im trying to run 2 DC motors (24VDC, 500Watt output) which is connected to Sabretooth motor driver 2x60Amp and via a serial connected to Arduino and im using HUSKYLENS AI camera connected to Arduino via "mySerial(10, 11)" as you can see in attached code Im reading the correct values if I let the camera recognize and learn certain color like red for example so in serial monitor I could see when I move the color to write or left or forward all is okay but the motors don't correspond with that can you help please?

The code (The camera part its from the internet and the motor part is a example from Sabertooth Arduino library and examples):

#include "HUSKYLENS.h"
#include "SoftwareSerial.h"
#include "SabertoothSimplified.h"
 SabertoothSimplified ST;
 //int stop = 0;
 HUSKYLENS huskylens;
 SoftwareSerial mySerial(10, 11);

void printResult(HUSKYLENSResult result);

void setup() {
    SabertoothTXPinSerial.begin(9600);
    Serial.begin(115200);
    mySerial.begin(9600);
    while (!huskylens.begin(mySerial))
    {
        Serial.println(F("Begin failed!"));
        Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>Serial 9600)"));
        Serial.println(F("2.Please recheck the connection."));
        delay(100);
    }
}

void loop()
{
    if (!huskylens.request())
Serial.println(F("Fail to request data from HUSKYLENS, recheck the connection!"));

    else if(!huskylens.isLearned())
Serial.println(F("Nothing learned, press learn button on HUSKYLENS to learn one!"));

    else if(!huskylens.available())
Serial.println(F("No block or arrow appears on the screen!"));

    else
    {
        Serial.println(F("###########"));
        while (huskylens.available())
        {
            HUSKYLENSResult result = huskylens.read();
            printResult(result);
            driveBot(result);
        }   
    }
}


void printResult(HUSKYLENSResult result){
    if (result.command == COMMAND_RETURN_BLOCK){
        Serial.println(String()+F("Block:xCenter=")+result.xCenter+F(",yCenter=")+result.yCenter+F(",width=")+result.width+F(",height=")+result.height+F(",ID=")+result.ID);
    }
    else if (result.command == COMMAND_RETURN_ARROW){
        Serial.println(String()+F("Arrow:xOrigin=")+result.xOrigin+F(",yOrigin=")+result.yOrigin+F(",xTarget=")+result.xTarget+F(",yTarget=")+result.yTarget+F(",ID=")+result.ID);
    }
    else{
        Serial.println("Object unknown!");
    }
}

void driveBot(HUSKYLENSResult result)
{
  if(result.xCenter<=140)
  {
    //left();
  ST.motor(1,2);
  ST.motor(2,5);
  Serial.println("Left");
  delay(100);
  }

  else if(result.xCenter>=200)
  {
    //right();
    ST.motor(1,5);
    ST.motor(2,2);
    Serial.println("Right");
    delay(100);
  }

    else if((result.xCenter>=140)&&(result.xCenter<=200))
  {
    if(result.width<=20)
    {
     // forward();
     ST.motor(1,5);
     ST.motor(2,5);
     Serial.println("Forward");
     delay(100);
    }

    else if(result.width>30)
    {
      //Stop();
      ST.motor(1,0);
      ST.motor(2,0);
      Serial.println("Stop");
      delay(100);
    }
  }
 
}

wildbill

Do you have a simpler program to prove to yourself that the setup you have will drive the motors? What do you have for a power supply?

Go Up