From 3283cff60c978e4afddd13f253743bf25620ddf4 Mon Sep 17 00:00:00 2001 From: lt Date: Fri, 9 Mar 2018 08:48:45 +0100 Subject: [PATCH] Set default speed of moving functions to 50 and added comments to the methods --- autonomous_roboclaw/Engine.py | 80 +++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/autonomous_roboclaw/Engine.py b/autonomous_roboclaw/Engine.py index fc9eaa6..f4d9e04 100644 --- a/autonomous_roboclaw/Engine.py +++ b/autonomous_roboclaw/Engine.py @@ -1,8 +1,7 @@ -import serial, time +import serial class Engine: - global pwm speed_right_wheels = 0 speed_left_wheels = 0 @@ -17,41 +16,106 @@ def __init__(self): bytesize=serial.EIGHTBITS ) - def move_right_wheels_forward(self, speed): + def move_right_wheels_forward(self, speed=50): + """ + Move the right wheels forward with a default speed of 50. Another speed can be provided by calling the + function with a speed parameter. + :param speed: An int which indicates the speed + :return: + """ self.ser.write(bytes([128, 0, speed, (128 + speed) & 0x7F])) - def move_right_wheels_backward(self, speed): + def move_right_wheels_backward(self, speed=50): + """ + Move the right wheels backward with a default speed of 50. Another speed can be provided by calling the + function with a speed parameter. + :param speed: An int which indicates the speed + :return: + """ self.ser.write(bytes([128, 1, speed, (129 + speed) & 0x7F])) def stop_right_wheels(self): + """ + Stop the right wheels by setting speed to 0 + :return: + """ self.ser.write(bytes([128, 0, 0, 128 & 0x7F])) - def move_left_wheels_backward(self, speed): + def move_left_wheels_backward(self, speed=50): + """ + Move the left wheels backward with a default speed of 50. Another speed can be provided by calling the + function with a speed parameter. + :param speed: An int which indicates the speed + :return: + """ self.ser.write(bytes([128, 4, speed, (132 + speed) & 0x7F])) - def move_left_wheels_forward(self, speed): + def move_left_wheels_forward(self, speed=50): + """ + Move the left wheels backward with a default speed of 50. Another speed can be provided by calling the + function with a speed parameter. + :param speed: An int which indicates the speed + :return: + """ self.ser.write(bytes([128, 5, speed, (133 + speed) & 0x7F])) + def stop_left_wheels(self): + """ + Stop the left wheels by setting speed to 0 + :return: + + """ self.ser.write(bytes([128, 4, 0, 132 & 0x7F])) - def move_all_wheels_forward(self, speed): + def move_all_wheels_forward(self, speed=50): + """ + Move all wheels forward with a default speed of 50. Another speed can be provided by calling the + function with a speed parameter. + :param speed: An int which indicates the speed + :return: + + """ self.move_right_wheels_forward(speed) self.move_left_wheels_forward(speed) def stop_all_wheels(self): + """ + Stop all wheels by setting speed to 0 + :return: + """ self.stop_right_wheels() self.stop_left_wheels() - def move_all_wheels_backward(self, speed): + def move_all_wheels_backward(self, speed=50): + """ + Move all wheels backward with a default speed of 50. Another speed can be provided by calling the + function with a speed parameter. + :param speed: An int which indicates the speed + :return: + """ self.move_right_wheels_backward(speed) self.move_left_wheels_backward(speed) def turn_around_left(self, speed=35): + """ + Performs a left-hand turn on the spot by rotating the wheels in opposite directions. + Right wheels forward and left wheels backward. Another speed can be provided by calling the + function with a speed parameter. + :param speed: An int which indicates the speed + :return: + """ self.move_right_wheels_forward(speed) self.move_left_wheels_backward(speed) def turn_around_right(self, speed=35): + """ + Performs a right-hand turn on the spot by rotating the wheels in opposite directions. + Left wheels forward and right wheels backward. Another speed can be provided by calling the + function with a speed parameter. + :param speed: An int which indicates the speed + :return: + """ self.move_right_wheels_backward(speed) self.move_left_wheels_forward(speed)