Some more modifications to drive sender so things are a little smoother. Works well now. Changed update rates for control systems.

This commit is contained in:
2018-03-04 16:27:24 -08:00
parent add93b6b7f
commit 8b83e84677
6 changed files with 24 additions and 11 deletions

View File

@@ -23,7 +23,7 @@ DEFAULT_RIGHT_BOGIE_TOPIC = "drive_control/right"
UINT16_MAX = 65535
DEFAULT_HERTZ = 20
DEFAULT_HERTZ = 30
WATCHDOG_TIMEOUT = 0.3
@@ -136,7 +136,7 @@ class DriveCoordinator(object):
def iris_drive_command_callback(self, drive_command):
self.drive_command_data["iris"]["message"] = drive_command
self.drive_command_data["iris"]["last_time"] = time()
self.drive_command_data["iris"]["last_time"] = time()
def ground_station_drive_command_callback(self, drive_command):
self.drive_command_data["ground_station"]["message"] = drive_command

View File

@@ -29,11 +29,13 @@ DEFAULT_DRIVE_CONTROL_STATUS_TOPIC = "drive_status/rear"
FIRST_MOTOR_ID = 1
SECOND_MOTOR_ID = 2
COMMUNICATIONS_TIMEOUT = 0.15 # Seconds
COMMUNICATIONS_TIMEOUT = 0.01 # Seconds
RX_DELAY = 0.01
TX_DELAY = 0.01
DEFAULT_HERTZ = 20
MODBUS_REGISTERS = {
"DIRECTION": 0,
"SPEED": 1,
@@ -71,6 +73,8 @@ class DriveControl(object):
self.drive_control_status_topic = rospy.get_param("~drive_control_status_topic", DEFAULT_DRIVE_CONTROL_STATUS_TOPIC)
self.wait_time = 1.0 / rospy.get_param("~hertz", DEFAULT_HERTZ)
self.first_motor = minimalmodbus.Instrument(self.port, FIRST_MOTOR_ID)
self.second_motor = minimalmodbus.Instrument(self.port, SECOND_MOTOR_ID)
self.__setup_minimalmodbus_for_485()
@@ -98,9 +102,18 @@ class DriveControl(object):
def run(self):
while not rospy.is_shutdown():
self.send_drive_control_message()
self.get_drive_status()
sleep(0.005)
start_time = time()
try:
self.send_drive_control_message()
self.get_drive_status()
except Exception, error:
print "Error occurred:", error
time_diff = time() - start_time
sleep(max(self.wait_time - time_diff, 0))
def send_drive_control_message(self):
if self.new_control_message: