Show Posts
Pages: [1] 2 3 ... 6
1  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 26, 2010, 09:29:02 am
Thanks Paul, I'll edit my processing code.

[glow]For the Arduino code ( all keypress responded ,but the Q key[/glow])

#include <SoftwareSerial.h>

// Labels for use with the Sabertooth 2x5 motor controller

// Digital pin 13 is the serial transmit pin to the
// Sabertooth 2x5
#define SABER_TX_PIN 13

// NOT USED (but still init'd)
// Digital pin 12 is the serial receive pin from the
// Sabertooth 2x5
#define SABER_RX_PIN 12

// Set to 9600 through Sabertooth dip switches
#define SABER_BAUDRATE 9600

// Simplified serial Limits for each motor
#define SABER_MOTOR1_FULL_FORWARD 127
#define SABER_MOTOR1_FULL_REVERSE 1
#define SABER_MOTOR1_FULL_STOP 64


#define SABER_MOTOR2_FULL_FORWARD 255
#define SABER_MOTOR2_FULL_REVERSE 128
#define SABER_MOTOR2_FULL_STOP 192


// Motor level to send when issuing the full stop command
#define SABER_ALL_STOP 0


SoftwareSerial SaberSerial = SoftwareSerial( SABER_RX_PIN, SABER_TX_PIN );

void initSabertooth( void )
{
 // Init software UART to communicate
 // with the Sabertooth 2x5
 pinMode( SABER_TX_PIN, OUTPUT );

 SaberSerial.begin( SABER_BAUDRATE );

 // 2 second time delay for the Sabertooth to init
 delay( 2000 );
 // Send full stop command
 setEngineSpeed( SABER_ALL_STOP );
}

/************************************************** ***
* setEngineSpeed
*
* Inputs - cSpeed_Motor1 - Input a percentage of full
* speed, from -100 to +100
*
************************************************** ***/
void setEngineSpeed( signed char cNewMotorSpeed )
{
 unsigned char cSpeedVal_Motor1 = 0;

 unsigned char cSpeedVal_Motor2 = 0;

 // Check for full stop command
 if( cNewMotorSpeed == 0 )
 {
   // Send full stop command for both motors
   SaberSerial.print( 0, BYTE );

   return;
 }

 // Calculate the speed value for motor 1
 if( cNewMotorSpeed >= 100 )
 {
   cSpeedVal_Motor1 = SABER_MOTOR1_FULL_FORWARD;

   cSpeedVal_Motor2 = SABER_MOTOR2_FULL_FORWARD;
 }
 else if( cNewMotorSpeed <= -100 )
 {
   cSpeedVal_Motor1 = SABER_MOTOR1_FULL_REVERSE;

   cSpeedVal_Motor2 = SABER_MOTOR2_FULL_REVERSE;
 }
 else
 {
   // Calc motor 1 speed (Final value ranges from 1 to 127)
   cSpeedVal_Motor1 = map( cNewMotorSpeed,
                          -100,
                           100,
                           SABER_MOTOR1_FULL_REVERSE,
                           SABER_MOTOR1_FULL_FORWARD );

    // Calc motor 2 speed (Final value ranges from 128 to 255)
    cSpeedVal_Motor2 = map( cNewMotorSpeed,
                           -100,
                            100,
                            SABER_MOTOR2_FULL_REVERSE,
                            SABER_MOTOR2_FULL_FORWARD );
 }

 // Fire the values off to the Sabertooth motor controller
 SaberSerial.print( cSpeedVal_Motor1, BYTE );
 SaberSerial.print( cSpeedVal_Motor2, BYTE );
}

void setup( )
{
 initSabertooth( );
 Serial.begin(9600); // Code that made the keypress work
}

//void control( )
//{
//  // Full stop
//  setEngineSpeed( 0 );
//
//  // Half reverse
//  setEngineSpeed( -50 );
//
//  // Full reverse
//  setEngineSpeed( -100 );
//
//  // Half forward
//  setEngineSpeed( 50 );
//
//  // Full forward
//  setEngineSpeed( 100 );
//}

void setEngineSpeedDir( signed char cNewMotorSpeedDir )
{
 unsigned char cSpeedValDir_Motor1 = 0;

 unsigned char cSpeedValDir_Motor2 = 0;

 if( cNewMotorSpeedDir >= 100 )
 {
   cSpeedValDir_Motor1 = SABER_MOTOR1_FULL_FORWARD; // GO RIGHT

   cSpeedValDir_Motor2 = SABER_MOTOR2_FULL_STOP;
 }
 else if( cNewMotorSpeedDir <= -100 )
 {
   cSpeedValDir_Motor1 = SABER_MOTOR1_FULL_STOP; // GO LEFT

   cSpeedValDir_Motor2 = SABER_MOTOR2_FULL_FORWARD;
 }
 else
 {
   // Calc motor 1 speed (Final value ranges from 64 to 127)
   cSpeedValDir_Motor1 = map( cNewMotorSpeedDir,
                             -100,
                              100,
                              SABER_MOTOR1_FULL_STOP,
                              SABER_MOTOR1_FULL_FORWARD );

   // Calc motor 2 speed (Final value ranges from 192 to 255)
   cSpeedValDir_Motor2 = map( cNewMotorSpeedDir,
                             -100,
                              100,
                              SABER_MOTOR2_FULL_FORWARD,
                              SABER_MOTOR2_FULL_STOP);
 }

 // Fire the values off to the Sabertooth motor controller
 SaberSerial.print( cSpeedValDir_Motor1, BYTE );

 SaberSerial.print( cSpeedValDir_Motor2, BYTE );
}

//void turn ( )
//{
//  // Turn left
//  setEngineSpeedDir( -100 );
//
//  // Turn right
//  setEngineSpeedDir( 100 );
//}




void loop()
{
// setEngineSpeedDir( -100 );
 //delay( 5000 );
 //setEngineSpeed( 0 );

 
 
 
  signed char traverse;
  signed char negotiate;

  if(Serial.available()>0)
  {
    int data = Serial.read();
//
//    digitalWrite(buttonPin,LOW);

    switch(data)
    {
      case'w':traverse = 100;break; //full forward
      case's':traverse = -50;break; // half reverse
      case'q':traverse = 0;break; // Stop,[glow] Won't respond ( Motors won't stop)[/glow]
      case'a':negotiate = -100;break; // left
      case'd':negotiate = 100;break; // right
    }

    setEngineSpeed( traverse );
    setEngineSpeedDir( negotiate );
  }
}

Regards
2  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 26, 2010, 04:31:51 am
Hi Paul,

I can't possibly get my Processing code to work, now the error is:

processing.app.debug.RunnerException: The function print(char) does not exist.
      at processing.app.Sketch.placeException(Sketch.java:1543)
      at processing.app.debug.Compiler.compile(Compiler.java:149)
      at processing.app.Sketch.build(Sketch.java:1573)
      at processing.app.Sketch.build(Sketch.java:1553)
      at processing.app.Editor$DefaultRunHandler.run(Editor.java:1485)
      at java.lang.Thread.run(Thread.java:619)

[glow]My Processing Code:[/glow]

void keyPressed()
{

switch(key)
{
 case('w'):
 case('W'):
 case('d'):
 case('D'):
 case('s'):
 case('S'):
 case('a'):
 case('A'):
 case('q'):
 case('Q'):
    myPort.print(key);
    break;
    //Serial myPort;
}
}

import processing.serial.*;

Serial myPort;
//println(Serial.list());

void setup (){

myPort = new Serial(this, Serial.list()[0], 9600);
}
void draw(){

}


I got impatient with processing that I tried to go back to my arduino code.. And luckily I made the keypress work.. I added Serial.begin (9600); in my setup function.

The only odd thing is that the stop button Q wont respond, I don't get it… Is there a possible way in the arduino coding that when I release the W ( forward button) then the motor will also cease going forward?  Because when I press/ send the keypress button in the serial monitor it goes on until a new command is sent.. Help



Regards
3  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 24, 2010, 12:40:30 am
Paul,

My Processing sketch still won't compile:

Still with the same error of:










processing.app.debug.RunnerException: expecting EOF, found 'myPort'
      at processing.app.Sketch.preprocess(Sketch.java:1326)
      at processing.app.Sketch.preprocess(Sketch.java:1205)
      at processing.app.Sketch.build(Sketch.java:1568)
      at processing.app.Sketch.build(Sketch.java:1553)
      at processing.app.Editor$DefaultRunHandler.run(Editor.java:1485)
      at java.lang.Thread.run(Thread.java:619

//void setup (){



void keyPressed()
{

switch(key)
{
  case('w'):
  case('W'):
  case('d'):
  case('D'):
  case('s'):
  case('S'):
  case('a'):
  case('A'):
  case('q'):
  case('Q'):
     myPort.print(key);
     break;
     Serial myPort;
}
}

import processing.serial.*;

Serial myPort;
//println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);

void draw(){

}

//}

I already placed an empty draw function as you advised, but still with same error, but when I try to place a setup function, it has an error or unexpected void...

Please help :'(

Regards

4  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 22, 2010, 08:12:44 am
Paul,

Sorry to bother you again,but I'm already pulling my hair off because of the expecting EOF, found 'myPort' problem when I run my processing code


processing.app.debug.RunnerException: expecting EOF, found 'myPort'
      at processing.app.Sketch.preprocess(Sketch.java:1326)
      at processing.app.Sketch.preprocess(Sketch.java:1205)
      at processing.app.Sketch.build(Sketch.java:1568)
      at processing.app.Sketch.build(Sketch.java:1553)
      at processing.app.Editor$DefaultRunHandler.run(Editor.java:1485)
      at java.lang.Thread.run(Thread.java:619)

[[glow]highlight]I already verified that 0 is my COM 5 [/glow]



5  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 20, 2010, 07:37:48 pm
Hi Paul,

So how will I run processing to arduino? I will just compile my sketches for my processing and arduino and then upload my arduino sketch to the board?

[glow]My Arduino Code ( edited keypress part only, the others are same)[/glow]

void loop()
{
 signed char traverse;
  signed char negotiate;

 if(Serial.available()>0)
 {
    int data = Serial.read();

   digitalWrite(buttonPin,LOW);

   switch(data)
   {  // key is from the Processing keypress
      case'w':traverse = 100;break; //full forward  
      case's':traverse = -50;break; // half reverse
     case'q':traverse = 0;break; // Stop
      case'a':negotiate = -100;break; // left
      case'd':negotiate = 100;break; // right
    }

    setEngineSpeed( traverse );
    setEngineSpeedDir( negotiate );
  }
}


[glow]My Processing Code: ( edited)[/glow]

void keyPressed()
{
 switch(key)
{
   case('w'):
   case('W'):
   case('d'):
   case('D'):
   case('s'):
   case('S'):
   case('a'):
   case('A'):
   case('q'):
   case('Q'):
      myPort.print(key);
      break;
 }
}

import processing.serial.*;


Serial myPort;


println(Serial.list());


myPort = new Serial(this, Serial.list()[0], 9600); // I will edit
  • which ever is for COM 5 which I saw in my Arduino IDE..



Regards
6  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 19, 2010, 09:42:40 am
Noted.. I will link it all and update you.

Thanks
7  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 19, 2010, 09:39:06 am
So myPort.write(); So I will just leave it empty? Assuming it already sent data to COM 5.. ?
8  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 19, 2010, 08:41:04 am
Paul,

So in the Arduino:

switch(data)
{
   case 'w':
      // Do something
      break;
// Add remaining cases for 'a', 's', 'd', and 'q'
}


For the Processing

void keyPressed()
{
  switch(key)
 {
    case('w'):
    case('W'):
    case('d'):
    case('D'):
    case('s'):
    case('S'):
    case('a'):
    case('A'):
    case('q'):
    case('Q'):
       myPort.print(key);
       break;
  }
}

import processing.serial.*;


Serial myPort;


println(Serial.list());


myPort = new Serial(this, Serial.list()[0], 9600); // I will edit
  • which ever is for COM 5 which I saw in my Arduino IDE..

myPort.write(key);


Am I on the right track?



9  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 19, 2010, 01:44:53 am
Hi Paul,

I wish to simmulate what this code: http://wiki.processing.org/w/W-A-S-D_control_keyboard_input  with keyrelease and keypress
to my motor control using processing to arduino…

Will my codes below work? I did everything as said on http://www.arduino.cc/playground/Interfacing/Processing , but how will I connect processing to arduino ( what sketch to be typed)?


My Arduino Code ( part to be applied): (not sure about the key part)

void loop()
{
 
 
  
  
  
 signed char traverse;
  signed char negotiate;

 if(Serial.available()>0)
 {
    int data = Serial.read();

   //digitalWrite(buttonPin,LOW);

   switch(data)
   {  // key is from the Processing keypress
      case'key':traverse = 100;break; //full forward  
      case'key':traverse = -50;break; // half reverse
     case'key':traverse = 0;break; // Stop
      case'key':negotiate = -100;break; // left
      case'key':negotiate = 100;break; // right
    }

    setEngineSpeed( traverse );
    setEngineSpeedDir( negotiate );
  }
}


My Processing Code: I'm not sure on the Serial.list()[0]



import processing.serial.*;
int result;

 
void setup()
{

}
 

 
void keyPressed(){
  switch(key) {
    case('w'):case('W'):result |=FORWARD;break;
    case('d'):case('D'):result |=RIGHT;break;
    case('s'):case('S'):result |=REVERSE;break;
    case('a'):case('A'):result |=LEFT;break;
    case('q'):case('Q'):result |=STOP;break;
      
  }
}
 
void keyReleased(){  
  switch(key) {
    case('w'):case('W'):result ^=FORWARD;break;
    case('d'):case('D'):result ^=RIGHT;break;
    case('s'):case('S'):result ^=REVERSE;break;
    case('a'):case('A'):result ^=LEFT;break;
    case('q'):case('Q'):result ^=STOP;break;
  }
}





import processing.serial.*;


Serial myPort;


println(Serial.list());


myPort = new Serial(this, Serial.list()[0], 9600);

myPort.write(key);


Hope for your support
10  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 18, 2010, 04:42:49 am
Thanks Paul it's clearer now…I will try it and update you.
11  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 18, 2010, 04:28:40 am
Paul,

Sorry, but It's not quite clear to me..

 So I will use the serial.write command in Processing that is linked with the keypressed () then on the arduino, I will use serial.read() and link it with the setEngineSpeed( traverse ) and setEngineSpeedDir( negotiate )? Is it correct?

Regards
12  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 17, 2010, 07:49:47 pm
Hi Paul,

I just downloaded the processing loader/ compiler, but how can I connect it to the arduino code? For it to read my keyboard inputs and send data to my motor controller via my arduino?

Is it possible for my case? Sorry Its my first time to see processing

Regards
13  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 17, 2010, 06:05:51 pm
Hi Paul,

I'm quite interested with the Microsoft Visual Studio that creates C++ or C# applications that can capture keystrokes, and send them to the serial port....

I'm just not sure how to set this up both software and hardware so that it can communicate with my arduino. Do you have samples?


For the Processing, I found this code: http://wiki.processing.org/w/W-A-S-D_control_keyboard_input ,but how can I incorporate it with my arduino? for the control?



Regards
14  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 17, 2010, 09:30:10 am
My only application is arduino 019 compiler/loader.. What applications captures the keypresses( using laptop keyboard)?
15  Forum 2005-2010 (read only) / Troubleshooting / Re: Sabertooth 2x25 Simpified Serial Mode ( Tank Style on: October 17, 2010, 08:39:33 am
Hey Paul,

I commented out the keypress part because it does not respond to the keys when pressed, so I tried to assign the specific chars to the motor and it worked fine.

My setup is: 2 motors, batteries, sabertooth ( motor controller), and the arduino.. so I want it to respond to the keyboard press on my computer, but it won't..I don't know why.

any ideas?

Regards
Pages: [1] 2 3 ... 6