Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: PS2 controller RC Car code problem. on: September 22, 2011, 05:51:18 am
Quote
Does it make a difference?
Yes - a whole lot less typing.

It didn't strike in my mind.

Thank You
2  Using Arduino / Programming Questions / Re: PS2 controller RC Car code problem. on: September 22, 2011, 12:28:04 am
Does it make a difference?

Thank you anyway
3  Using Arduino / Programming Questions / Re: PS2 controller RC Car code problem. on: September 17, 2011, 06:15:52 am
Thank you.. It works like a gem.
4  Using Arduino / Programming Questions / Re: PS2 controller RC Car code problem. on: September 17, 2011, 04:16:19 am
I have put an 'if' statement so that if the values are between -10 and 30 convert it into zero.
But what should I put in the 'Else' statement?
I have added a screenshot.

CODE:
Code:
#include <PS2X_lib.h>

PS2X ps2x;

//int Lp = 7;
//int Ln = 4;
//int Rp = 8;
//int Rn = 12;
int El = 11;
int Er = 9;
int right_speed = 0;
int left_speed = 0;

void setup () {
  ps2x.config_gamepad(2,6,4,7, true, true);
  //pinMode (Lp, OUTPUT);
  //pinMode (Ln, OUTPUT);
  //pinMode (Rp, OUTPUT);
  //pinMode (Rn, OUTPUT);
  pinMode (El, OUTPUT);
  pinMode (Er, OUTPUT);
 
  digitalWrite (El,LOW);
  digitalWrite (Er,LOW);
  Serial.begin(9600);
}

void loop () {
  ps2x.read_gamepad();
  left_speed = ps2x.Analog(PSS_LY);
  right_speed = ps2x.Analog(PSS_RY);
  left_speed = 255 - left_speed;
  right_speed = 255 - right_speed;
  left_speed = map(left_speed, 0, 255, -255, 255);
  right_speed = map(right_speed, 0, 255, -255, 255);
  if(-10<=left_speed<=30) {
    left_speed = 0;
  }
  //WHAT SHOULD I PUT IN THE ELSE STATEMENT??
  Serial.print("Left Joystick Value: ");
  Serial.print(left_speed);
  Serial.print("\t");
  Serial.print("Right Joystick Value: ");
  Serial.println(right_speed);
 
  if(ps2x.Button(PSB_L1) && ps2x.Button(PSB_R1)) {
    analogWrite(Er, right_speed);
    analogWrite(El, left_speed);
  }
 
  else {
    analogWrite(Er, 0);
    analogWrite(El, 0);
  }
}

Thanks in advance.
5  Using Arduino / Programming Questions / Re: PS2 controller RC Car code problem. on: September 16, 2011, 11:50:59 am
You're mapping the whole range of the stick to +/- 255, so just take the centre of the original range, say 128, and put a band of +/- 10 around that that maps to zero.

How should I do that? Please Help
6  Using Arduino / Programming Questions / Re: PS2 controller RC Car code problem. on: September 16, 2011, 11:40:50 am
Can't you just program in a dead zone around stick-centre?

Sorry didn't get that what should I do?
7  Using Arduino / Programming Questions / PS2 controller RC Car code problem. on: September 16, 2011, 09:48:10 am
Hey guys,

I am trying to make a RC controlled car using Arduino and a PS2 DualShock Joystick.

I am using Bill Porter's PS2X Library: http://www.billporter.info/playstation-2-controller-arduino-library-v1-0/ to get the readings form the controller and it works perfectly.
I am using the controllers left and right joysticks to control the PWM of the left and right motors.

The only problem I am suffering from is that when the joysticks are in the rest position (i.e. When I am not moving the joysticks) the values are unstable.
I have attached a picture of the Serial Monitor with the joystick readings in the rest position.
Due to these reading the motors move even when I am not moving the joystick.

The Code :
Code:
#include <PS2X_lib.h>

PS2X ps2x; //initialize controller

//int Lp = 7;
//int Ln = 4;
//int Rp = 8;
//int Rn = 12;
int El = 11;
int Er = 9;
int right_speed = 0;
int left_speed = 0;

void setup () {
  ps2x.config_gamepad(2,6,4,7, true, true); //controller pins
  //pinMode (Lp, OUTPUT); //motor pins
  //pinMode (Ln, OUTPUT);
  //pinMode (Rp, OUTPUT);
  //pinMode (Rn, OUTPUT);
  pinMode (El, OUTPUT);
  pinMode (Er, OUTPUT);
  
  digitalWrite (El,LOW);
  digitalWrite (Er,LOW);
  Serial.begin(9600);
}

void loop () {
  ps2x.read_gamepad();
  left_speed = ps2x.Analog(PSS_LY); //Left Y-Axis
  right_speed = ps2x.Analog(PSS_RY); //Right Y-Axis
  left_speed = 255 - left_speed;
  right_speed = 255 - right_speed;
  left_speed = map(left_speed, 0, 255, -255, 255);
  right_speed = map(right_speed, 0, 255, -255, 255);
  Serial.print(left_speed);
  Serial.print("\t");
  Serial.println(right_speed);
  
  if(ps2x.Button(PSB_L1) && ps2x.Button(PSB_R1)) {  //when L1 and R1 are pressed-drive motors
    analogWrite(Er, right_speed);
    analogWrite(El, left_speed);
  }
  
  else {
    analogWrite(Er, 0);
    analogWrite(El, 0);
  }
}

How should I modify the code so that the values of the rest position can be zero?

Thank you in advance,
SolidSnake31295
8  Using Arduino / Programming Questions / Re: beginner programming problems on: September 15, 2011, 12:05:55 pm
I thought he was talking about two different errors.  I was talking about the first, which I gathered wasn't part of the library problem.

Sorry I didn't see that. Its an error in his code. @angleofphase you need to post your code.
9  Using Arduino / Programming Questions / Re: Making Serial.print() to echo back on: September 15, 2011, 11:27:17 am
Code:
char inByte;  // incoming serial byte

void setup() {
// put your setup code here, to run once:
  Serial.begin(9600);          // serial communication baud rate
  }


void loop() {
// while loop begins here, continous loop:
  if (Serial.available()) {    // check for incoming data --> if available
  inByte = Serial.read();      // store incoming data
  Serial.print(inByte);        // echo back the data
}

}

This code should get you going....
10  Using Arduino / Programming Questions / Re: beginner programming problems on: September 15, 2011, 11:24:12 am
Variable scope has to do with where, in which functions, and when a variable exists.  For instance, if you declare a variable inside a function, then it can only be used inside that function.

Google C++ and scope and you should find more than you ever wanted to know.

Lol, you don't need to do that just download and install the library and you'l be fine.
11  Using Arduino / Programming Questions / Re: beginner programming problems on: September 15, 2011, 10:43:50 am
you 1st need to download and install the library

you can do that by downloading it from here: http://letsmakerobots.com/node/12336

Extract it and copy paste the VirtualWire folder in your arduino/libraries folder

Hope it helps...

12  Using Arduino / Installation & Troubleshooting / Re: Can't seem to get it to work on Windows 7 64x on: September 14, 2011, 01:37:45 pm
What is the MAIN difference between Uno and Duemilanove?
now that i have an uno

I was thinking that it was his first arduino... :/
13  Using Arduino / Installation & Troubleshooting / Re: Can't seem to get it to work on Windows 7 64x on: September 14, 2011, 09:55:00 am
I had the same problem...

Here's the solution:
Download the .rar from the link.
Extract it.
Connect Arduino to your PC.
Run CDM 2.04.16.exe
Check Device Manager, It should show USB Serial Port under COM PORTS.
Open Arduino IDE select the board and the COM PORT.

It worked for me.
Hope this helps.

Link: http://www.sendspace.com/file/b3qv3k
14  Topics / Robotics / Re: Grig & Maze Solving Robot on: September 11, 2011, 01:31:57 am
Lol... IIT Techfest... iNEXUS, NO MAN'S LAND..
15  Using Arduino / Installation & Troubleshooting / Re: How to emulate a ARDUINO without it.???? on: September 09, 2011, 12:47:06 pm
Be more specific.... What do you want to do with the emulator? Why you want to emulate the Arduino?

Google "Arduino Emulator" and you'll get plenty of results.
Also, the old arduino forum has many topics regarding this.

You may also try these:
http://hewgill.com/journal/entries/507-emulino-arduino-cpu-emulator
http://mtifall09.wordpress.com/2009/09/11/arduino-emulator/
http://durbn.net/blog/1-19-2011-emulating-arduino-0

Hope it helps.......
Pages: [1] 2 3