How to use get_idle_state method in avocado

Best Python code snippet using avocado_python

VIS.py

Source:VIS.py Github

copy

Full Screen

...148 return alignment_check_decorator149##################################################150# STATE GENERATORS151##################################################152def get_idle_state():153 class IDLE(GuardState):154 @watchdog_check155 def main(self):156 self.susobj = sustools.Sus(ezca)157 self.ol_shut_off = False158 @watchdog_check159 def run(self):160 if not olDamp_in_use(self.susobj):161 return True162 # OPLEV damping: for optics that have optical levers:163 # Check OpLev Sum and turn off OpLev damping if below164 # threshold (i.e. beam moved off QPD).165 # buffer for last couple of seconds of oplev sums166 # else if servo on167 if olDamp_engaged(self.susobj):168 # read the current values169 [pit, yaw, olsum] = self.susobj.olRead()170 # if sum below threshold...171 if abs(olsum) <= susconst.ol_off_threshold:172 # shut off the servo173 log('Optical lever sum dropped below off_threshold of: %d' % susconst.ol_off_threshold)174 self.susobj.olDampOutputSwitchWrite('OFF')175 self.ol_shut_off = True176 else:177 self.ol_shut_off = False178 # notify if the servo was shut off179 elif self.ol_shut_off:180 notify('OPLEV damping shut off, sum fell below threshold')181 return True182 return IDLE183def get_aligning_state(alignment, isc_gain):184 class ALIGNING_STATE(GuardState):185 request = False186 @watchdog_check187 def main(self):188 susobj = sustools.Sus(ezca)189 ramp_align_offsets(susobj, 'ON', susconst.rampTime)190 ramp_isc_gains(susobj, isc_gain, susconst.rampTime)191 # FIXME: use new ezca.is_ramping methods when available,192 # instead of using a timer193 log('Waiting %ds for ramps...' % susconst.rampTime)194 self.timer['ramp'] = susconst.rampTime195 @watchdog_check196 def run(self):197 if not self.timer['ramp']:198 return199 return True200 return ALIGNING_STATE201def get_aligned_state(alignment, isc_gain):202 class ALIGNED_STATE(GuardState):203 @watchdog_check204 @alignment_check(alignment) 205 def main(self):206 susobj = sustools.Sus(ezca)207 # we do this here so that you can re-request this state and208 # reset the alignements if they've changed209 if not is_aligned(susobj, alignment):210 set_alignment(susobj, alignment, susconst.rampTime)211 @watchdog_check212 @alignment_check(alignment)213 def run(self):214 return True215 return ALIGNED_STATE216 217##################################################218# STATES219##################################################220request = 'ALIGNED'221nominal = 'ALIGNED'222class INIT(GuardState):223 @watchdog_check224 def main(self):225 self.susobj = sustools.Sus(ezca)226 # FIXME: this only identifies that the alignment offsets are227 # active, but does not distinguish ALIGNED from MISALIGNED, or228 # check for damping loops already engaged229 if self.susobj.masterSwitchRead():230 if all(self.susobj.dampOutputSwitchRead()):231 if all(self.susobj.alignOffsetSwitchRead()):232 return 'ALIGNED'233 else:234 return 'DAMPED'235 else:236 log('Resetting DAMPED...')237 # make sure the alignment offsets aren't on238 ramp_align_offsets(self.susobj, 'OFF', susconst.rampTime)239 # FIXME: turn on the OLDAMP loops here since we don't240 # have a way to check if they're on already241 if olDamp_in_use(self.susobj):242 self.susobj.olDampOutputSwitchWrite('ON')243 self.timer['ramp'] = susconst.rampTime244 self.return_state = 'DAMPED'245 else:246 log('Resetting SAFE...')247 reset_safe(self.susobj, susconst.rampTime)248 self.timer['ramp'] = susconst.rampTime249 self.return_state = 'SAFE'250 log("next state: %s" % self.return_state)251 @watchdog_check252 def run(self):253 if not self.timer['ramp']:254 return255 if self.return_state == 'SAFE':256 log('Turning off Master Switch')257 self.susobj.masterSwitchWrite('OFF')258 return self.return_state259class TRIPPED(GuardState):260 index = 1261 redirect = False262 request = False263 def main(self):264 self.susobj = sustools.Sus(ezca)265 # for reporting trip status266 is_tripped(self.susobj)267 reset_safe(self.susobj, susconst.rampTime)268 log('Waiting %ds for ramps...' % susconst.rampTime)269 self.timer['ramp'] = susconst.rampTime270 self.switch_off = False271 def run(self):272 # for reporting trip status273 is_tripped(self.susobj)274pppp if self.timer['ramp'] and not self.switch_off:275 log('Turning off Master Switch')276 self.susobj.masterSwitchWrite('OFF')277 self.switch_off = True278 # finish the state if we're no longer tripped279 if not is_tripped(self.susobj):280 return True281class RESET(GuardState):282 index = 9283 goto = True284 request = False285 @watchdog_check286 def main(self):287 self.susobj = sustools.Sus(ezca)288 reset_safe(self.susobj, susconst.rampTime)289 # FIXME: use new ezca.is_ramping methods when available,290 # instead of using a timer291 log('Waiting %ds for ramps...' % susconst.rampTime)292 self.timer['ramp'] = susconst.rampTime293 @watchdog_check294 def run(self):295 if not self.timer['ramp']:296 return297 log('Turning off Master Switch')298 self.susobj.masterSwitchWrite('OFF')299 return True300SAFE = get_idle_state()301SAFE.index = 10302class MASTERSWITCH_ON(GuardState):303 index = 15304 request = False305 @watchdog_check306 def main(self):307 log('Turning On Master Switch')308 sustools.Sus(ezca).masterSwitchWrite('ON')309 return True310class ENGAGE_DAMPING(GuardState):311 index = 40312 request = False313 @watchdog_check314 def main(self):315 susobj = sustools.Sus(ezca)316 log('Turning on damping outputs')317 susobj.dampOutputSwitchWrite('ON')318 if olDamp_in_use(susobj):319 log('Turning on OL damping outputs')320 susobj.olDampOutputSwitchWrite('ON')321 return True322DAMPED = get_idle_state()323DAMPED.index = 50324ALIGNING = get_aligning_state('aligned', isc_gain=1)325ALIGNING.index = 90326#ALIGNED = get_aligned_state('aligned', isc_gain=1)327# FIXME: this needs to check that the alignment offset is still on328ALIGNED = get_idle_state()329ALIGNED.index = 100330# MISALIGNING = get_aligning_state('misaligned', isc_gain=0)331# MISALIGNED = get_aligned_state('misaligned', isc_gain=0)332class UNALIGNING(GuardState):333 index = 99334 request = False335 @watchdog_check336 def main(self):337 susobj = sustools.Sus(ezca)338 ramp_align_offsets(susobj, 'OFF', susconst.rampTime)339 ramp_isc_gains(susobj, 0, susconst.rampTime)340 # FIXME: use new ezca.is_ramping methods when available,341 # instead of using a timer342 log('Waiting %ds for ramps...' % susconst.rampTime)...

Full Screen

Full Screen

test_ripple.py

Source:test_ripple.py Github

copy

Full Screen

...50 # elements for all the servos.51 command_dict = state.command_dict()52 assert len(command_dict) == 1253def get_steady_state(gait, command):54 idle = gait.get_idle_state()55 gait.set_state(idle, command)56 for x in range(100):57 last = gait.advance_phase(0.01)58 assert abs(last.phase) < 0.0159 last.phase = 0.060 return last61def run_cycle(gait, start_state, command, total_time_s, time_step_s):62 old_state = gait.set_state(start_state, command).copy()63 # Things we will want to verify.64 #65 # * The robot moves at the expected rate/rotation66 stance_bearings = {}67 cur_time_s = 0.068 while cur_time_s < total_time_s:69 this_state = gait.advance_time(time_step_s)70 cur_time_s += time_step_s71 sanity_check_state(this_state)72 for leg_num in this_state.legs.keys():73 this_leg = this_state.legs[leg_num]74 old_leg = old_state.legs[leg_num]75 current_world_point = this_state.world_frame.map_from_frame(76 this_leg.frame, this_leg.point)77 old_world_point = old_state.world_frame.map_from_frame(78 old_leg.frame, old_leg.point)79 # Legs identified as in stance do not move in the world frame.80 if this_leg.mode == STANCE and old_leg.mode == STANCE:81 check_vectors_close(current_world_point, old_world_point)82 # No leg moves faster than X in the world frame.83 world_speed_mm_s = (current_world_point -84 old_world_point).length() / time_step_s85 assert world_speed_mm_s < 1000.086 # No Leg moves faster than Y in the body frame.87 current_body_point = this_state.body_frame.map_from_frame(88 this_leg.frame, this_leg.point)89 old_body_point = old_state.body_frame.map_from_frame(90 old_leg.frame, old_leg.point)91 body_speed_mm_s = (current_body_point -92 old_body_point).length() / time_step_s93 assert body_speed_mm_s < 600.094 if this_leg.mode == STANCE:95 shoulder_point = this_leg.shoulder_frame.map_from_frame(96 this_leg.frame, this_leg.point)97 bearing_deg = math.degrees(98 math.atan2(shoulder_point.x, shoulder_point.y))99 if not leg_num in stance_bearings:100 stance_bearings[leg_num] = {}101 bearing_deg_rounded = int(bearing_deg + 0.5)102 my_dict = stance_bearings[leg_num]103 my_dict[bearing_deg_rounded] = \104 my_dict.get(bearing_deg_rounded, 0.0) + time_step_s105 old_state = this_state.copy()106 return { 'stance_bearings' : stance_bearings }107def verify_symmetric_result(result):108 stance_bearings = result['stance_bearings']109 def verify_symmetric_stance(stance):110 leg_num, data = stance111 smallest = min(data.keys())112 biggest = max(data.keys())113 assert abs(abs(smallest) - abs(biggest)) <= 2.0114 less_than_zero = sum([val for key, val in data.iteritems()115 if key < 0.0])116 greater_than_zero = sum([val for key, val in data.iteritems()117 if key > 0.0])118 # TODO jpieper: Why shouldn't this be much smaller?119 assert abs(less_than_zero - greater_than_zero) < 0.45120 for stance in stance_bearings.items():121 verify_symmetric_stance(stance)122def test_ripple_basic():123 config = ripple.RippleConfig()124 mounts = [(90., 90.), (90., -90.), (-90., -90.), (-90., 90.)]125 ik_config = leg_ik.Configuration()126 ik_config.coxa_min_deg = -120.0127 ik_config.coxa_idle_deg = 0.0128 ik_config.coxa_max_deg = 120.0129 ik_config.coxa_length_mm = 60.0130 ik_config.femur_min_deg = -120.0131 ik_config.femur_idle_deg = 0.0132 ik_config.femur_max_deg = 120.0133 ik_config.femur_length_mm = 60.0134 ik_config.tibia_min_deg = -120.0135 ik_config.tibia_idle_deg = 0.0136 ik_config.tibia_max_deg = 120.0137 ik_config.tibia_length_mm = 60.0138 for leg_num in range(4):139 leg = ripple.LegConfig()140 leg.mount_x_mm = mounts[leg_num][0]141 leg.mount_y_mm = mounts[leg_num][1]142 leg.mount_z_mm = 0.0143 leg.idle_x_mm = 100.0144 leg.idle_y_mm = 0.0145 leg.idle_z_mm = 0.0146 this_ik_config = copy.copy(ik_config)147 this_ik_config.coxa_ident = leg_num * 3 + 0148 this_ik_config.femur_ident = leg_num * 3 + 1149 this_ik_config.tibia_ident = leg_num * 3 + 2150 leg.leg_ik = leg_ik.LizardIk(this_ik_config)151 config.mechanical.leg_config[leg_num] = leg152 config.mechanical.body_cog_x_mm = 0.0153 config.mechanical.body_cog_y_mm = 0.0154 config.mechanical.body_cog_z_mm = 0.0155 config.max_cycle_time_s = 4.0156 config.lift_height_mm = 20.0157 config.min_swing_percent = 50.0158 config.max_swing_percent = 100.0159 config.leg_order = [0, 2, 1, 3]160 config.body_z_offset_mm = 60.0161 gait = ripple.RippleGait(config)162 # We want to:163 # 1. get the idle state164 # 2. initialize ourselves to that165 #166 # then,167 # a) command no motion... verify stepping in place168 # b) command forward motion169 # c) command rotation170 # d) do all of the above with each of the other 6 degrees of171 # freedom altered172 # Also, we will want to test changes in command, and coming to a173 # stop.174 idle_state = gait.get_idle_state()175 assert len(idle_state.legs) == 4176 assert idle_state.legs[0].point == leg_ik.Point3D(190, 90, 0)177 assert idle_state.legs[1].point == leg_ik.Point3D(190, -90, 0)178 assert idle_state.legs[2].point == leg_ik.Point3D(-190, -90, 0)179 assert idle_state.legs[3].point == leg_ik.Point3D(-190, 90, 0)180 gait_graph = gait.get_gait_graph()181 assert len(gait_graph.leg) == 4182 sanity_check_state(idle_state)183 command = ripple.Command()184 run_cycle(gait, idle_state, command, 10.0, 0.01)185 run_cycle(gait, idle_state, command, 10.0, 0.0073)186 config.max_cycle_time_s = 1.7187 gait = ripple.RippleGait(config)188 run_cycle(gait, idle_state, command, 5.0, 0.01)189 command.translate_y_mm_s = 50.0190 steady_state = get_steady_state(gait, command)191 result = run_cycle(gait, steady_state, command, 7.0, 0.005)192 verify_symmetric_result(result)193 result = run_cycle(gait, steady_state, command, 7.0, 0.03)194 verify_symmetric_result(result)195 result = run_cycle(gait, steady_state, command, 7.0, 0.04)196 verify_symmetric_result(result)197 config.statically_stable = True198 gait = ripple.RippleGait(config)199 idle_state = gait.get_idle_state()200 command = ripple.Command()201 run_cycle(gait, idle_state, command, 10.0, 0.01)202def test_leg_order_parse():203 parse = ripple.RippleConfig.parse_leg_order204 assert parse('0,3,1,2') == [0, 3, 1, 2]205 assert parse('5,4,3,2,1') == [5, 4, 3, 2, 1]206 assert parse('(1,2),0,1') == [(1, 2), 0, 1]207 assert parse('0,(4,1),3,(2,5)') == [0, (4, 1), 3, (2, 5)]208 assert parse('( 1, 2), 0, 1 ') == [(1, 2), 0, 1]209 # Strings that should result in fractional results.210 assert parse('7,') == [7]211 assert parse('(7,') == []212 assert parse('3,),8,6') == [3]213 assert parse('2,3,(7,(8,6),1),0') == [2, 3]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful