Package: s2rcp
S2RCP - Simple Remote Robot Control Protocol.S2RCP is a simple application-level protocol for remote robot control. Allows
remote control of robot motors by sending and receiving packets with commands.
Due to the small size of the packets and the simplicity of their encoding and
decoding, applications implemented on the basis of S2RCP can be launched on
devices with weak hardware, for example, on EV3 Mindstorms microcomputers
with theev3devoperating system. Another advantage
of S2RCP is its versatility. According to this protocol, you can control any
robot where you do not need perfect precision of movements.This package includes modules:core- basic classes and functions needed to worknetwork- classes that provide communication between the robot and remote
controlrobot- for the software part of the robotremote- for the software part responsible for remote controlling the
robotHow to use?InstallationInstall frompippipinstalls2rcpCode example from the robot sideImplementBaseMotorinterface foryourmotorsfroms2rcp.robotimportBaseMotorclassMyMotorAdapter(BaseMotor):defstart(self,speed,inverted):# your implmentaion is here...defstop(self):# your implmentaion is here...Import of required modulesfroms2rcp.robotimport*froms2rcp.networkimportTcpClientCreate a TCP client to accept connection from remote controllertcp_client=TcpClient()# ROBOT_ADDRESS - ipv4 address in the form "xxx.xxx.xxx.xxx", for example# "192.168.1.10"# ROBOT_PORT - the port that will listen to the work, for example 53445# tcp_client.listen((ROBOT_ADDRESS, ROBOT_PORT))Create a controller and register your motors# Create controller for motorscontroller=MotorsController(tcp_client)# Register your motorsLEFT,RIGHT=range(2)# create constants for id motorscontroller.set_motor(# your motor class implementing the BaseMotor interface (see above)LEFT,MyMotorAdapter(...)# any constructor)controller.set_motor(RIGHT,MyMotorAdapter(...))Motors controller can be turned on and offcontroller.start()controller.stop()Code example from the remote sideImport of required modulesfroms2rcp.remoteimport*froms2rcp.networkimportTcpClientCreate a TCP client to connect to the robottcp_client=TcpClient()# ROBOT_ADDRESS - ipv4 address in the form "xxx.xxx.xxx.xxx", for example# "192.168.1.10"# ROBOT_PORT - the port that the robot controller listens to, for example# 53445tcp_client.connect((ROBOT_ADDRESS,ROBOT_PORT))Setup basic robot control# Example of settings axes for "tank" controlaxes_config=AxesConfig()axes_config.add_new_axis("MOVE")axes_config.add_motor_to_axis("MOVE",motor_id=0,motor_k=1.0)axes_config.add_motor_to_axis("MOVE",motor_id=1,motor_k=1.0)axes_config.add_new_axis("ROTATE")axes_config.add_motor_to_axis("ROTATE",motor_id=0,motor_k=1.0)axes_config.add_motor_to_axis("ROTATE",motor_id=1,motor_k=-1.0)# Create controllercontroller=RemoteController(tcp_client,axes_config)Example of robot control# "go straight ahead"controller.set_axis_value("MOVE",+1.0)controller.update()#            ^^^# Controller updates the internal state, generates commands and sends them to# the robot# "turn around on the spot"controller.set_axis_value("ROTATE",-1.0)controller.update()# "stop"controller.set_axis_value("MOVE",0)controller.update()Source codeSeehere