Question for one of the motors

Lower Canada College

Published on 2020-01-25

Hello,

I've experienced an error with one of my motors, more specifically CRC_PWM_3. What I've set up is a custom Mechanum wheel movement setup (shows up as "Belise" in the code provided below). In short, I wanted to set up a 5th motor for a separate function which isn't correlated with the Mechanum movement. However, the same 

void Test(int MyPWM){}

works just fine in a separate tab. Anything I did wrong?

- Bogdan

#include <CrcLib.h>
using namespace Crc;

void setup() 
{

  CrcLib::Initialize();

  CrcLib::InitializePwmOutput (CRC_PWM_3); // multi-use motor
  CrcLib::InitializePwmOutput (CRC_PWM_5); // front left
  CrcLib::InitializePwmOutput (CRC_PWM_7); // back left
  CrcLib::InitializePwmOutput (CRC_PWM_9, true); // front right
  CrcLib::InitializePwmOutput (CRC_PWM_11); // back right
  CrcLib::SetDigitalPinMode(CRC_DIG_4, OUTPUT); // multi-use motor digital output

  Serial.begin(9600);  
}

void loop() 
{
  CrcLib::Update();
  //bool L2Button = CrcLib::ReadDigitalChannel(BUTTON::L2);
  unsigned char LjoyY = LjoyY = Crc::CrcLib::ReadAnalogChannel(ANALOG::LCHANY);
  unsigned char LjoyX = LjoyX = Crc::CrcLib::ReadAnalogChannel(ANALOG::LCHANX);
  unsigned char RjoyY = RjoyY = Crc::CrcLib::ReadAnalogChannel(ANALOG::RCHANY);
  unsigned char RjoyX = RjoyX = Crc::CrcLib::ReadAnalogChannel(ANALOG::RCHANX); 

  CrcLib::Belise (ANALOG :: LCHANY, ANALOG :: LCHANX, ANALOG::RCHANX, CRC_PWM_5, CRC_PWM_7, CRC_PWM_9, CRC_PWM_11);

  Test(8);
}

void Test(int MyPWM)
{
  if (CrcLib::ReadDigitalChannel(BUTTON::L2)) {
    CrcLib::SetDigitalOutput(CRC_DIG_4, HIGH);
    CrcLib::SetPwmOutput(CRC_PWM_3, 127);
    bool L2Button = CrcLib::ReadDigitalChannel(BUTTON::L2);
    Serial.print(" L2-"); Serial.println(L2Button);
  }

    else {
    CrcLib::SetDigitalOutput(CRC_DIG_4, LOW);
    CrcLib::SetPwmOutput(CRC_PWM_3, 0);
    Serial.println("noButt");
  }
}
Answers

Marco Purich

Published on 2020-01-25

Hi Bogdan,

First thing I noticed about your code isn't really a problem just more of a little thing to keep in mind. You have a parameter "MyPWM" for your test function that is never used, so it could be removed entirely.

Second, I'm not entirely clear on what your actual issue is, as there should technically be no problem with you using your own setup function and other PWM pins separately provided it does not interfere with the library. What is the behaviour you're expecting? What actually happens? What do you mean by "it works fine in another tab"?

Lower Canada College

Published on 2020-01-25

Hey Marco,

Thanks for getting back so soon. By other tab I meant other .ino file, an older version of my base code. The older .ino is provided under this post. In short when uploaded a motor will spin in one direction and when I press L2 it spins in another direction. I want something similar for my new .ino with CRC_PWM_3  (when nothing is pressed nothing happens when L2 is pressed motor turns 127) but nothing is happening.

- Bogdan

#include <CrcLib.h>
using namespace Crc;
#define  MoTor CRC_PWM_5;

void setup()
{
  CrcLib::Initialize();

  CrcLib::InitializePwmOutput(CRC_PWM_5);

  CrcLib::SetDigitalPinMode(CRC_DIG_4, OUTPUT);

  //Not necessary
  Serial.begin(9600);
}

void loop()
{
  CrcLib::Update();
  //Not necessary
  //unsigned int deltaMicros = CrcLib::GetDeltaTimeMicros();
  //Serial.println(deltaMicros);
  Test(8);

}

void Test(int MyPWM) {
  /*if (CrcLib::ReadDigitalChannel(BUTTON::R2)) {
    CrcLib::SetDigitalOutput(CRC_DIG_4, HIGH);
    CrcLib::SetPwmOutput(CRC_PWM_5, 127);
    bool R2Button = CrcLib::ReadDigitalChannel(BUTTON::R2);
    Serial.print(" R2-"); Serial.println(R2Button);
  }*/

  if (CrcLib::ReadDigitalChannel(BUTTON::L2)) {
    CrcLib::SetDigitalOutput(CRC_DIG_4, HIGH);
    CrcLib::SetPwmOutput(CRC_PWM_5, -127);
    bool L2Button = CrcLib::ReadDigitalChannel(BUTTON::L2);
    Serial.print(" L2-"); Serial.println(L2Button);
  }

  else if (CrcLib::ReadAnalogChannel(ANALOG::LCHANY)) {
    CrcLib::SetDigitalOutput(CRC_DIG_4, HIGH);
    CrcLib::SetPwmOutput(CRC_PWM_5, 127);
    unsigned char LjoyY = CrcLib::ReadAnalogChannel(ANALOG::LCHANY);
    Serial.print(" bruh"); Serial.println(LjoyY);
  }
  
  else {
    CrcLib::SetDigitalOutput(CRC_DIG_4, LOW);
    CrcLib::SetPwmOutput(CRC_PWM_5, 0);
    Serial.println("noButt");
  }


}

Marco Purich

Published on 2020-01-25

From the looks of it, you might be encountering an error somewhere earlier in your loop function. Try commenting stuff out that's unessential, and then un-commenting it one at a time (of course re-compiling and testing it after each change) to see when it stops working. From what I've seen when there's a runtime error the arduino just kinda ignores it, doesn't tell you anything and skips to the beginning of the next loop iteration.

Did you add your "Belise" function info the library files we provided?

Lower Canada College

Published on 2020-01-26

Okay, I'll try commenting some lines out and then testing on the tester bot first thing I get access to it. Thanks a lot.

And yes, Belise is an edited version of moveHolonomic made to work for Mecanum. I edited CrcLib.h and CrcLib.cpp to get it working.