>>For the video streaming:
> install openssh and ffmpeg on server, mplayer on client and type:
ssh USER@IP ffmpeg -an -f video4linux2 -s 640x480 -i /dev/video0 -r 10 -b:v 50k -f avi - | mplayer - -idle -demuxer matroska -xy 1600
>>For the serial port forwarding:
> install ser2net on the server
> add in /etc/ser2net.conf the two following lines:
4000:raw:600:/dev/ttyUSB0:57600 8DATABITS NONE 1STOPBIT
4001:raw:600:/dev/ttyUSB1:57600 8DATABITS NONE 1STOPBIT
> sudo ufw allow 4000
> sudo ufw allow 4001
> install socat on the client
socat pty,link=$HOME/dev/ttyV0,waitslave tcp:IP:4000
>> For controling the car:
> I use a short python sketch based on the library for the Santtalgi, most of the code is for drawing the car on the screen in pygame:
import atmega8
import pygame
FRAMERATE = 100
HEIGHT = 800
WIDTH = 600
WEPS = WIDTH//100 #Size border for rectangle
HEPS = HEIGHT//100
pinI = [atmega8.PB0,atmega8.PB1,atmega8.PB2,atmega8.PB3] #Input pins I1,I2,I3,I4
CCAR = pygame.Color("green") #Color of the car main body
BLACK = pygame.Color("black") #Background color
def draw_rect_border(surface,color,x,y,k,l):
pygame.draw.rect(surface,BLACK,pygame.Rect((x-WEPS,y-HEPS),(k+2*WEPS,l+2*HEPS)))
pygame.draw.rect(surface,color,pygame.Rect((x,y),(k,l)))
def draw_car(surface,ccar,cleft,cright,cmotor):
#Main rectangle
pygame.draw.rect(surface, CCAR,pygame.Rect((WIDTH//10,HEIGHT//20),(8*WIDTH//10,9*HEIGHT//10)))
#Rear wheels and motor
draw_rect_border(surface,cmotor,WIDTH//20,14*HEIGHT//20,WIDTH//10,2*HEIGHT//10)
draw_rect_border(surface,cmotor,17*WIDTH//20,14*HEIGHT//20,WIDTH//10,2*HEIGHT//10)
draw_rect_border(surface,cmotor,2*WIDTH//10,29*HEIGHT//40,6*WIDTH//10,3*HEIGHT//20)
#Front wheels
draw_rect_border(surface,cleft,WIDTH//20,HEIGHT//10,WIDTH//10,2*HEIGHT//10)
draw_rect_border(surface,cright,17*WIDTH//20,HEIGHT//10,WIDTH//10,2*HEIGHT//10)
#Initialization
at = atmega8.ATMega8('/home/username/dev/ttyV0') #Replace username with your username
for pin in pinI:
at.pinMode(pin,atmega8.OUTPUT)
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((WIDTH,HEIGHT))
is_playing = True
while is_playing:
color_left = CCAR
color_right = CCAR
color_motor = CCAR
for event in pygame.event.get():
if event.type == pygame.QUIT:
is_playing = False
break
keys = pygame.key.get_pressed()
if keys[pygame.K_q]:
is_playing = False
break
if keys[pygame.K_UP]:
color_motor = pygame.Color("red")
at.digitalWrite(pinI[0],atmega8.LOW)
at.digitalWrite(pinI[1],atmega8.HIGH)
elif keys[pygame.K_DOWN]:
color_motor = pygame.Color("magenta")
at.digitalWrite(pinI[1],atmega8.LOW)
at.digitalWrite(pinI[0],atmega8.HIGH)
else:
at.digitalWrite(pinI[0],atmega8.LOW)
at.digitalWrite(pinI[1],atmega8.LOW)
if keys[pygame.K_LEFT]:
color_left = pygame.Color("red")
at.digitalWrite(pinI[2],atmega8.LOW)
at.digitalWrite(pinI[3],atmega8.HIGH)
elif keys[pygame.K_RIGHT]:
color_right = pygame.Color("red")
at.digitalWrite(pinI[3],atmega8.LOW)
at.digitalWrite(pinI[2],atmega8.HIGH)
else:
at.digitalWrite(pinI[2],atmega8.LOW)
at.digitalWrite(pinI[3],atmega8.LOW)
draw_car(screen,CCAR,color_left,color_right,color_motor)
pygame.display.flip()
clock.tick(FRAMERATE)
pygame.quit()