Hey All,
I am still a newbie in Arduino and would very appreciate help please. I need to (for a competition I am in) program my vehicle to run: four motors (one in each wheel), a controller (preferably and Xbox or Playstation controller), and four wheel steer with two servos. I would also like to learn how to read inputs from my dc motor (with the encoder) to implement a basic traction control.
As apart of the competition (Land Rover 4x4 in schools), we have to have two basic functions that need to be coded, they are to have a light sensor that reads the lux level to turn a set of lights on if it gets below a certain light level (determined by the competition technical regulations document) and a tilt sensor to read the angle the vehicle is tilted on, and then set a tone off when it gets above approx. 22 degrees from horizontal. The code I just used for the last competition just gone is below (it is very basic):
int led = 13;
int tiltSensor = A0;
int angle = 0;
int lightSensor = A3;
int lightLevel = 0;
int buzzer = 11;
void setup()
{
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop()
{
tiltCode();
lightSensorCode();
}
void tiltCode()
{
angle = analogRead(tiltSensor);
if(angle > 370 || angle < 280)
{
tone(buzzer, 1000);
}
else
{
noTone(buzzer);
}
}
void lightSensorCode()
{
lightLevel = analogRead(lightSensor);
Serial.println(lightLevel);
if(lightLevel < 15)
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
}
In this competition you do not have to code your steering and motors, but rather you can (if you wish) just install a receiver for an RC controller and plug your servos and motors into this. Although I would like to be able to have coded our Arduino to run the motors, servos, sensors and controller of our choice.
Due to my limited knowledge, when I've tried to find ways to connect a controller to the Arduino Uno board, I couldn't decipher what they were talking about with the USB Host shields in these websites:
https://www.circuitsathome.com/mcu/arduino/ps4-controller-support-for-the-usb-host-library/#comments
I would like to be able to understand what they are talking about in these websites in being able to "access" the libraries of the controllers. Specifically I would like to know about the Xbox One and/or the PS 4 controllers as these would be my team's ideal choice of controller. And also, is there something you have to put into your sketch in order to be able to "access" these libraries?
Could someone please help me out?
I've read that some of the triggers and/or dongles are digital (meaning they read the exact values) whereas some are analog (meaning they only read if it true or false, for the controller: if the button is pushed or if it is not). I would like the throttles and steering to be digital so that the person driving can adjust the speed and/or direction of turning. Would it be right to assume that I can have the controller be able to steer the car with the dongles on the controller and use the right trigger as a throttle for speed and left trigger as a reversing throttle?
Thanks for taking the time to help!
PS if you would like to know bit more about the competition see the youtube link below:
This is a video of the World Finals from last year (2016) that my team ended up winning, but I've come back this year with another team and am wanting to do it again. I've just won the National Finals for Australia and am heading off to the World Finals in Abu Dhabi in December.
This is the website for the competition:
http://www.4x4inschools.co.uk/home/?video_id=46
Feel free to ask questions about the competition and/or what I've talked about wanting for my vehicle if you want .