コード例 #1
0
    def get_vertical_joints(self):
        current_joint_id = "e"
        current_joint_name = "elbow"
        current_motor = Motor(1, 2)
        current_encoder_value = 60

        elbow = VerticalJoint(current_joint_id, current_joint_name, current_motor, current_encoder_value)

        current_shoulder_joint_id = "s"
        current_shoulder_joint_name = "shoulder"
        current_shoulder_motor = Motor(1, 2)
        current_shoulder_encoder_value = 60

        shoulder = VerticalJoint(current_shoulder_joint_id, current_shoulder_joint_name, current_shoulder_motor,
                                 current_shoulder_encoder_value)

        current_wrist_joint_id = "u"
        current_wrist_joint_name = "wrist"
        current_wrist_motor = Motor(1, 2)
        current_wrist_encoder_value = 60

        wrist = VerticalJoint(current_wrist_joint_id, current_wrist_joint_name, current_wrist_motor,
                              current_wrist_encoder_value)

        vertical_joints = [elbow, shoulder, wrist]  

        return vertical_joints
コード例 #2
0
    def test_should_return_gripper(self):
        gripper_motor = Motor(1, 2)

        gripper = Gripper(gripper_motor)

        expected_motor = Motor(1, 2)

        self.assertEquals(gripper.motor, expected_motor)
        self.assertFalse(gripper.has_gripped())
コード例 #3
0
    def test_should_return_waist(self):
        expected_motor = Motor(13, 19)
        waist = Motor(13, 19)
        arm = Arm_partial(waist, None, None, None, None, None)

        self.assertEquals(expected_motor.pin_a.number, arm.waist.pin_a.number)
        self.assertEquals(expected_motor.pin_b.number, arm.waist.pin_b.number)
        self.assertEquals(expected_motor.pin_a.value, arm.waist.pin_a.value)
        self.assertEquals(expected_motor.pin_b.value, arm.waist.pin_b.value)
コード例 #4
0
    def test_shoul_return_gripper(self):
        gripper_motor = Motor(1, 2)
        gripper = Gripper(gripper_motor)

        expected_gripper__motor = Motor(1, 2)
        expected_gripper = Gripper(expected_gripper__motor)

        arm = Arm(None, None, gripper)

        self.assertEquals(arm.gripper, expected_gripper)
コード例 #5
0
    def test_should_turn_right_02_degrees(self):
        executor = RPiExecutor()
        motor = Motor(0, 0)
        control = Control(motor, executor, None)

        motor.turn_right = MagicMock()
        motor.stop = MagicMock()
        executor.move = MagicMock()

        control.turn_right(10)

        executor.move.assert_called_with(motor)
        motor.turn_right.assert_called_with()
        motor.stop.assert_called_with()
コード例 #6
0
    def test_should_return_elbow_motor(self):
        expected_motor = Motor(17, 27)
        elbow = Motor(17, 27)
        arm = Arm_partial(None, None, elbow, None, None, None)

        current_waist = arm.get_motor("e")

        self.assertEquals(expected_motor.pin_a.number,
                          current_waist.pin_a.number)
        self.assertEquals(expected_motor.pin_b.number,
                          current_waist.pin_b.number)
        self.assertEquals(expected_motor.pin_a.value,
                          current_waist.pin_a.value)
        self.assertEquals(expected_motor.pin_b.value,
                          current_waist.pin_b.value)
コード例 #7
0
    def test_should_return_wrist_motor(self):
        expected_motor = Motor(16, 20)
        wrist = Motor(16, 20)
        arm = Arm_partial(None, None, None, wrist, None, None)

        current_waist = arm.get_motor("u")

        self.assertEquals(expected_motor.pin_a.number,
                          current_waist.pin_a.number)
        self.assertEquals(expected_motor.pin_b.number,
                          current_waist.pin_b.number)
        self.assertEquals(expected_motor.pin_a.value,
                          current_waist.pin_a.value)
        self.assertEquals(expected_motor.pin_b.value,
                          current_waist.pin_b.value)
コード例 #8
0
    def test_should_return_gripper_motor(self):
        expected_motor = Motor(5, 6)
        gripper = Motor(5, 6)
        arm = Arm_partial(None, None, None, None, gripper, None)

        current_waist = arm.get_motor("g")

        self.assertEquals(expected_motor.pin_a.number,
                          current_waist.pin_a.number)
        self.assertEquals(expected_motor.pin_b.number,
                          current_waist.pin_b.number)
        self.assertEquals(expected_motor.pin_a.value,
                          current_waist.pin_a.value)
        self.assertEquals(expected_motor.pin_b.value,
                          current_waist.pin_b.value)
コード例 #9
0
    def pi_arm_configuration(self):
        Configuration().configure()
        self._executor = RPiExecutor()

        waist = Motor(13, 19)
        shoulder = Motor(23, 24)
        elbow = Motor(17, 27)
        wrist = Motor(16, 20)
        gripper = Motor(5, 6)
        led = Pin(21)
        arm = Arm_partial(waist, shoulder, elbow, wrist, gripper, led)
        self._arm = arm
        self._led = led
        control = Control(None, self._executor, self._led)
        pi_arm = PiArm(control)

        return control, pi_arm
コード例 #10
0
    def test_should_open_gripper(self):
        gripper_motor = Motor(1, 2)

        gripper = Gripper(gripper_motor)

        gripper.open()

        self.assertTrue(gripper.motor._is_on)
コード例 #11
0
    def test_should_close_gripper(self):
        gripper_motor = Motor(1, 2)

        gripper = Gripper(gripper_motor)

        gripper.close()

        self.assertTrue(gripper.motor._is_on)
コード例 #12
0
    def test_should_gripped(self):
        gripper_motor = Motor(1, 2)

        gripper = Gripper(gripper_motor)

        gripper.gripped()

        self.assertTrue(gripper.has_gripped())
コード例 #13
0
 def test_should_stop_motor(self):
     motor = Motor(0, 0)
     motor.turn_left()
     motor.stop()
     self.assertEqual(False, motor.pin_a.value)
     self.assertEqual(False, motor.pin_b.value)
     self.assertFalse(motor.is_on())
コード例 #14
0
    def test_should_return_joint(self):
        expected_motor = Motor(1, 2)
        joint = Joint_partial("w", "l", 10)

        current_name = joint.name

        self.assertEquals(current_name, "w")
        self.assertEquals(joint.direction, "l")
        self.assertEquals(joint.value, 10)
コード例 #15
0
    def test_should_return_joint(self):
        expected_joint_id = "w"
        expected_joint_name = "waist"
        expected_motor = Motor(1, 2)
        expected_encoder_value = 250

        current_joint_id = "w"
        current_joint_name = "waist"
        current_motor = Motor(1, 2)
        current_encoder_value = 250

        joint = Joint(current_joint_id, current_joint_name, current_motor,
                      current_encoder_value)

        self.assertEquals(joint.id, expected_joint_id)
        self.assertEquals(joint.name, expected_joint_name)
        self.assertEquals(joint.motor, expected_motor)
        self.assertEquals(joint.encoder, expected_encoder_value)
コード例 #16
0
    def test_should_return_waist_joint(self):
        current_joint_id = "w"
        current_joint_name = "waist"
        current_motor = Motor(1, 2)
        current_encoder_value = 60

        waist = HorizontalJoint(current_joint_id, current_joint_name, current_motor, current_encoder_value)

        expected_joint_id = "w"
        expected_joint_name = "waist"
        expected_motor = Motor(1, 2)
        expected_encoder_value = 60

        expected_waist = HorizontalJoint(expected_joint_id, expected_joint_name, expected_motor, expected_encoder_value)

        arm = Arm(waist, None, None)

        self.assertEquals(arm.waist, expected_waist)
コード例 #17
0
    def test_should_right_and_stop_when_encoder_value_more_than_150(self):
        current_joint_id = "w"
        current_joint_name = "waist"
        current_motor = Motor(1, 2)
        current_encoder_value = 151

        joint = HorizontalJoint(current_joint_id, current_joint_name,
                                current_motor, current_encoder_value)

        joint.right()

        self.assertFalse(joint.motor.is_on())
コード例 #18
0
    def test_should_move_left_when_encoder_Value_less_than_150(self):
        current_joint_id = "w"
        current_joint_name = "waist"
        current_motor = Motor(1, 2)
        current_encoder_value = 60

        joint = HorizontalJoint(current_joint_id, current_joint_name,
                                current_motor, current_encoder_value)

        joint.left()

        self.assertTrue(joint.motor.is_on())
コード例 #19
0
    def test_should_right_and_stop_when_encoder_value_more_than_150(self):
        current_joint_id = "s"
        current_joint_name = "shoulder"
        current_motor = Motor(1, 2)
        current_encoder_value = 151

        joint = VerticalJoint(current_joint_id, current_joint_name,
                              current_motor, current_encoder_value)

        joint.down()

        self.assertFalse(joint.motor.is_on())
コード例 #20
0
    def test_should_griped(self):
        gripper_motor = Motor(1, 2)

        gripper = Gripper(gripper_motor)

        gripper.close()

        self.assertTrue(gripper.motor.is_on())

        gripper.gripped()

        self.assertFalse(gripper.motor.is_on())
コード例 #21
0
    def test_should_stop_when_encoder_value_equals_150(self):
        current_joint_id = "s"
        current_joint_name = "shoulder"
        current_motor = Motor(1, 2)
        current_encoder_value = 150

        joint = VerticalJoint(current_joint_id, current_joint_name,
                              current_motor, current_encoder_value)

        joint.up()

        self.assertFalse(joint.motor.is_on())
コード例 #22
0
    def test_should_move_up_when_encoder_Value_less_than_150(self):
        current_joint_id = "s"
        current_joint_name = "shoulder"
        current_motor = Motor(1, 2)
        current_encoder_value = 60

        joint = VerticalJoint(current_joint_id, current_joint_name,
                              current_motor, current_encoder_value)

        joint.up()

        self.assertTrue(joint.motor.is_on())
コード例 #23
0
    def __init__(self, control):
        Configuration().configure()
        self._executor = RPiExecutor()

        waist = Motor(13, 19)
        shoulder = Motor(23, 24)
        elbow = Motor(17, 27)
        wrist = Motor(16, 20)
        gripper = Motor(5, 6)
        led = Pin(21)

        arm = Arm_partial(waist, shoulder, elbow, wrist, gripper, led)
        self._arm = arm
        self._led = led

        if control == None:
            print "runtime constructor"
            self._control = Control(None, self._executor, self._led)

        else:
            print "test constructor"
            self._control = control
コード例 #24
0
    def test_should_turn_Left_and_then_turn_right(self):
        shoulder = Motor(0, 0)

        shoulder.turn_right()
        self.assertEqual(True, shoulder.pin_b.value)
        self.assertEqual(False, shoulder.pin_a.value)

        shoulder.turn_left()
        self.assertEqual(True, shoulder.pin_a.value)
        self.assertEqual(False, shoulder.pin_b.value)

        self.assertTrue(shoulder.is_on())
コード例 #25
0
    def should_be_call_parser_with_joint(self):
        Configuration().configure()
        self._executor = RPiExecutor()

        waist = Motor(13, 19)
        shoulder = Motor(23, 24)
        elbow = Motor(17, 27)
        wrist = Motor(16, 20)
        gripper = Motor(5, 6)
        led = Pin(21)
        arm = Arm_partial(waist, shoulder, elbow, wrist, gripper, led)
        self._arm = arm
        self._led = led
        control = Control(None, self._executor, self._led)
        pi_arm = PiArm(control)

        input_primitive_joints = "g c 10"
        pi_arm.execute_joint = MagicMock()
        expected_joint = Joint_partial("g", "c", 10)

        pi_arm.parse_joints(input_primitive_joints)

        pi_arm.execute_joint.assert_called_with(expected_joint)
コード例 #26
0
    def test_should_return_wrist_joint(self):
        vertical_joints = self.get_vertical_joints()

        expected_wrist_id = "u"
        expected_wrist_name = "wrist"
        expected_motor = Motor(1, 2)
        expected_encoder_value = 60

        expected_elbow = VerticalJoint(expected_wrist_id, expected_wrist_name, expected_motor,
                                       expected_encoder_value)

        arm = Arm(None, vertical_joints, None)

        self.assertEquals(arm.get_vertical_joint(expected_wrist_id), expected_elbow)
コード例 #27
0
    def test_should_configure_arm(self):
        expected_waist = Motor(13, 19)
        expected_shoulder = Motor(23, 24)
        expected_elbow = Motor(17, 27)
        expected_wrist = Motor(16, 20)
        expected_gripper = Motor(5, 6)
        expected_led = Pin(21)

        expected_arm = Arm_partial(expected_waist, expected_shoulder, expected_elbow, expected_wrist, expected_gripper, expected_led)

        pi_arm = PiArm(None)
        current_arm = pi_arm._arm

        self.assertEquals(current_arm.waist.pin_a.number, expected_arm.waist.pin_a.number)
        self.assertEquals(current_arm.waist.pin_b.number, expected_arm.waist.pin_b.number)
        self.assertEquals(current_arm.shoulder.pin_a.number, expected_arm.shoulder.pin_a.number)
        self.assertEquals(current_arm.shoulder.pin_b.number, expected_arm.shoulder.pin_b.number)
        self.assertEquals(current_arm.elbow.pin_a.number, expected_arm.elbow.pin_a.number)
        self.assertEquals(current_arm.elbow.pin_b.number, expected_arm.elbow.pin_b.number)
        self.assertEquals(current_arm.wrist.pin_a.number, expected_arm.wrist.pin_a.number)
        self.assertEquals(current_arm.wrist.pin_b.number, expected_arm.wrist.pin_b.number)
        self.assertEquals(current_arm.gripper.pin_a.number, expected_arm.gripper.pin_a.number)
        self.assertEquals(current_arm.gripper.pin_b.number, expected_arm.gripper.pin_b.number)
        self.assertEquals(current_arm.led.number, expected_arm.led.number)
コード例 #28
0
import sys

sys.path.append('../../')

from src.main.domain.pin import Pin
from src.main.logic.parser import Parser
from src.main.Infra.rpiexecutor import RPiExecutor
from src.main.logic.control import Control
from src.main.domain.motor import Motor
from src.main.configuration.configuration import Configuration
from src.main.domain.arm_partial import Arm_partial

Configuration().configure()
executor = RPiExecutor()

waist = Motor(13, 19)
shoulder = Motor(23, 24)
elbow = Motor(17, 27)
wrist = Motor(16, 20)
gripper = Motor(5, 6)
led = Pin(21)

arm = Arm_partial(waist, shoulder, elbow, wrist, gripper, led)

while True:
    primitive_joints = raw_input("enter a joints <(name direction value) ... > : ")

    parser = Parser()
    joints = parser.get_joints(primitive_joints)

    for joint in joints:
コード例 #29
0
    def test_should_be_pin1_and2_when_configure_motor(self):
        motor = Motor(1, 2)

        self.assertEqual(1, motor.pin_a.number)
        self.assertEqual(2, motor.pin_b.number)
コード例 #30
0
    def test_should_return_none_motor(self):
        waist = Motor(13, 19)
        arm = Arm_partial(waist, None, None, None, None, None)
        current_waist = arm.get_motor("x")

        self.assertIsNone(current_waist)