go away spammer

Author Topic: Controlling motors [Urgent]  (Read 11680 times)

0 Members and 1 Guest are viewing this topic.

Offline MastermimeTopic starter

  • Supreme Robot
  • *****
  • Posts: 316
  • Helpful? 5
Re: Controlling motors [Urgent]
« Reply #60 on: February 21, 2013, 12:26:37 AM »
Ok I will integrate this into my code tomorrow after I get home from school.  Do you think this is the problem though for the odd motor occurrences?  I forgot to just set the motors at 256 to see if its a hardware problem.  I will do this as well.

Offline MastermimeTopic starter

  • Supreme Robot
  • *****
  • Posts: 316
  • Helpful? 5
Re: Controlling motors [Urgent]
« Reply #61 on: February 21, 2013, 09:59:32 PM »
Ok I set the motors at half speed and they worked.

I added the change Webbot suggested and the same results occurred.  It's almost as if the Sabertooth can't interpret data at the same time.  I'm checking my data (rprintf) and I'm getting the correct data from the Xbee when I push both forward
« Last Edit: February 21, 2013, 11:14:35 PM by Mastermime »

Offline MastermimeTopic starter

  • Supreme Robot
  • *****
  • Posts: 316
  • Helpful? 5
Re: Controlling motors [Urgent]
« Reply #62 on: February 25, 2013, 05:43:30 PM »
Ahh man I tried another thing, but that didn't work either. 

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Controlling motors [Urgent]
« Reply #63 on: February 25, 2013, 09:05:15 PM »
Whenever I get stuck like this, I just comment out all of the code except the most important parts.

I also simplify everything to the very basics.

Then verify each part of the code in small chunks.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Controlling motors [Urgent]
« Reply #64 on: February 25, 2013, 09:58:02 PM »
Going back to one of my earlier posts - are you still sending Sabertooth commands yourself (ie in ProjectDesigner the Sabertooth is just a UART) or are you then trying to send them via WebbotLib to set the speed (ie in ProjectDesigner the Sabertooth is a Sabertooth).

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline MastermimeTopic starter

  • Supreme Robot
  • *****
  • Posts: 316
  • Helpful? 5
Re: Controlling motors [Urgent]
« Reply #65 on: February 26, 2013, 02:13:56 PM »
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.

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Controlling motors [Urgent]
« Reply #66 on: February 26, 2013, 04:10:17 PM »
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: [Select]
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);
4. Now that you've got a DRIVE_SPEED you can use it to call act_setSpeed on the Sabertooth motor.
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline MastermimeTopic starter

  • Supreme Robot
  • *****
  • Posts: 316
  • Helpful? 5
Re: Controlling motors [Urgent]
« Reply #67 on: March 06, 2013, 09:44:39 PM »
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: [Select]
#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;
}
« Last Edit: March 06, 2013, 09:46:33 PM by Mastermime »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Controlling motors [Urgent]
« Reply #68 on: March 08, 2013, 01:20:45 PM »
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.

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline MastermimeTopic starter

  • Supreme Robot
  • *****
  • Posts: 316
  • Helpful? 5
Re: Controlling motors [Urgent]
« Reply #69 on: March 09, 2013, 12:26:31 PM »
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.

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).
DIP switches checked and they are correct

Code: [Select]
#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;
}

So now if I rewrite the receiving code, it should work correct if I use this
Code: [Select]
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);

and then use the code below to set it according to the bytes received
Code: [Select]
act_setSpeed(&motor_1,speed);

Offline MastermimeTopic starter

  • Supreme Robot
  • *****
  • Posts: 316
  • Helpful? 5
Re: Controlling motors [Urgent]
« Reply #70 on: March 16, 2013, 08:09:29 PM »
Ok I just tried it with some new code I wrote and I got a horrible result.  Only the left motor moved and it wasn't very responsive. 

Then the worst part was my motor driver went up in flames  :'(.  I couldn't tell if it was the code or if I accidentally shorted something out, but the Sabertooth should have protection against overcurrent and shorting something out.

Is there something noticeably wrong with this code that caused the fire?  It would've been probably easier to adapt the command to my old code.
Code: [Select]
#include "hardware.h"

#define XBee_Controlled
#define DEBUG 1

#define UART0_TX_BUFFER_SIZE 80
#define UART0_RX_BUFFER_SIZE 80

#define ACCELERATION 5
#define DECELERATION 5
#define IDLE_LOOPS_TILL_STOP 10
#define DRIVE_SPEED_MIN -128
#define DRIVE_SPEED_MAX 128

#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

#ifndef max
#define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
#endif

#ifndef min
#define min( a, b ) ( ((a) < (b)) ? (a) : (b) )
#endif

int16_t motorLCurVal;
int16_t motorRCurVal;
int16_t motorLTarVal;
int16_t motorRTarVal;
int16_t motorLIdle;
int16_t motorRIdle;

boolean receiving;
#define PACKET_SIZE 3
char packet[] = {0, 0, 0, 0};
int curByte;

// Initialize the hardware
void appInitHardware(void) {

initHardware();

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

//rprintf("\nHardware initialized.\n\n");
}


// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
//rprintf("\nAxon Initiated.\n\n");
receiving = false;
motorLCurVal = motorLTarVal = MOTOR_L_STOP;
motorRCurVal = motorRTarVal = MOTOR_R_STOP;
curByte = 0;
}

// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {

uint16_t tempbyte = NULL;

#ifdef XBee_Controlled
if(!uartReceiveBufferIsEmpty(UART0)) {
char temp = uartGetByte(UART0);
if (temp == 'A' && !receiving)
{
receiving = true;
packet[3] = '\0';
curByte = 0;
}
else
{
packet[curByte] = temp;
if (curByte == (PACKET_SIZE - 1) )
{
tempbyte = atoi(packet);
rprintf("Packet recieved: %d", tempbyte);
receiving = false;
}
curByte++;
}
}
#endif

if (tempbyte != NULL)
{
if (tempbyte >= MOTOR_L_MIN && tempbyte <= MOTOR_L_MAX)
{
motorLTarVal = interpolate(tempbyte, 1, 127, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
motorLIdle = 0; motorRIdle++;
}
else if (tempbyte >= MOTOR_L_MIN && tempbyte <= MOTOR_L_MAX)
{
motorRTarVal = interpolate(tempbyte, 128, 255, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
motorRIdle = 0; motorLIdle++;
}
else
{
motorLIdle++; motorRIdle++;
switch(tempbyte)
{
case TRIANGLE:
break;

case START:
break;

case L2:
break;

case R2:
break;

default:
break;
}
}
tempbyte = NULL;
}

adjustMotorSpeed(); //Only moves motor if current value != target value

if (motorLIdle > IDLE_LOOPS_TILL_STOP)
{
motorLTarVal = 0;
}

if (motorRIdle > IDLE_LOOPS_TILL_STOP)
{
motorRTarVal = 0;
}

return 0;
}

void adjustMotorSpeed()
{
if (motorLCurVal < motorLTarVal)
{
motorLCurVal = min((motorLCurVal + ACCELERATION), motorLTarVal);
act_setSpeed(&motor_1, motorLCurVal);
}
if (motorLCurVal > motorLTarVal)
{
motorLCurVal = max((motorLCurVal - DECELERATION), motorLTarVal);
act_setSpeed(&motor_1, motorLCurVal);
}
if (motorRCurVal < motorRTarVal)
{
motorRCurVal = min((motorRCurVal + ACCELERATION), motorRTarVal);
act_setSpeed(&motor_2, motorRCurVal);
}
if (motorRCurVal > motorRTarVal)
{
motorRCurVal = max((motorRCurVal - DECELERATION), motorRTarVal);
act_setSpeed(&motor_2, motorRCurVal);
}

}

« Last Edit: March 16, 2013, 09:06:48 PM by Mastermime »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: Controlling motors [Urgent]
« Reply #71 on: March 17, 2013, 08:52:59 AM »
Why are you redefining DRIVE_SPEED_MIN and DRIVE_SPEED_MAX - they are defined in Webbotlib (with different values to yours - so you will be confusing Webbotlib enormously).
Since its just a serial interface to the Sabertooth there shouldn't be anything you can send it that will damage the board. So I think you must have shorted something.

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline MastermimeTopic starter

  • Supreme Robot
  • *****
  • Posts: 316
  • Helpful? 5
Re: Controlling motors [Urgent]
« Reply #72 on: March 20, 2013, 09:37:29 PM »
Quote
Why are you redefining DRIVE_SPEED_MIN and DRIVE_SPEED_MAX - they are defined in Webbotlib (with different values to yours - so you will be confusing Webbotlib enormously).
Ahh that was a mistake.  My new Sabertooth should be coming very soon thanks to Dimension Engineering's great support (highly recommended).

Does everything else look alright? 
Btw I'm sorry for my ignorance.  It's just that I'm more of an EE guy and my software skills are raw and rough.

Offline MastermimeTopic starter

  • Supreme Robot
  • *****
  • Posts: 316
  • Helpful? 5
Re: Controlling motors [Urgent]
« Reply #73 on: March 31, 2013, 07:47:33 PM »
Ok I just finished rewiring my electrical to make it cleaner and less problematic.  I verified my wiring so that's correct.  Is it possible that my wiring was causing the simultaneous half speed full speed?  I did notice the error LED went off when this occurred, but I was able to run them both full speed by just setting them to full speed without any serial communication so this makes me think its my code.  I just don't see what would cause this

 


Get Your Ad Here

data_list