Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4537

Other projects • Raspberry Pi RC Car Script

$
0
0
Ive made a FPV using an old RC Truck with a Webcam speaker and Raspberry pi 4B.
ive created a script to run it via keyboard however i have a few issues i can not fix.
One issue is the reverse speed for the car wont work at any lower speed than listed or it refuses to work. Is there perhaps an error in the code or is it a hardware issue?
The other issue i have is getting the Raspberry pi to recognize a 4G USB Qualcomm dongle. the dongle seems to flash on and of and disappears from the pi.
ive tried modeswitch techniques etc but they all seem to be from 5 to 6 years ago and have had no luck installing the Dongle so i can connect to 4g.
Thanks for any help that can be provided. Details are as follows:
RC car is driven by a motor connected to a ESC (Model Number WP-10BL60-RTR)
Steering is by a small servo
Im using Pygame and Pigpio
The USB Modem is a 4G LTE Qualcomm FP3
Camera Vision is being controlled via Mjpg-streamer.
The Python code to control the car is as follows:

Thanks in Advance

import pigpio
import pygame
import time

pygame.init()

screen = pygame.display.set_mode((100, 100))

pi = pigpio.pi()
if not pi.connected:
exit()

servo_pin = 18
esc_pin = 23

neutral_pulse_esc = 1500
neutral_pulse_servo = 1500

def control_esc(speed):
pulse_width = int(((speed + 100) / 200) * (2000 - 1000) + 1000)
pi.set_servo_pulsewidth(esc_pin, pulse_width)

def set_servo_angle(angle):
pulsewidth = int(((angle + 90) / 180) * (2500 - 500) + 500)
pi.set_servo_pulsewidth(servo_pin, pulsewidth)

control_esc(0)

running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_w:
control_esc(13) # Forward
elif event.key == pygame.K_s:
control_esc(-29) # Reverse #### cant set the speed any lower than this ########
elif event.key == pygame.K_a:
set_servo_angle(-40) # Left
elif event.key == pygame.K_d:
set_servo_angle(40) # Right
elif event.type == pygame.KEYUP:
if event.key in [pygame.K_w, pygame.K_s]:
control_esc(0)
elif event.key in [pygame.K_a, pygame.K_d]:
set_servo_angle(0)

pi.set_servo_pulsewidth(esc_pin, neutral_pulse_esc)
pi.set_servo_pulsewidth(servo_pin, neutral_pulse_servo)
pi.stop()
pygame.quit()

Statistics: Posted by Claytux — Wed Mar 27, 2024 3:17 am — Replies 0 — Views 5



Viewing all articles
Browse latest Browse all 4537

Trending Articles