I am working on a school project. I have to build a robot that will push the other robot off the table. the robot should have a camera and move by it self, but my teacher said that if i manage to connect xbox controller to it it will be fine.
I was given an esp8266 NodeMCU v3, Arduino uno, 2 motors, l298n motor driver and nothing else. I have writen a code in python and ArduinoIDE
void setup()
{
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(12, OUTPUT);
pinMode(14, OUTPUT);
Serial.begin(9600);
}
void rr(int value1, int value2)
{
analogWrite(4, value1);
analogWrite(5, value2);
}
void rl(int value1, int value2)
{
analogWrite(12, value1);
analogWrite(14, value2);
}
void loop()
{
String read = Serial.readString();
int power = read.toInt();
rr(power, 0);
rl(power, 0);
}
import pygame, sys, serial
import time
time.sleep(1.0)
ser = serial.Serial("COM5", 9600)
pygame.joystick.init()
joystick = [pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())]
pygame.init()
clock = pygame.time.Clock()
def map_range(x, a, b, c, d):
y = (x-a) * (d-c) / (b-a) + c
return y
while True:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
position = round(pygame.joystick.Joystick(0).get_axis(5))
#position = 100
ser.write(str(map_range(position, -1, 1, 0, 255)).encode("utf-8"))
I wonder if it possible to wirelessly update "power" variable so i can controll the robot speed.
I have done lots of reserch and i was not able to find anything that will work