hi all robot builders, i am new to the botboarduino i have used arduino in the past, but not this type i was whating to know to set the botboard up in code. So that i could use all the ps2 outputs to control the robot i have seen forms for the botboard 2 but not to meany on botboardunio if someone could help me figure this out i would be thankfull :mrgreen: .
What kind of robot? We have several tutorials using the Botboarduino and the PS2 controller.
Its a outdoor robot that im making from a kit that i got for a gift its a platform from andymark i have tow hb25 moter controlers two cim motors. I order ur botboard and ps2 controler and need to know how to wright the code to convert the controles to on and off comands and thats it. For now
The part that idont know how to do in thecode is how to have it read the inputs form the ps2 controler and the convert it to drive and stear. turn cam on and off turn light on and off.i am looking at post that people have used and i what to learn. if someone could show me were to look for examples. i what to use the full benafit of the ps2 controler. will i need to use a servo board for the full control? 8)
There are several examples of programs running on BotBoarduino that use the ps2, including hex robots, brats and rovers… One I did awhile ago for rover is in thread viewtopic.php?t=7806&p=77477#p77477
Kurt
Download the PS2X Arduino library found here
This library is what we use in all of our code for the PS2 controller. This library also includes an example which demonstrates every function of the library.
Thanks Dev that will help me a lot when i get the board, How do i use this to set output for motors and lights., and assigning the stick up to drive forward and stick left turn left? If I’m making sense it might be right in front of me and I’m blind, and don’t see it is there a outline on how to arsing this stuff some were.
It is difficult to give very much advice here as you have not provided any details. When you mention Motors, are you talking about servos or some other form of motor. Some motors that are used on Rovers for example typically take some other hardware. This could be in the form of a shield like lynxmotion.com/p-576-saberto … oller.aspx. When you say turn on lights? are you talking about the built-in leds, external leds or some other types of lights?
Have you looked at the thread I mentioned in the previous post? It had an Arduino controlling a Rover or Tri-track using a Basic Micro Roboclaw for the motors. Most of the code should also work with a Sabertooth motor controller.
To turn on the LEDs of the BotBoarduino, you can simply set the appropriate IO line high or low depending if you wish to turn it on or off. It is as simple as doing something like:
ps2x.read_gamepad();
if (ps2x.ButtonPressed(PSB_L1)) {// L1 Button Test
digitalWrite(7, !digitalWrite(7)); // Toggle pin 7 which is one of the LEDS...
}
...
This should toggle one of the LEDs on the board when you press the L1 button on the PS2…
Good Luck
Kurt
can some one write me a code that uses the left joystick to go left and right forward and back. I think seeing jest that little bit will get me started. Sorry to sound lazy but if i see a simple code it will help me i jest need to see how it layed out.
I could write a simple example but you need to give us more details on the motors…
The HB-25 is a servo pulse type motor controller. I grabbed the following from the data sheet…
Pulse Input: 1.0ms Full Reverse, 1.5ms Neutral (off), 2.0ms Full Forward
Pulse Refresh Rate: Single Pulse Operation
Modes: Single/Dual Motor Control
I don’t have two HB-25s to test this on but I checked the output on a scope and it seems to be correct.
/*
This Program is an example of how to control a tank style robot using the Left analog
stick of a PS2 controller. This code is set up to control two Parrelax HB-25 motor
controllers in the Daisy-chain Mode 2 setup using just one IO pin.
Connect the first HB-25 to digital pin 2
The PS2 controller should be connected as follows:
CLK - Digital pin 9
CMD - Digital pin 7
ATT - Digital pin 8
DAT - Digital pin 6
The JPU jumper on the BotBoarduino should be installed.
By Devon Simmons
*/
#include <PS2X_lib.h>
PS2X ps2x; // create PS2 Controller Class
#define Deadzone 10
#define motor_pin 2
void setup()
{
//Open the Serial port for debugging
Serial.begin(115200);
//Create the Variables for the PS2 controller error checking
int error = 0;
byte type = 0;
byte vibrate = 0;
error = ps2x.config_gamepad(9,7,8,6, true, true); //setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
if(error == 0)
Serial.println("Found Controller, configured successful");
else if(error == 1)
Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");
else if(error == 2)
Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");
else if(error == 3)
Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
type = ps2x.readType();
switch(type)
{
case 0:
Serial.println("Unknown Controller type");
break;
case 1:
Serial.println("DualShock Controller Found");
break;
case 2:
Serial.println("GuitarHero Controller Found");
break;
}
pinMode(motor_pin, OUTPUT); //Set the Motor pin to an OUTPUT
}
//This function generates pulses for two HB-25 controllers in the Daisy-chained Mode2 setup
void driveMotors(int m1, int m2) //input range from 1ms - 2ms
{
digitalWrite(motor_pin, HIGH);
delayMicroseconds(constrain(m1, 1000, 2000));
digitalWrite(motor_pin, LOW);
delayMicroseconds(1100);
digitalWrite(motor_pin, HIGH);
delayMicroseconds(constrain(m2, 1000, 2000));
digitalWrite(motor_pin, LOW);
delayMicroseconds(5250);
}
void loop()
{
ps2x.read_gamepad(false, 0); //Must call this at least every second or the controller will fall out on analog mode
int LSY = 128 - ps2x.Analog(PSS_LY); //Adjust range to -128 through 128
int LSX = ps2x.Analog(PSS_LX) - 128; //Adjust range to -128 through 128
int Pulse1, Pulse2, V, W; //Create the variables for the math
//Filter the joystick values
if(LSY < Deadzone && LSY > -Deadzone)
LSY = 0;
if(LSX < Deadzone && LSX > -Deadzone)
LSX = 0;
//This is the math that takes our joystick input and converts it to pulses for each motor
V = (128 - abs(LSX)) * (LSY/128) + LSY;
W = (128 - abs(LSY)) * (LSX/128) + LSX;
Pulse1 = map((V+W)/2, -128, 128, 1000, 2000);
Pulse2 = map((V-W)/2, -128, 128, 1000, 2000);
driveMotors(Pulse1, Pulse2); //Send the pulses to the motor controller
}
Devon, Looks good to me. When I looked at the motor controller spec, it more or less said that it’s purpose was to make the motors look like continuous rotation servos.
So I was going to suggest that he simply use the Arduino servo library. To do this he would simply need to call the attach method in the init for the two pins that they are attached to. And in the loop function call the writeMicroseconds method to set the motor speeds…
Kurt
Using this method not only uses just one pin but it also doesn’t require an interrupt like the Servo library does. Plus, why include an entire library when an 11 line function can get the job done just as well
Actually to me it depends on what the goals are for the program…
If that is all you want the program to do, then I totally agree with you. But if for example you are plan to expand the program to do other things like manipulate some servos for an arm, or gripper, or… Or maybe read a few sensors… Than the servo library takes care of issues, like outputting the pulses at the right time… Also I hate just spinning in a waitMicroseconds when the processor could be free to do something else
But again,
Jest got the board and tried to upload the program and it said (Ps2x does not name type) ? what does that mean? it highlights ps2x ps2x;//create ps2 controller class.
Sounds like it can’t find the PS2X_lib library. Under the Sketch tab, “import library”, there need to be a PS2X_lib directory with PS2X_lib.cpp and .h files.
Alan KM6VV
You need to download the PS2X library and put it in the libraries folder of the Arduino IDE
ok call me slow but, i downloaded the ps2x lib and it still is saying the same thing any clue where i went wrong?
Assuming you have the library unzipped and placed in an appropriate area. Such as the libraries folder of the Arduino IDE or in the Library folder of your Arduino Sketchbook. In my case on my machine: C:\Users\Kurt\Documents\Arduino\libraries (In your case you would need to change Kurt to your user name…). For platforms other than windows, this again is wherever the IDE points for your sketchbook…
Then with the sketch open in the IDE. go to the Sketch menu, find the Import Library Menu item and in their select the PS2X_lib menu item, which will add an include to the start of your sketch. Than try to compile your program.
Kurt