Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
#include "hardware.h"#define XBee_Controlled//#define USB_Controlled#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 0int motorLCurVal;int motorRCurVal;int motorLTarVal;int motorRTarVal;int motorVal;// Initialise the hardwarevoid appInitHardware(void) { //uartInit(); // initialize the UART (serial port) uartInit(Xbee, 9600); //UART0 uartInit(uart1, 9600); //USB uartInit(Sabertooth_uart, 9600); //USB SabertoothInit(&driver); //Initialize sabertooth}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ motorLCurVal = motorLTarVal = MOTOR_L_STOP; motorRCurVal = motorRTarVal = MOTOR_R_STOP;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { int tempbyte = NULL; tempbyte=XbeeGetByte; // Xbee byte if (tempbyte >= MOTOR_L_MIN && tempbyte <= MOTOR_R_MAX) { setMotorSpeed(tempbyte); } else if (tempbyte == START) { pin_toggle(Remoteswitch_relay); // Turn relay on or off } else { motorStopMotor(); } delay_ms(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;}//code by Tzankoff//code for gradual stopping and starting//motorXCurVal is the current speed. //motorXTarVal is where we want the speed to be.//motorVal, in this case, is running on a scale of 1 to 10. Thus, 1 is 10% of maximum //speed, 2 is 20%, and so on. NOT USEDvoid motorStopMotor(){ do { if (motorLCurVal<MOTOR_L_STOP) { motorLCurVal=motorLCurVal+1; } else if (motorLCurVal>MOTOR_L_STOP) { motorLCurVal=motorLCurVal-1; } Sabertooth_uartSendByte(motorLCurVal); delay_ms(50); if (motorRCurVal<MOTOR_R_STOP) { motorRCurVal=motorRCurVal+1; } else if (motorRCurVal>MOTOR_R_STOP) { motorRCurVal=motorRCurVal-1; } Sabertooth_uartSendByte(motorRCurVal); delay_ms(50); } while (motorLCurVal!=MOTOR_L_STOP && motorRCurVal!=MOTOR_R_STOP);}void setMotorSpeed(int byte){ if (byte >= MOTOR_L_MIN && byte <= MOTOR_L_MAX) { motorLTarVal = byte; do { if (motorLCurVal < motorLTarVal) { Sabertooth_uartSendByte(++motorLCurVal); } else { Sabertooth_uartSendByte(--motorLCurVal); } delay_ms(100); } while (motorLCurVal != motorLTarVal); } else if (byte >= MOTOR_R_MIN && byte <= MOTOR_R_MAX) { motorRTarVal = byte; do { if (motorRCurVal < motorRTarVal) { Sabertooth_uartSendByte(++motorRCurVal); } else { Sabertooth_uartSendByte(--motorRCurVal); } delay_ms(100); } while (motorRCurVal != motorRTarVal); }}/* This is weird and seems unecessarily complicated. Basically the same thing above I think. Not sure why it stopsthe motor before moving it as well, seems logically incorrect. Should move from CurSpeed -> TarSpeed, notCurSpeed -> Stop -> TarSpeed. Keeping this around incase I am wrong.void motorMoveMotor(int motorL, int motorR) // motorL and motorR are -1 for reverse, 0 for stop, 1 for forward{ motorStopMotor(); delay_ms(100); motorInt=(63*motorVal)/100; motorLTarVal=64+motorInt; if (motorL<0) { motorLTarVal=64-motorInt; } motorRTarVal=192+motorInt; if (motorR<0) { motorRTarVal=192-motorInt; } do { if (motorLCurVal<motorLTarVal) { motorLCurVal=motorLCurVal+1; } else if (motorLCurVal>motorLTarVal) { motorLCurVal=motorLCurVal-1; } motors_uartSendByte(motorLCurVal); delay_ms(50); if (motorRCurVal<motorRTarVal) { motorRCurVal=motorRCurVal+1; } else if (motorRCurVal>motorRTarVal) { motorRCurVal=motorRCurVal-1; } motors_uartSendByte(motorRCurVal); delay_ms(50); } while (motorLCurVal!=motorLTarVal && motorRCurVal!=motorRTarVal);}*/
#include "hardware.h"// Initialise the hardwarevoid appInitHardware(void) { initHardware();}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { // -------- Start Switch/Button------- // Switch/Button - see switch.h // To test if it is pressed then if(SWITCH_pressed(&button)){ // pressed } // To test if it is released then if(SWITCH_released(&button)){ // released } // -------- End Switch/Button------- // -------- Start Marquee------- // Marquee - see 'segled.h' // Before using the Marquee you need to redirect rprintf to write to it // This can be done using Writer old = rprintfInit(marqueeGetWriter(&marquee)); // All rprintf output will then be sent to the marquee but will not // display until an end-of-line eg "\n" has been sent. Example:- // rprintf("Hello World\n"); // If the endDelay is non-zero then the marquee will scroll // forever or until you call: marqueeStop(&marquee); // If the endDelay is zero then the marquee will stop once // the entire line has been shown ('one-shot' mode) // In 'one-shot' mode then you may want to make sure that // a previous line has finished before you display a second line. // This can be done as follows:- marqueeSetEndDelay(&marquee,0); // Make sure we are in one-shot mode if(marqueeIsActive(&marquee)==FALSE){ if(loopCount==1){ rprintf("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"); }else{ rprintf("Loop=%u\n",(unsigned)loopCount); // Put the loop count } } // Restore rprintf back to its previous location rprintfInit(old); // -------- End Marquee------- // -------- Start Analogue Input------- // Read the Analogue Input and store results uint16_t Temp_sensor1val = a2dConvert10bit(Temp_sensor1); // Dump out the value rprintf("Temp_sensor1: %d\n",Temp_sensor1val); // -------- End Analogue Input------- // -------- Start Analogue Input------- // Read the Analogue Input and store results uint16_t Temp_sensor2val = a2dConvert10bit(Temp_sensor2); // Dump out the value rprintf("Temp_sensor2: %d\n",Temp_sensor2val); // -------- End Analogue Input------- // -------- Start Analogue Input------- // Read the Analogue Input and store results uint16_t Bat_monitorval = a2dConvert10bit(Bat_monitor); // Dump out the value rprintf("Bat_monitor: %d\n",Bat_monitorval); // -------- End Analogue Input------- // -------- Start LED------- // The LED can be manipulated using the calls in led.h // To turn the LED on:- LED_on(&led_ext1); // To turn the LED off:- LED_off(&led_ext1); // -------- End LED------- // -------- Start LED------- // The LED can be manipulated using the calls in led.h // To turn the LED on:- LED_on(&led_ext2); // To turn the LED off:- LED_off(&led_ext2); // -------- End LED------- // -------- Start LED------- // The LED can be manipulated using the calls in led.h // To turn the LED on:- LED_on(&leds_int); // To turn the LED off:- LED_off(&leds_int); // -------- End LED------- // -------- Start Digital Output------- // Set the pin high pin_high(Remoteswitch_relay); // Set the pin low pin_low(Remoteswitch_relay); // Toggle the pin ie high->low, or low->high pin_toggle(Remoteswitch_relay); // Output a high pulse of 1000us pin_pulseOut(Remoteswitch_relay,1000,TRUE); // -------- End Digital Output------- // -------- Start Digital Output------- // Set the pin high pin_high(Xbee5v); // Set the pin low pin_low(Xbee5v); // Toggle the pin ie high->low, or low->high pin_toggle(Xbee5v); // Output a high pulse of 1000us pin_pulseOut(Xbee5v,1000,TRUE); // -------- 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 DRIVE_SPEED speed = interpolate(now, 0, 5000, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX); // Set speed for all motors/servos act_setSpeed(&motor_1,speed); act_setSpeed(&motor_2,speed); act_setSpeed(&servo,speed); // -------- End Actuators ------- return 0;}
/* * NOTES: * 0-127 Motor Left (1-63: forward, 64: stop, 65-127: reverse) * 128-255 Motor Right (128-191: forward, 192: stop, 193-255: reverse) */ #include <GPSXClass.h>#include <SoftwareSerial.h>#include <LiquidCrystal.h>//#include <XBee.h>#include <Servo.h>#include <Sabertooth.h>// LCD SCREEN#define LCD_COLS 20#define LCD_ROWS 4#define BACKLIGHT_ON 'HIGH'#define BACKLIGHT_OFF 'LOW'// XBEE#define DATA_LED 10#define STATUS_LED 11#define ERROR_LED 12#define REMOTE_XBEE_ADDR 0x1874 //TODO#define RESPONSE_WAIT 5000#define DEBUG true// PS2 SEND#define TRIANGLE 256#define START 0#define L2 257#define R2 258#define JOYSTICK_LOW 90#define JOYSTICK_HIGH 160#define DELAY 100#define SERIAL_BPS 9600// GLOBAL VARIABLESLiquidCrystal lcd(12, 11, 5, 4, 3, 2); //TODO/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Initialize- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */void setup(){ initPSX(); //Get PS2 controller ready initLCD(); //Get LCD ready initXBee(); //Get XBee Wireless Transmitter ready}/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Main- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */void loop(){ //PS2 Controller Input readPS2Input(); delay(DELAY);}/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Helpers- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */void initPSX(){ PSX.mode(PSX_PAD1, MODE_ANALOG, MODE_LOCK); PSX.motorEnable(PSX_PAD1, MOTOR1_DISABLE, MOTOR2_DISABLE); // Poll current state once. PSX.updateState(PSX_PAD1);}void initLCD(){ lcd.begin(LCD_COLS, LCD_ROWS); lcd.clear(); lcd.setCursor(0,0); //lcd.print("Robot Started");}void initXBee(){ Serial.begin(9600);}void readPS2Input(){ Serial.begin(9600); PSX.updateState(PSX_PAD1); if(PRESSED_TRIANGLE(PSX_PAD1)) { if (DEBUG) Serial.println("Triangle pressed"); else sendData(TRIANGLE); } if(PRESSED_START(PSX_PAD1)) { if (DEBUG) Serial.println("Start pressed"); else sendData(START); } if(IS_DOWN_L2(PSX_PAD1)) { if (DEBUG) Serial.println("L2 down"); else sendData(L2); } if(IS_DOWN_R2(PSX_PAD1)) { if (DEBUG) Serial.println("R2 down"); else sendData(R2); } int leftStick = ANALOG_LEFT_Y(PSX_PAD1); int rightStick = ANALOG_RIGHT_Y(PSX_PAD1); if(leftStick < JOYSTICK_LOW) { if (DEBUG) { Serial.print("LEFT TRIGGER FORWARD: "); Serial.println(ANALOG_LEFT_Y(PSX_PAD1), DEC); } else sendData(map(leftStick, 0, JOYSTICK_LOW, 127, 65)); } if(leftStick > JOYSTICK_HIGH) { if (DEBUG) { Serial.print("LEFT TRIGGER BACKWARDS: "); Serial.println(ANALOG_LEFT_Y(PSX_PAD1), DEC); } else sendData(map(leftStick, JOYSTICK_HIGH, 255, 63, 1)); } if(rightStick < JOYSTICK_LOW) { if (DEBUG) { Serial.print("RIGHT TRIGGER FORWARDS: "); Serial.println(ANALOG_RIGHT_Y(PSX_PAD1), DEC); } else sendData(map(rightStick, 0, JOYSTICK_LOW, 255, 193)); } if(rightStick > JOYSTICK_HIGH) { if (DEBUG) { Serial.print("RIGHT TRIGGER BACKWARDS: "); Serial.println(ANALOG_RIGHT_Y(PSX_PAD1), DEC); } else sendData(map(rightStick, JOYSTICK_HIGH, 255, 191, 128)); }}void sendData(int sendVal){ Serial.print(sendVal, DEC);delay(10);}
Is there an issue between the Axon, Arduino and Sabertooth? Which processor is actually controlling the Sabertooth?
2- Is there a communication issue on the serial link? Get the serial data link working between the processors without the XBees by hard wiring the serial line between the two processors.
3- Is there an XBee setup and communication issue? Get the XBees working with a simple to test code. One way is just send data one way then send the data back (remote Echo).
6- Also use a PC (or MAC or Linx) serial data port to test the serial to each processor. Send commands to mimic the data from the PC to each processor. Send the PS2 data to the PC to test if the data is being send properly. Show us a block diagram of the system and what connects to what. So far we can only guess.
I must also add the Marquee is blinking randomly even though I didn't program it to or at least I don't think I did. Does this mean the Axon could be resetting? Just a guess.
Also I have a remote switch I'm having issues with too. How it works Xbee Digital Output > to MOSFET (connects grounds) > energize relay coil and now power can flow to the Sabertooth. When I connect to a 12v signal, everything turns on, but when I connect it to the digital output, the relay makes a loud buzzing sound. Any ideas what this could be? Sorry for all the issues
#include "hardware.h"#define XBee_Controlled//#define USB_Controlled#define UART0_TX_BUFFER_SIZE 4#define UART0_RX_BUFFER_SIZE 4#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 0int motorLCurVal;int motorRCurVal;int motorLTarVal;int motorRTarVal;int motorVal;// Initialise the hardwarevoid appInitHardware(void) { initHardware();}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ motorLCurVal = motorLTarVal = MOTOR_L_STOP; motorRCurVal = motorRTarVal = MOTOR_R_STOP;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { int tempbyte = NULL; #ifdef XBee_Controlled //tempbyte=XbeeGetByte; if(!uartReceiveBufferIsEmpty(UART0)) { int tempbyte = uartGetByte(UART0); } #endifif (tempbyte != NULL) { if (tempbyte >= MOTOR_L_MIN && tempbyte <= MOTOR_R_MAX) { setMotorSpeed(tempbyte); } else if (tempbyte==START) { pin_low(Remoteswitch_relay); } else { motorStopMotor(); } } delay_ms(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;}//motorXCurVal is the current speed. //motorXTarVal is where we want the speed to be.//motorVal, in this case, is running on a scale of 1 to 10. Thus, 1 is 10% of maximum //speed, 2 is 20%, and so on. NOT USEDvoid motorStopMotor(){ do { if (motorLCurVal<MOTOR_L_STOP) { motorLCurVal=motorLCurVal+1; } else if (motorLCurVal>MOTOR_L_STOP) { motorLCurVal=motorLCurVal-1; } Sabertooth_uartSendByte(motorLCurVal); delay_ms(50); if (motorRCurVal<MOTOR_R_STOP) { motorRCurVal=motorRCurVal+1; } else if (motorRCurVal>MOTOR_R_STOP) { motorRCurVal=motorRCurVal-1; } Sabertooth_uartSendByte(motorRCurVal); delay_ms(50); } while (motorLCurVal!=MOTOR_L_STOP && motorRCurVal!=MOTOR_R_STOP);}void setMotorSpeed(int byte){ if (byte >= MOTOR_L_MIN && byte <= MOTOR_L_MAX) { motorLTarVal = byte; do { if (motorLCurVal < motorLTarVal) { Sabertooth_uartSendByte(++motorLCurVal); } else { Sabertooth_uartSendByte(--motorLCurVal); } delay_ms(100); } while (motorLCurVal != motorLTarVal); } else if (byte >= MOTOR_R_MIN && byte <= MOTOR_R_MAX) { motorRTarVal = byte; do { if (motorRCurVal < motorRTarVal) { Sabertooth_uartSendByte(++motorRCurVal); } else { Sabertooth_uartSendByte(--motorRCurVal); } delay_ms(100); } while (motorRCurVal != motorRTarVal); }}/* This is weird and seems unecessarily complicated. Basically the same thing above I think. Not sure why it stopsthe motor before moving it as well, seems logically incorrect. Should move from CurSpeed -> TarSpeed, notCurSpeed -> Stop -> TarSpeed. Keeping this around incase I am wrong.void motorMoveMotor(int motorL, int motorR) // motorL and motorR are -1 for reverse, 0 for stop, 1 for forward{ motorStopMotor(); delay_ms(100); motorInt=(63*motorVal)/100; motorLTarVal=64+motorInt; if (motorL<0) { motorLTarVal=64-motorInt; } motorRTarVal=192+motorInt; if (motorR<0) { motorRTarVal=192-motorInt; } do { if (motorLCurVal<motorLTarVal) { motorLCurVal=motorLCurVal+1; } else if (motorLCurVal>motorLTarVal) { motorLCurVal=motorLCurVal-1; } motors_uartSendByte(motorLCurVal); delay_ms(50); if (motorRCurVal<motorRTarVal) { motorRCurVal=motorRCurVal+1; } else if (motorRCurVal>motorRTarVal) { motorRCurVal=motorRCurVal-1; } motors_uartSendByte(motorRCurVal); delay_ms(50); } while (motorLCurVal!=motorLTarVal && motorRCurVal!=motorRTarVal);}*/
/* NOTES: * 0-127 Motor Left (1-63: forward, 64: stop, 65-127: reverse) * 128-255 Motor Right (128-191: forward, 192: stop, 193-255: reverse) */ #include <GPSXClass.h>#include <SoftwareSerial.h>#include <LiquidCrystal.h>//#include <XBee.h>#include <Servo.h>#include <Sabertooth.h>// LCD SCREEN#define LCD_COLS 20#define LCD_ROWS 4#define BACKLIGHT_ON 'HIGH'#define BACKLIGHT_OFF 'LOW'// XBEE#define DATA_LED 10#define STATUS_LED 11#define ERROR_LED 12#define REMOTE_XBEE_ADDR 0x1874 //TODO#define RESPONSE_WAIT 5000#define DEBUG false// PS2 SEND#define TRIANGLE 256#define START 257#define L2 258#define R2 259#define JOYSTICK_LOW 90#define JOYSTICK_HIGH 160#define DELAY 100#define SERIAL_BPS 9600// GLOBAL VARIABLESLiquidCrystal lcd(12, 11, 5, 4, 3, 2); //TODO/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Initialize- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */void setup(){ initPSX(); //Get PS2 controller ready initLCD(); //Get LCD ready initXBee(); //Get XBee Wireless Transmitter ready}/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Main- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */void loop(){ //PS2 Controller Input readPS2Input(); delay(DELAY);}/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Helpers- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */void initPSX(){ PSX.mode(PSX_PAD1, MODE_ANALOG, MODE_LOCK); PSX.motorEnable(PSX_PAD1, MOTOR1_DISABLE, MOTOR2_DISABLE); // Poll current state once. PSX.updateState(PSX_PAD1);}void initLCD(){ lcd.begin(LCD_COLS, LCD_ROWS); lcd.clear(); lcd.setCursor(0,0); //lcd.print("Robot Started");}void initXBee(){ Serial.begin(9600);}void readPS2Input(){ Serial.begin(9600); PSX.updateState(PSX_PAD1); if(PRESSED_TRIANGLE(PSX_PAD1)) { if (DEBUG) Serial.println("Triangle pressed"); else sendData(TRIANGLE); } if(PRESSED_START(PSX_PAD1)) { if (DEBUG) Serial.println("Start pressed"); else sendData(START); } if(IS_DOWN_L2(PSX_PAD1)) { if (DEBUG) Serial.println("L2 down"); else sendData(L2); } if(IS_DOWN_R2(PSX_PAD1)) { if (DEBUG) Serial.println("R2 down"); else sendData(R2); } int leftStick = ANALOG_LEFT_Y(PSX_PAD1); int rightStick = ANALOG_RIGHT_Y(PSX_PAD1); if(leftStick < JOYSTICK_LOW) { if (DEBUG) { Serial.print("LEFT TRIGGER FORWARD: "); Serial.println(ANALOG_LEFT_Y(PSX_PAD1), DEC); } else sendData(map(leftStick, 0, JOYSTICK_LOW, 127, 65)); } if(leftStick > JOYSTICK_HIGH) { if (DEBUG) { Serial.print("LEFT TRIGGER BACKWARDS: "); Serial.println(ANALOG_LEFT_Y(PSX_PAD1), DEC); } else sendData(map(leftStick, JOYSTICK_HIGH, 255, 63, 1)); } if(rightStick < JOYSTICK_LOW) { if (DEBUG) { Serial.print("RIGHT TRIGGER FORWARDS: "); Serial.println(ANALOG_RIGHT_Y(PSX_PAD1), DEC); } else sendData(map(rightStick, 0, JOYSTICK_LOW, 255, 193)); } if(rightStick > JOYSTICK_HIGH) { if (DEBUG) { Serial.print("RIGHT TRIGGER BACKWARDS: "); Serial.println(ANALOG_RIGHT_Y(PSX_PAD1), DEC); } else sendData(map(rightStick, JOYSTICK_HIGH, 255, 191, 128)); }}void sendData(int sendVal){ Serial.print(sendVal, DEC);delay(10);}
/* This file has been auto-generated by WebbotLib tools V1.1 ** DO NOT MODIFY BY HAND ***/#ifndef _HARDWARE_H_#define _HARDWARE_H_#if !defined (_LIB_HARDWARE_C_) && !defined(_LIB_HARDWARE_CPP_)#define BUILDING_LIBRARY#define _LIB_HARDWARE_C_#endif#ifndef F_CPU#warning No CPU speed specified - assuming running at 16000000#define F_CPU 16000000#endif#if F_CPU != 16000000# warning "Board runs at 16000000 but you have defined a different value"#endif#if defined (__AVR_ATmega640__)#else# error You must set the device to the ATmega640#endif#define FLASH_SIZE 65536#define RAM_SIZE 8192#define EEPROM_SIZE 4096#define _NUM_PCINT_PINS 9// Include library files#include <libdefs.h>#include <core.h>#include <timer.h>#include <a2d.h>#include <rprintf.h>#include <led.h>#include <stdlib.h>#include <avr/eeprom.h>#include <switch.h>#include <errors.h>#include <uart.h>#include <segled.h>#include <Motors/DimensionEngineering/Sabertooth.h>#include <iopin.h>#include <servos.h>#include "lib/lib_timerdef.h"#include "lib/lib_iopins.h"#ifdef __cplusplusextern "C" {#endif// ------------------- uart1 -------------------extern MAKE_WRITER(uart1SendByte);extern MAKE_READER( uart1GetByte);// Create hardware UART uart1extern HW_UART _uart1;#define uart1 &_uart1#define UART1 uart1// ------------------- Xbee -------------------extern MAKE_WRITER(XbeeSendByte);extern MAKE_READER(XbeeGetByte);// Create hardware UART Xbeeextern HW_UART _Xbee;#define Xbee &_Xbee#define UART0 Xbee// ------------------- Sabertooth_uart -------------------extern MAKE_WRITER(Sabertooth_uartSendByte);// Create hardware UART Sabertooth_uartextern HW_UART _Sabertooth_uart;#define Sabertooth_uart &_Sabertooth_uart#define UART2 Sabertooth_uart// ----------- Define the ADC channels ----------#define ADC0 ADC_NUMBER_TO_CHANNEL(0)#define ADC1 ADC_NUMBER_TO_CHANNEL(1)#define ADC2 ADC_NUMBER_TO_CHANNEL(2)#define ADC3 ADC_NUMBER_TO_CHANNEL(3)#define ADC4 ADC_NUMBER_TO_CHANNEL(4)#define ADC5 ADC_NUMBER_TO_CHANNEL(5)#define ADC6 ADC_NUMBER_TO_CHANNEL(6)#define ADC7 ADC_NUMBER_TO_CHANNEL(7)#define ADC8 ADC_NUMBER_TO_CHANNEL(8)#define ADC9 ADC_NUMBER_TO_CHANNEL(9)#define ADC10 ADC_NUMBER_TO_CHANNEL(10)#define ADC11 ADC_NUMBER_TO_CHANNEL(11)#define ADC12 ADC_NUMBER_TO_CHANNEL(12)#define ADC13 ADC_NUMBER_TO_CHANNEL(13)#define ADC14 ADC_NUMBER_TO_CHANNEL(14)#define ADC15 ADC_NUMBER_TO_CHANNEL(15)extern const uint8_t NUM_ADC_CHANNELS;// ----------- My devices -----------------------extern SWITCH button;extern SEGLED led_display;extern MARQUEE marquee;#define Temp_sensor1 ADC0#define Temp_sensor2 ADC2#define Bat_monitor ADC4extern LED led_ext1;extern LED led_ext2;extern LED leds_int;extern SABERTOOTH_MOTOR motor_1;extern SABERTOOTH_MOTOR motor_2;extern SABERTOOTH_DRIVER Sabertooth;#define Remoteswitch_relay L6extern SERVO servo;extern SERVO_DRIVER Servo;#define Xbee5v E6void initHardware(void);#ifdef __cplusplus}#endif#endif// undefine all ports so the user cannot change them directly#undef PORTA#undef DDRA#undef PINA#undef PORTB#undef DDRB#undef PINB#undef PORTC#undef DDRC#undef PINC#undef PORTD#undef DDRD#undef PIND#undef PORTE#undef DDRE#undef PINE#undef PORTF#undef DDRF#undef PINF#undef PORTG#undef DDRG#undef PING#undef PORTH#undef DDRH#undef PINH#undef PORTJ#undef DDRJ#undef PINJ#undef PORTK#undef DDRK#undef PINK#undef PORTL#undef DDRL#undef PINL// Undefine timer registers to stop users changing them#undef TCNT0#undef TCCR0B#undef OCR0A#undef OCR0B#undef TCNT1#undef TCCR1B#undef OCR1A#undef OCR1B#undef OCR1C#undef TCNT2#undef TCCR2B#undef OCR2A#undef OCR2B#undef TCNT3#undef TCCR3B#undef OCR3A#undef OCR3B#undef OCR3C#undef TCNT4#undef TCCR4B#undef OCR4A#undef OCR4B#undef OCR4C#undef TCNT5#undef TCCR5B#undef OCR5A#undef OCR5B#undef OCR5C
First thing I did wrong, was I sent 0 as triangle, but my motors still should've turned regardless.
Is there a way to look at the output of a UART (Sabertooth) port? I can use an FTDI cable, cant I?
rprintf("\n motorRCurVal is: %d", motorRCurVal);delay_ms(100);//use this so it doesn't output a billion times per second
I have no idea what sending '0 as triangle' means lol
yeapRather than giving you the answer, I'll tell you how to debug software like this. What you need to do is add output data that you can see.Add in rprintf commands here and there in your code, and then view it with Hyperterminal using your FTDI cable. For example:
You can also use the numbered LED to show a certain number when it's running a certain subset of code. This lets you know what the software is doing behind the scenes.And just skimming through your code I noticed this very serious bug:int motorRTarVal;motorRTarVal=192+motorInt;The int type only ranges from −128 to 127, so having 192 + anything means your variable is going out of bounds.
The int type only ranges from −128 to 127, so having 192 + anything means your variable is going out of bounds.
#include "hardware.h"#define XBee_Controlled//#define USB_Controlled#define UART0_TX_BUFFER_SIZE 2#define UART0_RX_BUFFER_SIZE 2#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 0uint16_t motorLCurVal;uint16_t motorRCurVal;uint16_t motorLTarVal;uint16_t motorRTarVal;uint16_t motorVal;// Initialise the hardwarevoid appInitHardware(void) { initHardware(); #ifdef XBee_Controlled rprintfInit(XbeeSendByte); #endif}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ motorLCurVal = motorLTarVal = MOTOR_L_STOP; motorRCurVal = motorRTarVal = MOTOR_R_STOP;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { uint16_t tempbyte = NULL; #ifdef XBee_Controlled //tempbyte=XbeeGetByte; if(!uartReceiveBufferIsEmpty(UART0)) { tempbyte = uartGetByte(UART0); rprintf(“Value recieved is: %d \n”); delay_ms(200); } #endifif (tempbyte != NULL) { if (tempbyte >= MOTOR_L_MIN && tempbyte <= MOTOR_R_MAX) { setMotorSpeed(tempbyte); } else if (tempbyte==START) { //pin_low(Remoteswitch_relay); } else { motorStopMotor(); } delay_ms(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;}//motorXCurVal is the current speed.//motorXTarVal is where we want the speed to be.//motorVal, in this case, is running on a scale of 1 to 10. Thus, 1 is 10% of maximum //speed, 2 is 20%, and so on. NOT //USEDvoid motorStopMotor(){ do { if (motorLCurVal<MOTOR_L_STOP) { motorLCurVal=motorLCurVal+1; } else if (motorLCurVal>MOTOR_L_STOP) { motorLCurVal=motorLCurVal-1; } Sabertooth_uartSendByte(motorLCurVal); delay_ms(50); if (motorRCurVal<MOTOR_R_STOP) { motorRCurVal=motorRCurVal+1; } else if (motorRCurVal>MOTOR_R_STOP) { motorRCurVal=motorRCurVal-1; } Sabertooth_uartSendByte(motorRCurVal); delay_ms(50); } while (motorLCurVal!=MOTOR_L_STOP && motorRCurVal!=MOTOR_R_STOP);}void setMotorSpeed(uint16_t byte){ if (byte >= MOTOR_L_MIN && byte <= MOTOR_L_MAX) { motorLTarVal = byte; do { if (motorLCurVal < motorLTarVal) { Sabertooth_uartSendByte(++motorLCurVal); } else { Sabertooth_uartSendByte(--motorLCurVal); } delay_ms(100); } while (motorLCurVal != motorLTarVal); } else if (byte >= MOTOR_R_MIN && byte <= MOTOR_R_MAX) { motorRTarVal = byte; do { if (motorRCurVal < motorRTarVal) { Sabertooth_uartSendByte(++motorRCurVal); } else { Sabertooth_uartSendByte(--motorRCurVal); } delay_ms(100); } while (motorRCurVal != motorRTarVal); }}
Ah ok. I just hooked up my ftdi cable to my corresponding Xbee on the controller because in my code it says send rprintf to XbeeSendByte. It says "value received: -17404" Where the heck is that number coming from and how can I fix it?
I should probably set my rprintf output to UART3 because Xbees are half duplex, therefore how can it transmit and receive data at the same time, right?
Look at your rprintf statement:rprintf(“Value recieved is: %d \n”);and then look at mine:rprintf("\n motorRCurVal is: %d", motorRCurVal);
Error 11 is a receive buffer overflow (see the errors.h file in WebbotLib). This happens when you send a bunch of data but the mcu doesn't process it before the buffer overflows.Try increasing buffer size in Project Designer. If your baud isn't matching, the 'random junk' can quickly fill a small buffer. Have your mcu repeat back what it sees to verify baud (if you aren't sure).
Yeah right now I have my receive buffer and transmit buffer on the Xbee set to zero. What should I set it to and also should i set a buffer on the other UART ports as well?
Last question, currently my baud rate is at 9600, would increasing my baud rate help too?
#include "hardware.h"#define XBee_Controlled//#define USB_Controlled#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 0uint16_t motorLCurVal;uint16_t motorRCurVal;uint16_t motorLTarVal;uint16_t motorRTarVal;uint16_t motorVal;// Initialise the hardwarevoid appInitHardware(void) { initHardware(); #ifdef XBee_Controlled rprintfInit(uart3SendByte);delay_ms(100); #endif}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){rprintf("\nAxon Initiated.\n\n"); motorLCurVal = motorLTarVal = MOTOR_L_STOP; motorRCurVal = motorRTarVal = MOTOR_R_STOP;return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { uint16_t tempbyte = NULL; #ifdef XBee_Controlled //tempbyte=XbeeGetByte; if(!uartReceiveBufferIsEmpty(UART0)) { tempbyte = uartGetByte(UART0); rprintf(“\n tempbyte is: %d”, tempbyte); delay_ms(200); } #endifif (tempbyte != NULL) { if (tempbyte >= MOTOR_L_MIN && tempbyte <= MOTOR_R_MAX) { setMotorSpeed(tempbyte); } else if (tempbyte==START) { pin_low(Remoteswitch_relay); } else { motorStopMotor(); } delay_ms(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;}//motorXCurVal is the current speed. //motorXTarVal is where we want the speed to be.//motorVal, in this case, is running on a scale of 1 to 10. Thus, 1 is 10% of maximum //speed, 2 is 20%, and so on. NOT //USEDvoid motorStopMotor(){ do { if (motorLCurVal<MOTOR_L_STOP) { motorLCurVal=motorLCurVal+1; } else if (motorLCurVal>MOTOR_L_STOP) { motorLCurVal=motorLCurVal-1; } Sabertooth_uartSendByte(motorLCurVal); delay_ms(50); if (motorRCurVal<MOTOR_R_STOP) { motorRCurVal=motorRCurVal+1; } else if (motorRCurVal>MOTOR_R_STOP) { motorRCurVal=motorRCurVal-1; } Sabertooth_uartSendByte(motorRCurVal); delay_ms(50); } while (motorLCurVal!=MOTOR_L_STOP && motorRCurVal!=MOTOR_R_STOP);}void setMotorSpeed(uint16_t byte){ if (byte >= MOTOR_L_MIN && byte <= MOTOR_L_MAX) { motorLTarVal = byte; do { if (motorLCurVal < motorLTarVal) { Sabertooth_uartSendByte(++motorLCurVal); } else { Sabertooth_uartSendByte(--motorLCurVal); } delay_ms(100); } while (motorLCurVal != motorLTarVal); } else if (byte >= MOTOR_R_MIN && byte <= MOTOR_R_MAX) { motorRTarVal = byte; do { if (motorRCurVal < motorRTarVal) { Sabertooth_uartSendByte(++motorRCurVal); } else { Sabertooth_uartSendByte(--motorRCurVal); } delay_ms(100); } while (motorRCurVal != motorRTarVal); }}
#include "hardware.h"#define XBee_Controlled//#define USB_Controlled#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 0uint16_t motorLCurVal;uint16_t motorRCurVal;uint16_t motorLTarVal;uint16_t motorRTarVal;uint16_t motorVal;// Initialise the hardwarevoid appInitHardware(void) { initHardware(); #ifdef XBee_Controlled rprintfInit(debugSendByte);delay_ms(100); #endif}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){rprintf("\nAxon Initiated.\n\n"); motorLCurVal = motorLTarVal = MOTOR_L_STOP; motorRCurVal = motorRTarVal = MOTOR_R_STOP;return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) { uint16_t tempbyte = NULL; #ifdef XBee_Controlled //tempbyte=XbeeGetByte; if(!uartReceiveBufferIsEmpty(UART0)) { tempbyte = uartGetByte(UART0); delay_ms(200); } #endifif (tempbyte != NULL) { if (tempbyte >= MOTOR_L_MIN && tempbyte <= MOTOR_R_MAX) { setMotorSpeed(tempbyte);rprintf(“\n motorspeed is: %d”, tempbyte); } else if (tempbyte==START) { pin_low(Remoteswitch_relay); } else { motorStopMotor(); } delay_ms(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;}//code below by Tzankoff//motorXCurVal is the current speed.//motorXTarVal is where we want the speed to be.//motorVal, in this case, is running on a scale of 1 to 10. Thus, 1 is 10% of maximum //speed, 2 is 20%, and so on. NOT USEDvoid motorStopMotor(){ do { if (motorLCurVal<MOTOR_L_STOP) { motorLCurVal=motorLCurVal+1; } else if (motorLCurVal>MOTOR_L_STOP) { motorLCurVal=motorLCurVal-1; } Sabertooth_uartSendByte(motorLCurVal);rprintf("\n StopmotorLCurVal is: %d", motorLCurVal);delay_ms(100); if (motorRCurVal<MOTOR_R_STOP) { motorRCurVal=motorRCurVal+1; } else if (motorRCurVal>MOTOR_R_STOP) { motorRCurVal=motorRCurVal-1; } Sabertooth_uartSendByte(motorRCurVal);rprintf("\n StopmotorRCurVal is: %d", motorRCurVal); delay_ms(50); } while (motorLCurVal!=MOTOR_L_STOP && motorRCurVal!=MOTOR_R_STOP);}void setMotorSpeed(uint16_t byte){ if (byte >= MOTOR_L_MIN && byte <= MOTOR_L_MAX) { motorLTarVal = byte; do { if (motorLCurVal < motorLTarVal) { Sabertooth_uartSendByte(++motorLCurVal);rprintf("\n setSpeed++motorLCurVal is: %d", ++motorLCurVal); } else { Sabertooth_uartSendByte(--motorLCurVal);rprintf("\n setSpeed--motorLCurVal is: %d", --motorLCurVal); } delay_ms(100); } while (motorLCurVal != motorLTarVal); } else if (byte >= MOTOR_R_MIN && byte <= MOTOR_R_MAX) { motorRTarVal = byte; do { if (motorRCurVal < motorRTarVal) { Sabertooth_uartSendByte(++motorRCurVal);rprintf("\n setSpeed++motorRCurVal is: %d", ++motorRCurVal); } else { Sabertooth_uartSendByte(--motorRCurVal);rprintf("\n setSpeed--motorRCurVal is: %d", --motorRCurVal); } delay_ms(100); } while (motorRCurVal != motorRTarVal); }}
Axon Initiated. setSpeed--motorLCurVal is: 62 setSpeed--motorLCurVal is: 60 setSpeed--motorLCurVal is: 58 setSpeed--motorLCurVal is: 56 setSpeed--motorLCurVal is: 54 setSpeed--motorLCurVal is: 52 setSpeed--motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50WebbotLib Error:11 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50 setSpeed--motorLCurVal is: 48 setSpeed++motorLCurVal is: 50
/* This is weird and seems unecessarily complicated. Basically the same thing above I think. Not sure why it stopsthe motor before moving it as well, seems logically incorrect. Should move from CurSpeed -> TarSpeed, notCurSpeed -> Stop -> TarSpeed. Keeping this around incase I am wrong.void motorMoveMotor(int motorL, int motorR) // motorL and motorR are -1 for reverse, 0 for stop, 1 for forward{ motorStopMotor(); delay_ms(100); motorInt=(63*motorVal)/100; motorLTarVal=64+motorInt; if (motorL<0) { motorLTarVal=64-motorInt; } motorRTarVal=192+motorInt; if (motorR<0) { motorRTarVal=192-motorInt; } do { if (motorLCurVal<motorLTarVal) { motorLCurVal=motorLCurVal+1; } else if (motorLCurVal>motorLTarVal) { motorLCurVal=motorLCurVal-1; } motors_uartSendByte(motorLCurVal); delay_ms(50); if (motorRCurVal<motorRTarVal) { motorRCurVal=motorRCurVal+1; } else if (motorRCurVal>motorRTarVal) { motorRCurVal=motorRCurVal-1; } motors_uartSendByte(motorRCurVal); delay_ms(50); } while (motorLCurVal!=motorLTarVal && motorRCurVal!=motorRTarVal);}*/
#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
@Admin jwatte is 100% correct. An int is 16 bits on all avr compilers ie an int16_t.
Seems you are trying to convert Arduino code that only works with the Sabertooth into WebbotLib code? It doesn't work like that. In WebbotLib you set a drive speed from -127 (full reverse), 0=stop, +127=full fwd and WebbotLib turns it into the relevant numbers that are sent to the Sabertooth.Unlike Arduino this means you can swap the Sabertooth to a different controller and not have to change your code.
//for triangleif(variableA == 50 && variableB == 53 && variableC == 54){do_something();}
#define TRIANGLE 256#define START 257#define L2 258#define R2 259
triangle- 50, 53,54start- 50, 53, 55right trigger- 50, 53, 57left trigger- 50, 53, 56left joystick all the way forward- 49, 50, 55right joystick all the way forward- 50, 53, 53right joystick all the way down- 49, 50, 56left joystick all the way down- 49, 49, 49 (may just be 49, 49 couldnt really tell)