Commits

German Larrain committed 5c8b709

demos: replaced prints to console with logging

  • Participants
  • Parent commits 5581277

Comments (0)

Files changed (20)

File demos/CentrifugalForceTest.py

 analytical solution exists.
 
 """
-from ars.app import Program, dispatcher
+from ars.app import Program, dispatcher, logger
 import ars.utils.mathematical as mut
 import ars.constants as cts
 from ars.model.simulator import signals
 
 			print((ball_pos, ball_vel, ball_omega, theta_sim))
 
-		except Exception as e:
-			print('Exception when executing on_pre_frame: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_pre_frame")
 
 	def inc_joint1_vel(self):
 		self.joint1_vel_user += self.POLE_SPEED_STEP

File demos/ControlledSimpleArm.py

 There's friction proportional to angle speed, for both joints.
 
 """
-from ars.app import Program, dispatcher
+from ars.app import Program, dispatcher, logger
 import ars.utils.mathematical as mut
 import ars.constants as cts
 from ars.model.simulator import signals
 			output_data(time, self.sp, cv, self.sp - cv, mv)
 			#print('q1p: %f, q2p: %f' % (q1p, q2p))
 
-		except Exception as e:
-			print('Exception when executing on_pre_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_pre_step")
 
 	def rotate_clockwise(self):
 		self.apply_torque_to_joints(self.R1_TORQUE, 0)

File demos/IROS/example1_bouncing_ball.py

 must be set to 0.9, instead of the default 0.2 value.
 
 """
-from ars.app import Program, dispatcher
+from ars.app import Program, dispatcher, logger
 from ars.model.simulator import signals
 
 
 			print('%.7e\t%.7e\t%.7e' % (time, pos[1], vel[1]))
 
 		except Exception:
-			print('Exception when executing on_pre_step')
+			logger.exception("Exception when executing on_pre_step")

File demos/IROS/example2_conical_pendulum.py

 
 """
 import ars.app
-from ars.app import Program, Simulation
+from ars.app import Program, Simulation, logger
 from ars.model.simulator import signals
 import ars.utils.mathematical as mut
 import ars.constants as cts
 
 			print('%.7e\t%.7e\t%.7e\t%.7e\t%.7e' % (time, q1, q1p, q2, q2p))
 
-		except Exception as e:
-			print('Exception when executing on_pre_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_pre_step")
 
 	def get_torque_to_apply(self, time):
 		if time < self.SATURATION_TIME:

File demos/IROS/example3_speed_profile.py

 """
 import ars.exceptions as exc
 
-from ..VehicleWithArm import VehicleWithArm, mut
+from ..VehicleWithArm import VehicleWithArm, logger, mut
 
 
 class Example3(VehicleWithArm):
 			print('%.7e\t%.7e\t%.7e\t%.7e\t%.7e\t%.7e\t%.7e\t%.7e\t%.7e' %
 			      (time, pos[0], cv, sp, q1, q1p, q2, q2p, torque))
 
-		except Exception as e:
-			print('Exception when executing on_pre_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_pre_step")
 
 	def calc_desired_speed(self, time):
 

File demos/IROS/example4_sinusoidal_terrain.py

 from ars.model.simulator import Simulation, signals
 import ars.utils.mathematical as mut
 
-from ..VehicleWithArm import VehicleWithArm
+from ..VehicleWithArm import VehicleWithArm, logger
 
 
 def random_heightfield(num_x, num_z, scale=1.0):
 			      (time, pos[0], pos[1], pos[2], q1, torque1, q2, torque2,
 			       wheels_torque))
 
-		except Exception as e:
-			print('Exception when executing on_pre_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_pre_step")
 
 	def get_arm_compensation(self, q1, q2):
 		"""Calculate the control torque with a PD controller."""

File demos/IROS/example5_vehicle_with_user_input.py

 must be set to 50, instead of the default 500 value.
 
 """
-from ..VehicleWithArm import VehicleWithArm
+from ..VehicleWithArm import VehicleWithArm, logger
 
 
 class Example5(VehicleWithArm):
 			self.torque_w1 = 0.0
 			self.torque_w2 = 0.0
 
-		except Exception as e:
-			print('Exception when executing on_pre_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_pre_step")
 
 	def apply_torque_to_wheels(self, torque1, torque2):
 		VehicleWithArm.apply_torque_to_wheels(self, torque1, torque2)

File demos/VehicleWithArm.py

 joint speed.
 
 """
-from ars.app import Program, dispatcher
+from ars.app import Program, dispatcher, logger
 import ars.utils.mathematical as mut
 import ars.constants as cts
 from ars.model.simulator import signals
 
 			print('q1p: %f, q2p: %f' % (q1p, q2p))
 
-		except Exception as e:
-			print('Exception when executing on_pre_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_pre_step")
 
 	def apply_torque_to_wheels(self, torque1, torque2):
 		if torque1 is not None:

File demos/VehicleWithControlledArm.py

 joint speed. The second joint has a PD controller.
 
 """
-from .VehicleWithArm import VehicleWithArm
+from .VehicleWithArm import VehicleWithArm, logger
 
 
 def output_data(time, sp, cv, error, torque):
 
 			output_data(time, self.sp, cv, self.sp - cv, mv)
 
-		except Exception as e:
-			print('Exception when executing on_pre_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_pre_step")
 
 	def increase_sp(self):
 		"""Increase angle set point."""

File demos/sensors/accelerometer1.py

 from ars.model.robot import sensors
 from ars.model.simulator import signals
 
-from .base import FallingBalls, PrintDataMixin
+from .base import FallingBalls, PrintDataMixin, logger
 
 
 class Accelerometer(FallingBalls, PrintDataMixin):
 		try:
 			time = self.sim.sim_time
 			self.sensor.on_change(time)
-		except Exception as e:
-			print('Exception when executing on_post_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_post_step")

File demos/sensors/accelerometer2.py

 """
 from ars.model.robot import sensors
 
-from .base import CentrifugalForce2, PrintDataMixin
+from .base import CentrifugalForce2, PrintDataMixin, logger
 
 
 class Accelerometer(CentrifugalForce2, PrintDataMixin):
 		try:
 			time = self.sim.sim_time
 			self.sensor.on_change(time)
-		except Exception as e:
-			print('Exception when executing on_post_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_post_step")

File demos/sensors/base.py

 """Base program classes to create demos using sensors.
 
 """
-from ars.app import Program, dispatcher
+from ars.app import Program, dispatcher, logger
 import ars.constants as cts
 from ars.model.simulator import signals
 import ars.utils.mathematical as mut
 		try:
 			self.set_joint1_speed()
 			self.apply_friction()
-		except Exception as e:
-			print('Exception when executing on_pre_frame: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_pre_frame")
 
 	def inc_joint1_vel(self):
 		"""Increase joint1's speed set point."""

File demos/sensors/body.py

 from ars.model.robot import sensors
 from ars.model.simulator import signals
 
-from .base import FallingBalls, PrintDataMixin
+from .base import FallingBalls, PrintDataMixin, logger
 
 
 class GPSSensor(FallingBalls, PrintDataMixin):
 		try:
 			time = self.sim.sim_time
 			self.sensor.on_change(time)
-		except Exception as e:
-			print('Exception when executing on_post_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_post_step")

File demos/sensors/kinetic_energy1.py

 from ars.model.robot import sensors
 from ars.model.simulator import signals
 
-from .base import FallingBalls, PrintDataMixin
+from .base import FallingBalls, PrintDataMixin, logger
 
 
 class KineticEnergy(FallingBalls, PrintDataMixin):
 		try:
 			time = self.sim.sim_time
 			self.sensor.on_change(time)
-		except Exception as e:
-			print('Exception when executing on_post_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_post_step")

File demos/sensors/laser.py

 from ars.utils.geometry import calc_rotation_matrix
 from ars.utils.mathematical import add3, mult_by_scalar3, pi, rotate3
 
-from .base import FallingBalls, PrintDataMixin
+from .base import FallingBalls, PrintDataMixin, logger
 
 
 class LaserSensor(FallingBalls, PrintDataMixin):
 		try:
 			time = self.sim.sim_time
 			self.sensor.on_change(time)
-		except Exception as e:
-			print('Exception when executing on_post_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_post_step")
 
 
 class VisualLaser(LaserSensor):

File demos/sensors/potential_energy1.py

 from ars.model.robot import sensors
 from ars.model.simulator import signals
 
-from .base import FallingBalls, PrintDataMixin
+from .base import FallingBalls, PrintDataMixin, logger
 
 
 class PotentialEnergy(FallingBalls, PrintDataMixin):
 		try:
 			time = self.sim.sim_time
 			self.sensor.on_change(time)
-		except Exception as e:
-			print('Exception when executing on_post_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_post_step")

File demos/sensors/rotary_joint.py

 """
 from ars.model.robot import sensors
 
-from .base import CentrifugalForce, PrintDataMixin
+from .base import CentrifugalForce, PrintDataMixin, logger
 
 
 class RotaryJointSensor(CentrifugalForce, PrintDataMixin):
 		try:
 			time = self.sim.sim_time
 			self.sensor.on_change(time)
-		except Exception as e:
-			print('Exception when executing on_pre_frame: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_pre_frame")

File demos/sensors/system_total_energy1.py

 from ars.model.robot import sensors
 from ars.model.simulator import signals
 
-from .base import FallingBalls, PrintDataMixin
+from .base import FallingBalls, PrintDataMixin, logger
 
 
 class SystemTotalEnergy(FallingBalls, PrintDataMixin):
 		try:
 			time = self.sim.sim_time
 			self.sensor.on_change(time)
-		except Exception as e:
-			print('Exception when executing on_post_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_post_step")

File demos/sensors/total_energy1.py

 from ars.model.robot import sensors
 from ars.model.simulator import signals
 
-from .base import FallingBalls, PrintDataMixin
+from .base import FallingBalls, PrintDataMixin, logger
 
 
 class TotalEnergy(FallingBalls, PrintDataMixin):
 		try:
 			time = self.sim.sim_time
 			self.sensor.on_change(time)
-		except Exception as e:
-			print('Exception when executing on_post_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_post_step")

File demos/sensors/velometer1.py

 from ars.model.robot import sensors
 from ars.model.simulator import signals
 
-from .base import FallingBalls, PrintDataMixin
+from .base import FallingBalls, PrintDataMixin, logger
 
 
 class Velometer(FallingBalls, PrintDataMixin):
 		try:
 			time = self.sim.sim_time
 			self.sensor.on_change(time)
-		except Exception as e:
-			print('Exception when executing on_post_step: %s' % str(e))
+		except Exception:
+			logger.exception("Exception when executing on_post_step")