Software > Software

Controlling motors [Urgent]

<< < (14/15) > >>

Mastermime:
Well I set up Sabertooth in project designer as a Sabertooth, but I'm sending commands 0-255 not the Webbotlib -64 - 127.  I should probably change that to see if that may be part of the problem.

Webbot:
Ok - here are the steps that I would take:-

1-Get the joystick controller wired up to Hyperterminal (or other).  For each motor/stick make sure that it is sending 0 (ie in your case '000') for full reverse and '255' for full forward - irrespective of the fact that one motor is probably needing to turn the opposite way (we fix that in WebbotLib).

2-Now use your existing code to scan that 3 char string back into a number from 0 to 255. You could, as an interim, just dump these values to the USB/UART to make sure they are being received ok.

3-Now introduce the Sabertooth via Project Designer. Make one of the motors 'inverted' so that it turns the opposite way to the other if needs be. But before you can send it a command via WebbotLib you need to map the incoming values of 0-255 into the drive speed range DRIVE_SPEED_MIN to DRIVE_SPEED_MAX. You can do this easily with:-

--- Code: ---uint8_t received = the number from 0 to 255 that you received
DRIVE_SPEED speed = interpolate(received, 0, 255, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);

--- End code ---
4. Now that you've got a DRIVE_SPEED you can use it to call act_setSpeed on the Sabertooth motor.

Mastermime:
Ok I just got back to this.  I believe I have achieved step 1 and 2, but the easiest step, step 3 is causing me problems.   I am just trying to set the speed initially with the act_setSpeed function so I made a simplified test file, but when I turn the robot on, I get no activity from the motors.  I'm probably making a really dumb mistake I can't see.

Also just wondering, Why will act_setSpeed differ from what I'm using?  I know that use the same code to drive motors and modified servos, but why will this change anything for my particular problem?

Heres my simple code.


--- Code: ---#include "hardware.h"

#define XBee_Controlled
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

#define UART0_TX_BUFFER_SIZE 80
#define UART0_RX_BUFFER_SIZE 80

#define TRIANGLE 256
#define START 257
#define L2 258
#define R2 259

#define MOTOR_L_MIN 1
#define MOTOR_L_STOP 64
#define MOTOR_L_MAX 127
#define MOTOR_R_MIN 128
#define MOTOR_R_STOP 192
#define MOTOR_R_MAX 255
#define SIGNAL_MOTORS_OFF 0

// Initialize the hardware
void appInitHardware(void) {

initHardware();

#ifdef XBee_Controlled
rprintfInit(debugSendByte);
delay_ms(10);
#endif

}


// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
}

// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
uint8_t received = XbeeGetByte;
DRIVE_SPEED speed = interpolate(received, 0, 255, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
act_setSpeed(&motor_1, 100);
act_setSpeed(&motor_2, 100);

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
TICK_COUNT ms = loopStart / 1000; // Get current time in ms
int16_t now = ms % (TICK_COUNT)10000; // 10 sec for a full swing
if(now >= (int16_t)5000){ // Goes from 0ms...5000ms
now = (int16_t)10000 - now; // then 5000ms...0ms
}
return 0;
}

--- End code ---

Webbot:
The act_setSpeed will convert your value of 100 into almost full power forward and send a command out to the uart. Since you are using a constant value it will/should(?) only send it once.

First check that you've got the DIP switches on the Sabertooth set up according to the picture in Project Designer for the Sabertooth - as this has an effect on the commands that are sent out (eg packetized vs simple mode).

Try disconnecting the UART output from the Sabertooth and send it to your PC instead - assuming you've got a TTL to RS232/USB converter - then you can see exactly what cmd is being sent to the Sabertooth.

I'm assuming that if you create a fresh project and just use the default generated example code that the motors do move between full fwd and full reverse every 10 seconds.

Mastermime:
Ok I just tested again with fresh code generated from Webbotlib


--- Quote ---The act_setSpeed will convert your value of 100 into almost full power forward and send a command out to the uart. Since you are using a constant value it will/should(?) only send it once.
--- End quote ---

Yep that's exactly what happened so that's good


--- Quote ---First check that you've got the DIP switches on the Sabertooth set up according to the picture in Project Designer for the Sabertooth - as this has an effect on the commands that are sent out (eg packetized vs simple mode).
--- End quote ---
DIP switches checked and they are correct


--- Code: ---#include "hardware.h"

// Initialise the hardware
void appInitHardware(void) {
initHardware();
}
// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
return 0;
}
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {

// -------- End   Digital Output-------

// -------- Start Actuators -------
// To control your.motors/servos then see actuators.h in the manual
// To retrieve the required speed of motor_1 use:
// DRIVE_SPEED speed=act_getSpeed(motor_1);
// To set the required speed of motor_1 use:
// act_setSpeed(motor_1,speed);
// This example will move the motors back and forth using the loopStart time:
TICK_COUNT ms = loopStart / 1000; // Get current time in ms
int16_t now = ms % (TICK_COUNT)10000; // 10 sec for a full swing
if(now >= (int16_t)5000){ // Goes from 0ms...5000ms
now = (int16_t)10000 - now; // then 5000ms...0ms
}
// Map it into DRIVE_SPEED range
uint8_t received = XbeeGetByte;

DRIVE_SPEED speed = interpolate(received, 0, 255, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
// Set speed for all motors/servos
act_setSpeed(&motor_1,100);

act_setSpeed(&motor_2,100);

// -------- End   Actuators -------

return 0;
}

--- End code ---

So now if I rewrite the receiving code, it should work correct if I use this

--- Code: ---uint8_t received = the number from 0 to 255 that you received
DRIVE_SPEED speed = interpolate(received, 0, 255, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
--- End code ---

and then use the code below to set it according to the bytes received

--- Code: ---act_setSpeed(&motor_1,speed);
--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version