@@ -79,6 +79,7 @@ def rotate_around_joint_axis(self, angle_of_rotation, axis_of_rotation):
79
79
:type angle_of_rotation: float (radians)
80
80
:param axis_of_rotation: X, Y, or Z axis to apply around the objects specific X, Y, or Z axes
81
81
:type axis_of_rotation: class:`vpython.vector`
82
+ :raise ValueError: The given axis_of_rotation must be one of the default X, Y, Z vectors (e.g. x_axis_vector)
82
83
"""
83
84
# Determine the axis of rotation based on the given joint axis direction
84
85
# Then add the rotation amount to the axis counter
@@ -274,6 +275,7 @@ def get_rotation_angle(self, axis):
274
275
:type axis: class:`vpython.vector`
275
276
:return: Current angle of rotation with respect to world (includes rotation from previous joints)
276
277
:rtype: float (radians)
278
+ :raise ValueError: The given axis_of_rotation must be one of the default X, Y, Z vectors (e.g. x_axis_vector)
277
279
"""
278
280
# Ensure copying value not reference
279
281
ans = 0.0
@@ -284,7 +286,9 @@ def get_rotation_angle(self, axis):
284
286
elif axis .equals (z_axis_vector ):
285
287
ans += self .__z_rotation
286
288
else :
287
- ans += self .__y_rotation
289
+ error_str = "Bad input vector given ({0}). Must be either x_axis_vector ({1}), y_axis_vector ({2})," \
290
+ "or z_axis_vector ({3})."
291
+ raise ValueError (error_str .format (axis ), x_axis_vector , y_axis_vector , z_axis_vector )
288
292
289
293
return ans
290
294
@@ -296,6 +300,7 @@ def get_axis_vector(self, axis):
296
300
:type axis: class:`vpython.vector`
297
301
:return: Current vector representation of the joints X, Y, or Z axis
298
302
:rtype: class:`vpython.vector`
303
+ :raise ValueError: The given axis_of_rotation must be one of the default X, Y, Z vectors (e.g. x_axis_vector)
299
304
"""
300
305
# Return new vectors to avoid pass by reference
301
306
if axis .equals (x_axis_vector ):
@@ -305,7 +310,9 @@ def get_axis_vector(self, axis):
305
310
elif axis .equals (z_axis_vector ):
306
311
return vector (self .__z_vector )
307
312
else :
308
- return vector (self .__y_vector )
313
+ error_str = "Bad input vector given ({0}). Must be either x_axis_vector ({1}), y_axis_vector ({2})," \
314
+ "or z_axis_vector ({3})."
315
+ raise ValueError (error_str .format (axis ), x_axis_vector , y_axis_vector , z_axis_vector )
309
316
310
317
def get_joint_type (self ):
311
318
"""
@@ -459,6 +466,7 @@ class GraphicalRobot:
459
466
460
467
:param joints: A list of the joints in order from base (0) to gripper (end), or other types.
461
468
:type joints: list
469
+ :raise ValueError: The given length of joints must not be 0
462
470
"""
463
471
464
472
def __init__ (self , joints ):
@@ -514,6 +522,8 @@ def set_joint_angle(self, link_num, new_angle):
514
522
:type link_num: int
515
523
:param new_angle: The required angle to set the arm rotated towards
516
524
:type new_angle: float (radians)
525
+ :raise IndexError: Link index must be between 0 (inclusive) and number of joints (exclusive)
526
+ :raise TypeError: The joint index chosen must be indexing a revolute joint
517
527
"""
518
528
if (link_num < 0 ) or (link_num >= self .num_joints ):
519
529
error_str = "link number given ({0}) is not between range of 0 (inclusive) and {1} (exclusive)"
@@ -538,7 +548,7 @@ def set_joint_angle(self, link_num, new_angle):
538
548
self .__position_joints ()
539
549
else :
540
550
error_str = "Given joint {0} is not a revolute joint. It is a {1} joint"
541
- raise ValueError (error_str .format (link_num , self .joints [link_num ].get_joint_type ()))
551
+ raise TypeError (error_str .format (link_num , self .joints [link_num ].get_joint_type ()))
542
552
543
553
def set_all_joint_angles (self , new_angles ):
544
554
"""
@@ -547,6 +557,7 @@ def set_all_joint_angles(self, new_angles):
547
557
:param new_angles: List of new angles (radians) to set each joint to.
548
558
Must have the same length as number of joints in robot arm, even if the joints aren't revolute
549
559
:type new_angles: float list (radians)
560
+ :raise IndexError: The length of the given list must equal the number of joints.
550
561
"""
551
562
# Raise error if lengths don't match
552
563
if len (new_angles ) != len (self .joints ):
0 commit comments