Add complib client and TCP communication
This commit is contained in:
parent
1a033c8b03
commit
a484bc2137
35 changed files with 815 additions and 232 deletions
3
client_s2/.idea/.gitignore
generated
vendored
Normal file
3
client_s2/.idea/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
8
client_s2/.idea/client_s2.iml
generated
Normal file
8
client_s2/.idea/client_s2.iml
generated
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
12
client_s2/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
12
client_s2/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
|
@ -0,0 +1,12 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||
<option name="ignoredIdentifiers">
|
||||
<list>
|
||||
<option value="list.__getitem__" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
6
client_s2/.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
client_s2/.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
4
client_s2/.idea/misc.xml
generated
Normal file
4
client_s2/.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
||||
</project>
|
8
client_s2/.idea/modules.xml
generated
Normal file
8
client_s2/.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/client_s2.iml" filepath="$PROJECT_DIR$/.idea/client_s2.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
15
client_s2/.idea/saveactions_settings.xml
generated
Normal file
15
client_s2/.idea/saveactions_settings.xml
generated
Normal file
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="SaveActionSettings">
|
||||
<option name="actions">
|
||||
<set>
|
||||
<option value="activate" />
|
||||
<option value="activateOnShortcut" />
|
||||
<option value="activateOnBatch" />
|
||||
<option value="organizeImports" />
|
||||
<option value="reformat" />
|
||||
<option value="rearrange" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
6
client_s2/.idea/vcs.xml
generated
Normal file
6
client_s2/.idea/vcs.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -20,17 +20,65 @@ message GenericResponse {
|
|||
Status status = 2;
|
||||
}
|
||||
|
||||
message ReadSensorsRequest {
|
||||
message EncoderReadPositionsRequest {
|
||||
Header header = 1;
|
||||
}
|
||||
|
||||
message ReadSensorsResponse {
|
||||
message EncoderReadPositionsResponse {
|
||||
Header header = 1;
|
||||
Status status = 2;
|
||||
uint32 ir_1 = 3;
|
||||
uint32 ir_2 = 4;
|
||||
uint32 ir_3 = 5;
|
||||
uint32 ir_4 = 6;
|
||||
uint32 ir_5 = 7;
|
||||
repeated int32 positions = 3 [packed = true];
|
||||
}
|
||||
|
||||
message EncoderReadVelocitiesRequest {
|
||||
Header header = 1;
|
||||
}
|
||||
|
||||
message EncoderReadVelocitiesResponse {
|
||||
Header header = 1;
|
||||
Status status = 2;
|
||||
repeated double velocities = 3 [packed = true];
|
||||
}
|
||||
|
||||
message IRSensorsEnableRequest {
|
||||
Header header = 1;
|
||||
}
|
||||
|
||||
message IRSensorsDisableRequest {
|
||||
Header header = 1;
|
||||
}
|
||||
|
||||
message IRSensorsReadAllRequest {
|
||||
Header header = 1;
|
||||
}
|
||||
|
||||
message IRSensorsReadAllResponse {
|
||||
Header header = 1;
|
||||
Status status = 2;
|
||||
repeated uint32 data = 3 [packed = true];
|
||||
}
|
||||
|
||||
message MotorsSetPowerRequest {
|
||||
Header header = 1;
|
||||
uint32 port = 2;
|
||||
double power = 3;
|
||||
}
|
||||
|
||||
message MotorsSetSpeedRequest {
|
||||
Header header = 1;
|
||||
uint32 port = 2;
|
||||
double speed = 3;
|
||||
}
|
||||
|
||||
message OdometryReadRequest {
|
||||
Header header = 1;
|
||||
}
|
||||
|
||||
message OdometryReadResponse {
|
||||
Header header = 1;
|
||||
Status status = 2;
|
||||
double x_position = 3;
|
||||
double y_position = 4;
|
||||
double orientation = 5;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,84 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: CompLib.proto
|
||||
"""Generated protocol buffer code."""
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import descriptor_pool as _descriptor_pool
|
||||
from google.protobuf import message as _message
|
||||
from google.protobuf import reflection as _reflection
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rCompLib.proto\x12\x07\x43ompLib\"\x1e\n\x06Header\x12\x14\n\x0cmessage_type\x18\x01 \x01(\t\"3\n\x06Status\x12\x12\n\nsuccessful\x18\x01 \x01(\x08\x12\x15\n\rerror_message\x18\x02 \x01(\t\"1\n\x0eGenericRequest\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\"S\n\x0fGenericResponse\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\x12\x1f\n\x06status\x18\x02 \x01(\x0b\x32\x0f.CompLib.Status\"5\n\x12ReadSensorsRequest\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\"\x9d\x01\n\x13ReadSensorsResponse\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\x12\x1f\n\x06status\x18\x02 \x01(\x0b\x32\x0f.CompLib.Status\x12\x0c\n\x04ir_1\x18\x03 \x01(\r\x12\x0c\n\x04ir_2\x18\x04 \x01(\r\x12\x0c\n\x04ir_3\x18\x05 \x01(\r\x12\x0c\n\x04ir_4\x18\x06 \x01(\r\x12\x0c\n\x04ir_5\x18\x07 \x01(\rb\x06proto3')
|
||||
|
||||
|
||||
|
||||
_HEADER = DESCRIPTOR.message_types_by_name['Header']
|
||||
_STATUS = DESCRIPTOR.message_types_by_name['Status']
|
||||
_GENERICREQUEST = DESCRIPTOR.message_types_by_name['GenericRequest']
|
||||
_GENERICRESPONSE = DESCRIPTOR.message_types_by_name['GenericResponse']
|
||||
_READSENSORSREQUEST = DESCRIPTOR.message_types_by_name['ReadSensorsRequest']
|
||||
_READSENSORSRESPONSE = DESCRIPTOR.message_types_by_name['ReadSensorsResponse']
|
||||
Header = _reflection.GeneratedProtocolMessageType('Header', (_message.Message,), {
|
||||
'DESCRIPTOR' : _HEADER,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.Header)
|
||||
})
|
||||
_sym_db.RegisterMessage(Header)
|
||||
|
||||
Status = _reflection.GeneratedProtocolMessageType('Status', (_message.Message,), {
|
||||
'DESCRIPTOR' : _STATUS,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.Status)
|
||||
})
|
||||
_sym_db.RegisterMessage(Status)
|
||||
|
||||
GenericRequest = _reflection.GeneratedProtocolMessageType('GenericRequest', (_message.Message,), {
|
||||
'DESCRIPTOR' : _GENERICREQUEST,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.GenericRequest)
|
||||
})
|
||||
_sym_db.RegisterMessage(GenericRequest)
|
||||
|
||||
GenericResponse = _reflection.GeneratedProtocolMessageType('GenericResponse', (_message.Message,), {
|
||||
'DESCRIPTOR' : _GENERICRESPONSE,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.GenericResponse)
|
||||
})
|
||||
_sym_db.RegisterMessage(GenericResponse)
|
||||
|
||||
ReadSensorsRequest = _reflection.GeneratedProtocolMessageType('ReadSensorsRequest', (_message.Message,), {
|
||||
'DESCRIPTOR' : _READSENSORSREQUEST,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.ReadSensorsRequest)
|
||||
})
|
||||
_sym_db.RegisterMessage(ReadSensorsRequest)
|
||||
|
||||
ReadSensorsResponse = _reflection.GeneratedProtocolMessageType('ReadSensorsResponse', (_message.Message,), {
|
||||
'DESCRIPTOR' : _READSENSORSRESPONSE,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.ReadSensorsResponse)
|
||||
})
|
||||
_sym_db.RegisterMessage(ReadSensorsResponse)
|
||||
|
||||
if _descriptor._USE_C_DESCRIPTORS == False:
|
||||
|
||||
DESCRIPTOR._options = None
|
||||
_HEADER._serialized_start=26
|
||||
_HEADER._serialized_end=56
|
||||
_STATUS._serialized_start=58
|
||||
_STATUS._serialized_end=109
|
||||
_GENERICREQUEST._serialized_start=111
|
||||
_GENERICREQUEST._serialized_end=160
|
||||
_GENERICRESPONSE._serialized_start=162
|
||||
_GENERICRESPONSE._serialized_end=245
|
||||
_READSENSORSREQUEST._serialized_start=247
|
||||
_READSENSORSREQUEST._serialized_end=300
|
||||
_READSENSORSRESPONSE._serialized_start=303
|
||||
_READSENSORSRESPONSE._serialized_end=460
|
||||
# @@protoc_insertion_point(module_scope)
|
Binary file not shown.
45
client_s2/compLib/CompLibClient.py
Normal file
45
client_s2/compLib/CompLibClient.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
import socket
|
||||
|
||||
import compLib.CompLib_pb2 as CompLib_pb2
|
||||
|
||||
UNIX_SOCKET_PATH = "/tmp/compLib"
|
||||
TCP_SOCKET_HOST = "192.168.0.151"
|
||||
TCP_SOCKET_PORT = 9090
|
||||
|
||||
|
||||
class CompLibClient(object):
|
||||
|
||||
@staticmethod
|
||||
def send(data: bytes, size: int) -> bytes:
|
||||
# with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
# sock.connect((TCP_SOCKET_HOST, TCP_SOCKET_PORT))
|
||||
|
||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(UNIX_SOCKET_PATH)
|
||||
|
||||
sock.sendall(size.to_bytes(1, byteorder='big'))
|
||||
sock.sendall(data)
|
||||
|
||||
response_size_bytes = sock.recv(1)
|
||||
response_size = int.from_bytes(response_size_bytes, byteorder="big")
|
||||
# print(response_size)
|
||||
|
||||
response_bytes = sock.recv(response_size)
|
||||
# print(response_bytes.hex())
|
||||
# print(len(response_bytes))
|
||||
|
||||
CompLibClient.check_response(response_bytes)
|
||||
|
||||
return response_bytes
|
||||
|
||||
@staticmethod
|
||||
def check_response(response_bytes: bytes) -> bool:
|
||||
print(f"{response_bytes}")
|
||||
res = CompLib_pb2.GenericResponse()
|
||||
res.ParseFromString(response_bytes)
|
||||
|
||||
if res.status.successful:
|
||||
return True
|
||||
|
||||
# TODO: Log error message if unsuccessful
|
||||
return False
|
190
client_s2/compLib/CompLib_pb2.py
Normal file
190
client_s2/compLib/CompLib_pb2.py
Normal file
|
@ -0,0 +1,190 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: CompLib.proto
|
||||
"""Generated protocol buffer code."""
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import descriptor_pool as _descriptor_pool
|
||||
from google.protobuf import message as _message
|
||||
from google.protobuf import reflection as _reflection
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\rCompLib.proto\x12\x07\x43ompLib\"\x1e\n\x06Header\x12\x14\n\x0cmessage_type\x18\x01 \x01(\t\"3\n\x06Status\x12\x12\n\nsuccessful\x18\x01 \x01(\x08\x12\x15\n\rerror_message\x18\x02 \x01(\t\"1\n\x0eGenericRequest\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\"S\n\x0fGenericResponse\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\x12\x1f\n\x06status\x18\x02 \x01(\x0b\x32\x0f.CompLib.Status\">\n\x1b\x45ncoderReadPositionsRequest\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\"w\n\x1c\x45ncoderReadPositionsResponse\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\x12\x1f\n\x06status\x18\x02 \x01(\x0b\x32\x0f.CompLib.Status\x12\x15\n\tpositions\x18\x03 \x03(\x05\x42\x02\x10\x01\"?\n\x1c\x45ncoderReadVelocitiesRequest\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\"y\n\x1d\x45ncoderReadVelocitiesResponse\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\x12\x1f\n\x06status\x18\x02 \x01(\x0b\x32\x0f.CompLib.Status\x12\x16\n\nvelocities\x18\x03 \x03(\x01\x42\x02\x10\x01\"9\n\x16IRSensorsEnableRequest\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\":\n\x17IRSensorsDisableRequest\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\":\n\x17IRSensorsReadAllRequest\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\"n\n\x18IRSensorsReadAllResponse\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\x12\x1f\n\x06status\x18\x02 \x01(\x0b\x32\x0f.CompLib.Status\x12\x10\n\x04\x64\x61ta\x18\x03 \x03(\rB\x02\x10\x01\"U\n\x15MotorsSetPowerRequest\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\x12\x0c\n\x04port\x18\x02 \x01(\r\x12\r\n\x05power\x18\x03 \x01(\x01\"U\n\x15MotorsSetSpeedRequest\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\x12\x0c\n\x04port\x18\x02 \x01(\r\x12\r\n\x05speed\x18\x03 \x01(\x01\"6\n\x13OdometryReadRequest\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\"\x95\x01\n\x14OdometryReadResponse\x12\x1f\n\x06header\x18\x01 \x01(\x0b\x32\x0f.CompLib.Header\x12\x1f\n\x06status\x18\x02 \x01(\x0b\x32\x0f.CompLib.Status\x12\x12\n\nx_position\x18\x03 \x01(\x01\x12\x12\n\ny_position\x18\x04 \x01(\x01\x12\x13\n\x0borientation\x18\x05 \x01(\x01\x62\x06proto3')
|
||||
|
||||
|
||||
|
||||
_HEADER = DESCRIPTOR.message_types_by_name['Header']
|
||||
_STATUS = DESCRIPTOR.message_types_by_name['Status']
|
||||
_GENERICREQUEST = DESCRIPTOR.message_types_by_name['GenericRequest']
|
||||
_GENERICRESPONSE = DESCRIPTOR.message_types_by_name['GenericResponse']
|
||||
_ENCODERREADPOSITIONSREQUEST = DESCRIPTOR.message_types_by_name['EncoderReadPositionsRequest']
|
||||
_ENCODERREADPOSITIONSRESPONSE = DESCRIPTOR.message_types_by_name['EncoderReadPositionsResponse']
|
||||
_ENCODERREADVELOCITIESREQUEST = DESCRIPTOR.message_types_by_name['EncoderReadVelocitiesRequest']
|
||||
_ENCODERREADVELOCITIESRESPONSE = DESCRIPTOR.message_types_by_name['EncoderReadVelocitiesResponse']
|
||||
_IRSENSORSENABLEREQUEST = DESCRIPTOR.message_types_by_name['IRSensorsEnableRequest']
|
||||
_IRSENSORSDISABLEREQUEST = DESCRIPTOR.message_types_by_name['IRSensorsDisableRequest']
|
||||
_IRSENSORSREADALLREQUEST = DESCRIPTOR.message_types_by_name['IRSensorsReadAllRequest']
|
||||
_IRSENSORSREADALLRESPONSE = DESCRIPTOR.message_types_by_name['IRSensorsReadAllResponse']
|
||||
_MOTORSSETPOWERREQUEST = DESCRIPTOR.message_types_by_name['MotorsSetPowerRequest']
|
||||
_MOTORSSETSPEEDREQUEST = DESCRIPTOR.message_types_by_name['MotorsSetSpeedRequest']
|
||||
_ODOMETRYREADREQUEST = DESCRIPTOR.message_types_by_name['OdometryReadRequest']
|
||||
_ODOMETRYREADRESPONSE = DESCRIPTOR.message_types_by_name['OdometryReadResponse']
|
||||
Header = _reflection.GeneratedProtocolMessageType('Header', (_message.Message,), {
|
||||
'DESCRIPTOR' : _HEADER,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.Header)
|
||||
})
|
||||
_sym_db.RegisterMessage(Header)
|
||||
|
||||
Status = _reflection.GeneratedProtocolMessageType('Status', (_message.Message,), {
|
||||
'DESCRIPTOR' : _STATUS,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.Status)
|
||||
})
|
||||
_sym_db.RegisterMessage(Status)
|
||||
|
||||
GenericRequest = _reflection.GeneratedProtocolMessageType('GenericRequest', (_message.Message,), {
|
||||
'DESCRIPTOR' : _GENERICREQUEST,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.GenericRequest)
|
||||
})
|
||||
_sym_db.RegisterMessage(GenericRequest)
|
||||
|
||||
GenericResponse = _reflection.GeneratedProtocolMessageType('GenericResponse', (_message.Message,), {
|
||||
'DESCRIPTOR' : _GENERICRESPONSE,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.GenericResponse)
|
||||
})
|
||||
_sym_db.RegisterMessage(GenericResponse)
|
||||
|
||||
EncoderReadPositionsRequest = _reflection.GeneratedProtocolMessageType('EncoderReadPositionsRequest', (_message.Message,), {
|
||||
'DESCRIPTOR' : _ENCODERREADPOSITIONSREQUEST,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.EncoderReadPositionsRequest)
|
||||
})
|
||||
_sym_db.RegisterMessage(EncoderReadPositionsRequest)
|
||||
|
||||
EncoderReadPositionsResponse = _reflection.GeneratedProtocolMessageType('EncoderReadPositionsResponse', (_message.Message,), {
|
||||
'DESCRIPTOR' : _ENCODERREADPOSITIONSRESPONSE,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.EncoderReadPositionsResponse)
|
||||
})
|
||||
_sym_db.RegisterMessage(EncoderReadPositionsResponse)
|
||||
|
||||
EncoderReadVelocitiesRequest = _reflection.GeneratedProtocolMessageType('EncoderReadVelocitiesRequest', (_message.Message,), {
|
||||
'DESCRIPTOR' : _ENCODERREADVELOCITIESREQUEST,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.EncoderReadVelocitiesRequest)
|
||||
})
|
||||
_sym_db.RegisterMessage(EncoderReadVelocitiesRequest)
|
||||
|
||||
EncoderReadVelocitiesResponse = _reflection.GeneratedProtocolMessageType('EncoderReadVelocitiesResponse', (_message.Message,), {
|
||||
'DESCRIPTOR' : _ENCODERREADVELOCITIESRESPONSE,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.EncoderReadVelocitiesResponse)
|
||||
})
|
||||
_sym_db.RegisterMessage(EncoderReadVelocitiesResponse)
|
||||
|
||||
IRSensorsEnableRequest = _reflection.GeneratedProtocolMessageType('IRSensorsEnableRequest', (_message.Message,), {
|
||||
'DESCRIPTOR' : _IRSENSORSENABLEREQUEST,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.IRSensorsEnableRequest)
|
||||
})
|
||||
_sym_db.RegisterMessage(IRSensorsEnableRequest)
|
||||
|
||||
IRSensorsDisableRequest = _reflection.GeneratedProtocolMessageType('IRSensorsDisableRequest', (_message.Message,), {
|
||||
'DESCRIPTOR' : _IRSENSORSDISABLEREQUEST,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.IRSensorsDisableRequest)
|
||||
})
|
||||
_sym_db.RegisterMessage(IRSensorsDisableRequest)
|
||||
|
||||
IRSensorsReadAllRequest = _reflection.GeneratedProtocolMessageType('IRSensorsReadAllRequest', (_message.Message,), {
|
||||
'DESCRIPTOR' : _IRSENSORSREADALLREQUEST,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.IRSensorsReadAllRequest)
|
||||
})
|
||||
_sym_db.RegisterMessage(IRSensorsReadAllRequest)
|
||||
|
||||
IRSensorsReadAllResponse = _reflection.GeneratedProtocolMessageType('IRSensorsReadAllResponse', (_message.Message,), {
|
||||
'DESCRIPTOR' : _IRSENSORSREADALLRESPONSE,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.IRSensorsReadAllResponse)
|
||||
})
|
||||
_sym_db.RegisterMessage(IRSensorsReadAllResponse)
|
||||
|
||||
MotorsSetPowerRequest = _reflection.GeneratedProtocolMessageType('MotorsSetPowerRequest', (_message.Message,), {
|
||||
'DESCRIPTOR' : _MOTORSSETPOWERREQUEST,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.MotorsSetPowerRequest)
|
||||
})
|
||||
_sym_db.RegisterMessage(MotorsSetPowerRequest)
|
||||
|
||||
MotorsSetSpeedRequest = _reflection.GeneratedProtocolMessageType('MotorsSetSpeedRequest', (_message.Message,), {
|
||||
'DESCRIPTOR' : _MOTORSSETSPEEDREQUEST,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.MotorsSetSpeedRequest)
|
||||
})
|
||||
_sym_db.RegisterMessage(MotorsSetSpeedRequest)
|
||||
|
||||
OdometryReadRequest = _reflection.GeneratedProtocolMessageType('OdometryReadRequest', (_message.Message,), {
|
||||
'DESCRIPTOR' : _ODOMETRYREADREQUEST,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.OdometryReadRequest)
|
||||
})
|
||||
_sym_db.RegisterMessage(OdometryReadRequest)
|
||||
|
||||
OdometryReadResponse = _reflection.GeneratedProtocolMessageType('OdometryReadResponse', (_message.Message,), {
|
||||
'DESCRIPTOR' : _ODOMETRYREADRESPONSE,
|
||||
'__module__' : 'CompLib_pb2'
|
||||
# @@protoc_insertion_point(class_scope:CompLib.OdometryReadResponse)
|
||||
})
|
||||
_sym_db.RegisterMessage(OdometryReadResponse)
|
||||
|
||||
if _descriptor._USE_C_DESCRIPTORS == False:
|
||||
|
||||
DESCRIPTOR._options = None
|
||||
_ENCODERREADPOSITIONSRESPONSE.fields_by_name['positions']._options = None
|
||||
_ENCODERREADPOSITIONSRESPONSE.fields_by_name['positions']._serialized_options = b'\020\001'
|
||||
_ENCODERREADVELOCITIESRESPONSE.fields_by_name['velocities']._options = None
|
||||
_ENCODERREADVELOCITIESRESPONSE.fields_by_name['velocities']._serialized_options = b'\020\001'
|
||||
_IRSENSORSREADALLRESPONSE.fields_by_name['data']._options = None
|
||||
_IRSENSORSREADALLRESPONSE.fields_by_name['data']._serialized_options = b'\020\001'
|
||||
_HEADER._serialized_start=26
|
||||
_HEADER._serialized_end=56
|
||||
_STATUS._serialized_start=58
|
||||
_STATUS._serialized_end=109
|
||||
_GENERICREQUEST._serialized_start=111
|
||||
_GENERICREQUEST._serialized_end=160
|
||||
_GENERICRESPONSE._serialized_start=162
|
||||
_GENERICRESPONSE._serialized_end=245
|
||||
_ENCODERREADPOSITIONSREQUEST._serialized_start=247
|
||||
_ENCODERREADPOSITIONSREQUEST._serialized_end=309
|
||||
_ENCODERREADPOSITIONSRESPONSE._serialized_start=311
|
||||
_ENCODERREADPOSITIONSRESPONSE._serialized_end=430
|
||||
_ENCODERREADVELOCITIESREQUEST._serialized_start=432
|
||||
_ENCODERREADVELOCITIESREQUEST._serialized_end=495
|
||||
_ENCODERREADVELOCITIESRESPONSE._serialized_start=497
|
||||
_ENCODERREADVELOCITIESRESPONSE._serialized_end=618
|
||||
_IRSENSORSENABLEREQUEST._serialized_start=620
|
||||
_IRSENSORSENABLEREQUEST._serialized_end=677
|
||||
_IRSENSORSDISABLEREQUEST._serialized_start=679
|
||||
_IRSENSORSDISABLEREQUEST._serialized_end=737
|
||||
_IRSENSORSREADALLREQUEST._serialized_start=739
|
||||
_IRSENSORSREADALLREQUEST._serialized_end=797
|
||||
_IRSENSORSREADALLRESPONSE._serialized_start=799
|
||||
_IRSENSORSREADALLRESPONSE._serialized_end=909
|
||||
_MOTORSSETPOWERREQUEST._serialized_start=911
|
||||
_MOTORSSETPOWERREQUEST._serialized_end=996
|
||||
_MOTORSSETSPEEDREQUEST._serialized_start=998
|
||||
_MOTORSSETSPEEDREQUEST._serialized_end=1083
|
||||
_ODOMETRYREADREQUEST._serialized_start=1085
|
||||
_ODOMETRYREADREQUEST._serialized_end=1139
|
||||
_ODOMETRYREADRESPONSE._serialized_start=1142
|
||||
_ODOMETRYREADRESPONSE._serialized_end=1291
|
||||
# @@protoc_insertion_point(module_scope)
|
35
client_s2/compLib/Encoder.py
Normal file
35
client_s2/compLib/Encoder.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
import compLib.CompLib_pb2 as CompLib_pb2
|
||||
from compLib.CompLibClient import CompLibClient
|
||||
|
||||
|
||||
class Encoder(object):
|
||||
"""Class used to read the encoders
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def read_all_positions():
|
||||
"""Read all encoder positions.
|
||||
|
||||
:return: Tuple of all current encoder positions
|
||||
"""
|
||||
request = CompLib_pb2.EncoderReadPositionsRequest()
|
||||
request.header.message_type = request.DESCRIPTOR.full_name
|
||||
|
||||
response = CompLib_pb2.EncoderReadPositionsResponse()
|
||||
response.ParseFromString(CompLibClient.send(request.SerializeToString(), request.ByteSize()))
|
||||
|
||||
return tuple(i for i in response.positions)
|
||||
|
||||
@staticmethod
|
||||
def read_all_velocities():
|
||||
"""Read the velocity of all motors connected.
|
||||
|
||||
:return: Tuple of all current motor velocities
|
||||
"""
|
||||
request = CompLib_pb2.EncoderReadVelocitiesRequest()
|
||||
request.header.message_type = request.DESCRIPTOR.full_name
|
||||
|
||||
response = CompLib_pb2.EncoderReadVelocitiesResponse()
|
||||
response.ParseFromString(CompLibClient.send(request.SerializeToString(), request.ByteSize()))
|
||||
|
||||
return tuple(i for i in response.velocities)
|
39
client_s2/compLib/IRSensor.py
Normal file
39
client_s2/compLib/IRSensor.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import compLib.CompLib_pb2 as CompLib_pb2
|
||||
from compLib.CompLibClient import CompLibClient
|
||||
|
||||
|
||||
class IRSensor(object):
|
||||
"""Access the different IR Sensors of the robot
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def read_all():
|
||||
"""Read all IR sensors at once.
|
||||
|
||||
:return: Tuple of all current ir sensors
|
||||
"""
|
||||
request = CompLib_pb2.IRSensorsReadAllRequest()
|
||||
request.header.message_type = request.DESCRIPTOR.full_name
|
||||
|
||||
response = CompLib_pb2.IRSensorsReadAllResponse()
|
||||
response.ParseFromString(CompLibClient.send(request.SerializeToString(), request.ByteSize()))
|
||||
|
||||
return tuple(i for i in response.data)
|
||||
|
||||
@staticmethod
|
||||
def enable():
|
||||
"""Turn on all IR emitters
|
||||
"""
|
||||
request = CompLib_pb2.IRSensorsEnableRequest()
|
||||
request.header.message_type = request.DESCRIPTOR.full_name
|
||||
|
||||
CompLibClient.send(request.SerializeToString(), request.ByteSize())
|
||||
|
||||
@staticmethod
|
||||
def disable():
|
||||
"""Turn off all IR emitters
|
||||
"""
|
||||
request = CompLib_pb2.IRSensorsDisableRequest()
|
||||
request.header.message_type = request.DESCRIPTOR.full_name
|
||||
|
||||
CompLibClient.send(request.SerializeToString(), request.ByteSize())
|
69
client_s2/compLib/Motor.py
Normal file
69
client_s2/compLib/Motor.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
import compLib.CompLib_pb2 as CompLib_pb2
|
||||
from compLib.CompLibClient import CompLibClient
|
||||
|
||||
MOTOR_COUNT = 4
|
||||
|
||||
|
||||
class Motor(object):
|
||||
"""Class used to control the motors
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def power(port: int, percent: float):
|
||||
"""Set specified motor to percentage power
|
||||
|
||||
:param port: Port, which the motor is connected to. 0-3
|
||||
:param percent: Percentage of max speed. between -100 and 100
|
||||
:raises: IndexError
|
||||
"""
|
||||
|
||||
if port < 0 or port >= MOTOR_COUNT:
|
||||
raise IndexError("Invalid Motor port specified!")
|
||||
|
||||
if percent < -100 or percent > 100:
|
||||
raise IndexError("Invalid Motor speed specified! Speed is between -100 and 100 percent!")
|
||||
|
||||
request = CompLib_pb2.MotorsSetPowerRequest()
|
||||
request.header.message_type = request.DESCRIPTOR.full_name
|
||||
request.port = port
|
||||
request.power = percent
|
||||
|
||||
CompLibClient.send(request.SerializeToString(), request.ByteSize())
|
||||
|
||||
@staticmethod
|
||||
def speed(port: int, speed: float):
|
||||
"""Set specified motor to percentage power
|
||||
|
||||
:param port: Port, which the motor is connected to. 0-3
|
||||
:param speed: Speed at which a motor should turn in RPM
|
||||
:raises: IndexError
|
||||
"""
|
||||
|
||||
if port < 0 or port >= MOTOR_COUNT:
|
||||
raise IndexError("Invalid Motor port specified!")
|
||||
|
||||
request = CompLib_pb2.MotorsSetSpeedRequest()
|
||||
request.header.message_type = request.DESCRIPTOR.full_name
|
||||
request.port = port
|
||||
request.speed = speed
|
||||
|
||||
CompLibClient.send(request.SerializeToString(), request.ByteSize())
|
||||
|
||||
# @staticmethod
|
||||
# def all_off():
|
||||
# """
|
||||
# Turns of all motors
|
||||
# """
|
||||
# Logging.get_logger().debug(f"Motor.all_off")
|
||||
#
|
||||
# for i in range(1, MOTOR_COUNT + 1):
|
||||
# Motor.active_break(i)
|
||||
|
||||
# @staticmethod
|
||||
# def active_break(port: int):
|
||||
# """
|
||||
# Actively break with a specific motor
|
||||
#
|
||||
# :param port: Port, which the motor is connected to. 1-4
|
||||
# """
|
||||
# Motor.pwm(port, 0, MotorMode.BREAK)
|
0
client_s2/compLib/__init__.py
Normal file
0
client_s2/compLib/__init__.py
Normal file
BIN
client_s2/compLib/__pycache__/CompLibClient.cpython-39.pyc
Normal file
BIN
client_s2/compLib/__pycache__/CompLibClient.cpython-39.pyc
Normal file
Binary file not shown.
BIN
client_s2/compLib/__pycache__/CompLib_pb2.cpython-39.pyc
Normal file
BIN
client_s2/compLib/__pycache__/CompLib_pb2.cpython-39.pyc
Normal file
Binary file not shown.
BIN
client_s2/compLib/__pycache__/Encoder.cpython-39.pyc
Normal file
BIN
client_s2/compLib/__pycache__/Encoder.cpython-39.pyc
Normal file
Binary file not shown.
BIN
client_s2/compLib/__pycache__/IRSensor.cpython-39.pyc
Normal file
BIN
client_s2/compLib/__pycache__/IRSensor.cpython-39.pyc
Normal file
Binary file not shown.
BIN
client_s2/compLib/__pycache__/Motor.cpython-39.pyc
Normal file
BIN
client_s2/compLib/__pycache__/Motor.cpython-39.pyc
Normal file
Binary file not shown.
BIN
client_s2/compLib/__pycache__/__init__.cpython-39.pyc
Normal file
BIN
client_s2/compLib/__pycache__/__init__.cpython-39.pyc
Normal file
Binary file not shown.
|
@ -1,36 +1,48 @@
|
|||
import socket
|
||||
import sys
|
||||
import os
|
||||
import CompLib_pb2
|
||||
|
||||
|
||||
SOCKET_PATH = "/tmp/compLib"
|
||||
|
||||
|
||||
def send(data, size):
|
||||
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
|
||||
sock.connect(SOCKET_PATH)
|
||||
sock.sendall(size.to_bytes(1, byteorder='big'))
|
||||
sock.sendall(data)
|
||||
|
||||
responseSizeBytes = sock.recv(1)
|
||||
responseSize = int.from_bytes(responseSizeBytes, byteorder="big")
|
||||
print(responseSize)
|
||||
|
||||
responseBytes = sock.recv(responseSize)
|
||||
genericResponse = CompLib_pb2.GenericResponse()
|
||||
|
||||
genericResponse.ParseFromString(responseBytes)
|
||||
print(genericResponse)
|
||||
|
||||
# reponseBytes =
|
||||
# def send(data, size):
|
||||
# with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock:
|
||||
# sock.connect(SOCKET_PATH)
|
||||
# sock.sendall(size.to_bytes(1, byteorder='big'))
|
||||
# sock.sendall(data)
|
||||
#
|
||||
# response_size_bytes = sock.recv(1)
|
||||
# response_size = int.from_bytes(response_size_bytes, byteorder="big")
|
||||
# # print(f"Response size: {response_size}")
|
||||
#
|
||||
# response_bytes = sock.recv(response_size)
|
||||
# generic_response = CompLib_pb2.GenericResponse()
|
||||
#
|
||||
# generic_response.ParseFromString(response_bytes)
|
||||
# # print(f"Response: {generic_response}")
|
||||
#
|
||||
# # reponseBytes =
|
||||
|
||||
|
||||
def main():
|
||||
readSensorsRequest = CompLib_pb2.ReadSensorsRequest()
|
||||
# readSensorsRequest.header = CompLib_pb2.Header()
|
||||
readSensorsRequest.header.message_type = readSensorsRequest.DESCRIPTOR.full_name
|
||||
send(readSensorsRequest.SerializeToString(), readSensorsRequest.ByteSize())
|
||||
# encoder_read_positions_request = CompLib_pb2.EncoderReadPositionsRequest()
|
||||
# # readSensorsRequest.header = CompLib_pb2.Header()
|
||||
# encoder_read_positions_request.header.message_type = encoder_read_positions_request.DESCRIPTOR.full_name
|
||||
#
|
||||
# start_time = time.time()
|
||||
# for i in range(100000):
|
||||
# send(encoder_read_positions_request.SerializeToString(), encoder_read_positions_request.ByteSize())
|
||||
# print("--- %s seconds ---" % (time.time() - start_time))
|
||||
|
||||
# from compLib.IRSensor import IRSensor
|
||||
# IRSensor.read_all()
|
||||
#
|
||||
from compLib.Encoder import Encoder
|
||||
Encoder.read_all_positions()
|
||||
Encoder.read_all_velocities()
|
||||
|
||||
# from compLib.Motor import Motor
|
||||
# Motor.speed(0, 50)
|
||||
# Motor.speed(3, -50)
|
||||
|
||||
# time.sleep(10)
|
||||
|
||||
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Reference in a new issue