Hello all,
I’m new to the forum, so if I’m ignoring some important conventions or posing in the wrong category, sorry for that.
Our faculty just recently bought two 3WD Omniwheel Mobile Robots.
After playing around with the driving functionality using the included library, I noticed that stopping the robot does not work.
More specifically, even changing the speed of a single wheel is not working.
Here is a somewhat minimal example I came up with (derived from the included 3WD example code):
#include <EEPROM.h>
#include <fuzzy_table.h>
#include <PID_Beta6.h>
#include <PinChangeInt.h>
#include <PinChangeIntConfig.h>
#include <MotorWheel.h>
#include <Omni3WD.h>
irqISR(irq1,isr1);
MotorWheel wheel1(9,8,6,7,&irq1);
irqISR(irq2,isr2);
MotorWheel wheel2(10,11,12,13,&irq2);
irqISR(irq3,isr3);
MotorWheel wheel3(3,2,4,5,&irq3);
Omni3WD Omni(&wheel1,&wheel2,&wheel3);
void setup() {
TCCR1B=TCCR1B&0xf8|0x01; // Pin9,Pin10 PWM 31250Hz
TCCR2B=TCCR2B&0xf8|0x01; // Pin3,Pin11 PWM 31250Hz
Omni.PIDEnable(0.26,0.02,0,10);
}
void loop() {
int speed1 = 50;
unsigned long now = millis();
if (now % 7000 == 0) {
if (Omni.getCarStat() != Omni3WD::STAT_ADVANCE)
Omni.setCarSlow2Stop(500);
Omni.setCarAdvance(speed1);
} else if (now % 3000 == 0) {
if (Omni.getCarStat() != Omni3WD::STAT_STOP)
Omni.setCarSlow2Stop(500);
// !!!!
Omni.setCarStop(); // Reverses one wheel instead of stopping all wheels.
// !!!!
}
Omni.PIDRegulate();
}
Looking at the loop function, this should switch between driving forward and stopping every couple of seconds.
However, when the robot is supposed to be stopping, one of the wheels just starts rotating in the other direction and the other one keeps going.
I am guessing this is because, internally, the speed is set to 0 and so the direction is changed from backwards to forwards for this one wheel (which is rotating backwards to mirror the other wheel).
This is of course not the expected behaviour - both wheels ought to stop. Replacing setCarStop() with setting the speed of each wheel individually does not work either, and leaving out the setCarSlow2Stop parts doesn’t change anything.
Another example with one wheel (derived from one of the examples in the documentation):
#include <MotorWheel.h>
#include <PID_Beta6.h>
#include <PinChangeInt.h>
#include <PinChangeIntConfig.h>
irqISR(irq1,isr1);
MotorWheel wheel1(9,8,6,7,&irq1);
void setup() {
TCCR1B=TCCR1B&0xf8|0x01;
wheel1.PIDEnable(0.26, 0.02, 0, 10);
}
void loop() {
wheel1.setSpeedMMPS(40, DIR_ADVANCE);
for(int i=0;i<1000;++i) {
wheel1.PIDRegulate();
delay(10);
}
delay(1000);
wheel1.setSpeedMMPS(80, DIR_ADVANCE);
for(int i=0;i<1000;++i) {
wheel1.PIDRegulate();
delay(10);
}
delay(1000);
wheel1.setSpeedMMPS(0);
for(int i=0;i<1000;++i) {
wheel1.PIDRegulate();
delay(10);
}
delay(1000);
}
This should rotate one wheel with different speeds for a couple of seconds each, stopping it completely for some time (when the speed is set to 0).
However, it just rotates at a constant speed throughout. Changing the direction to DIR_BACKOFF works (the wheel rotates in the other direction).
I have tested these snippets on both robots we ordered, and the problem is occurring on both, so it’s unlikely to be a hardware- or assembly issue,
which means there’s probably either something wrong with the library or with my code.
Can someone please help me with this? I’ve tried everything I can come up with, and I’m completely clueless as to why it’s not working at this point.
Thank you in advance!
Best Regards
Max