Workaround for controlling motor for AAI Canada, Inc. Labo-3
At lab I'm writing a code that operates the wheels of AAI Canada, Inc.'s Labo-3 mobile robot. But I had a problem and found a workaround which was stated neither in the manual the company provides nor in the sample codes that were on the machine. Here's some tips I've found so far.
- Phenomenon
Machine doesn't move toward the direction given, and I failed to find a rule of this phenomeno. Sometimes it moved forward even though I told it to move backward, sometimes the opposite. It often seemed it took the values that were given just one previously, but sometimes it kept ignoring all data input.
- Workaround found
1. Do not use setMotorSpeedAll(int *speeds), use setMotorSpeed(unsigned int motornum, int speed) instead. Should be bug, not a specification, since it is against what is stated in the manual.
2. setMotorPower(int set) should be called AFTER setMotorSpeed. Can also be called as bug since this is against the sample code written in the manual provided the company.
Here's a sample code (oops it lost indentation...anybody tell me how to keep indentaion on blogger.com?):
- Phenomenon
Machine doesn't move toward the direction given, and I failed to find a rule of this phenomeno. Sometimes it moved forward even though I told it to move backward, sometimes the opposite. It often seemed it took the values that were given just one previously, but sometimes it kept ignoring all data input.
- Workaround found
1. Do not use setMotorSpeedAll(int *speeds), use setMotorSpeed(unsigned int motornum, int speed) instead. Should be bug, not a specification, since it is against what is stated in the manual.
2. setMotorPower(int set) should be called AFTER setMotorSpeed. Can also be called as bug since this is against the sample code written in the manual provided the company.
Here's a sample code (oops it lost indentation...anybody tell me how to keep indentaion on blogger.com?):
/*
* Author: Owarai Taikoku Nippon (isao.saito [at] mavs.uta.edu)
*/
#include "stdio.h"
#include "usermotor.h"
#define DURATION_SLEEP_INITIALIZATION 1
int steeringWheelTest(int duration_moving, int l, int r) {
signed int speeds[4], gpv[4];
if (initMotors()){
exit(-1);
}
printf("Input L= %d, R= %d. GetMotorPower= %d\n", l, r, getMotorPower());
setMotorPower(0);
setBrakes(0);
// sleep(2);
sleep(DURATION_SLEEP_INITIALIZATION);
gpv[0] = 0;
gpv[1] = 0;
gpv[2] = 0;
gpv[3] = 0;
getMotorSpeedAll(gpv);
printf("MotorSpeed obtained (Before setting speed): %d %d %d %d\n", gpv[0], gpv[1], gpv[2], gpv[3]);
// sleep(2);
sleep(DURATION_SLEEP_INITIALIZATION);
speeds[0] = l;
speeds[1] = r;
speeds[2] = l;
speeds[3] = r;
//setMotorSpeedAll(*speeds); // 10Aug09 Isao) This function may NOT function as you intend. Use setMotorSpeed(int, int) instead.
setMotorSpeed(2, speeds[2]);
setMotorSpeed(3, speeds[3]);
printf("GetMotorPower= %d\nMotor values passed: %d %d %d %d\n", getMotorPower(), speeds[0], speeds[1], speeds[2], speeds[3]);
setMotorPower(1); //10Aug09 Isao) Should be called AFTER setMotorSpeed(int, int) is called.
if(0 == duration_moving){
// Temporary block that enables this program durable in finite amount of time
duration_moving = 6;
}
sleep(duration_moving); // Cart keeps on moving during this sleep.
setMotorPower(0);
gpv[0] = 0;
gpv[1] = 0;
gpv[2] = 0;
gpv[3] = 0;
getMotorSpeedAll(gpv);
printf("MotorSpeed obtained (After setting speed): %d %d %d %d\n", gpv[0], gpv[1], gpv[2], gpv[3]);
usleep(100000);
printf("GetMotorPower= %d\n", getMotorPower());
closeMotors();
sleep(DURATION_SLEEP_INITIALIZATION);
printf("GetMotorPower= %d After closeMotors\n", getMotorPower());
printf("-- motorTest ends --\n");
}
int main(int argc, const char* argv[]) {
int dur, l, r;
dur = atoi(argv[1]);
l = atoi(argv[2]);
r = atoi(argv[3]);
steeringWheelTest(dur, l, r);
}
![]() |
Hamburgers@Billy's Miner, Ft.Worth, TX. Nothing special but authentic. Friend drinks beer even though this is lunch during his job. |
Comments