def state_machine_example(): state = I32Value(0) iters = I32Value(0) amplitude = DoubleValue(1000) stop = BooleanValue(False) output = ChannelReference('Aliases/DesiredRPM') while stop.value != True and iters.value < 10: # noqa: E712 NI recommends you use comparison instead of identity. state.value = rand(7) if state.value == 0: wait(2) elif state.value == 1: sine_wave(output, amplitude, 1, 0, 0, 2) elif state.value == 2: square_wave(output, amplitude, 5, 0, 0, 50, 2) elif state.value == 3: triangle_wave(output, amplitude, 1, 0, 0, 2) elif state.value == 4: uniform_white_noise_wave(output, amplitude, tickcountus(), 2) elif state.value == 5: ramp(output, -amplitude.value, amplitude, 2) elif state.value == 6: sawtooth_wave(output, amplitude, 1, 0, 0, 2) else: stop.value = True iters.value += 1 state.value = rand(7)
def engine_demo_basic(engine_power, desired_rpm): """Turn on the engine, set the desired_rpm to the passed value for 20 seconds, and shut down the engine. You must access parameters through their ".value" property. """ # You can access a channel with a ChannelReference engine_power_chan = ChannelReference('Aliases/EnginePower') desired_rpm_chan = ChannelReference('Aliases/DesiredRPM') engine_power_chan.value = engine_power.value desired_rpm_chan.value = desired_rpm.value wait(DoubleValue(20)) engine_power_chan.value = False desired_rpm_chan.value = 0
def enter_30(): ReAX_GearA_Disable_chan.value = 0 ReAX_GearB_Disable_chan.value = 0 # Power on button Power_On_chan.value = 1 # Check System Status if SystemStatus_chan.value != 25: error_status.value = True # Push autonomous driving button Autonomous_Drive_chan.value = 1 wait(DoubleValue(1)) Autonomous_Drive_chan.value = 0 # Check System Status if SystemStatus_chan.value != 30: error_status.value = True MODE_TRANS_chan.value = 18 enter_autonomous_succeeded.value = True
def enter_30(): error_status = BooleanValue(True) # channel references Power_On_chan = ChannelReference( 'Targets/TruckSim_TTC580/Hardware/Chassis/DAQ/PXI1Slot2/Digital Output/port0/Power on') ReAX_GearA_Disable_chan = ChannelReference( 'Targets/TruckSim_TTC580/User Channels/NI-XNET/VCAN-B/ReAX_GearA (486535187)/ReAX_GearA (486535187) Disable') ReAX_GearB_Disable_chan = ChannelReference( 'Targets/TruckSim_TTC580/User Channels/NI-XNET/VCAN-B/ReAX_GearB (486535443)/ReAX_GearB (486535443) Disable') RemoteAccelPedalPos_chan = ChannelReference( 'Targets/TruckSim_TTC580/Hardware/Chassis/NI-XNET/CAN/Vehicle CAN/Incoming/Single-Point/EEC2_CMD (418382648)/RemoteAccelPedalPos') XBRBrakeDemand_chan = ChannelReference( 'Targets/TruckSim_TTC580/Hardware/Chassis/NI-XNET/CAN/Vehicle CAN/Incoming/Single-Point/XBR (201591804)/XBRBrakeDemand') XPRPReq_chan = ChannelReference( 'Targets/TruckSim_TTC580/Hardware/Chassis/NI-XNET/CAN/VCAN-B/Incoming/Single-Point/XPRCmd (218060344)/XPRPReq') Autonomous_Drive_chan = ChannelReference('Targets/TruckSim_TTC580/Hardware/Chassis/DAQ' '/PXI1Slot2/Digital Output/port0/Autonomous Drive') MODE_TRANS_chan = ChannelReference( 'Targets/TruckSim_TTC580/Simulation Models/Models/trucksim_LVRT/Inports/MODE_TRANS') SystemStatus_chan = ChannelReference( 'Targets/TruckSim_TTC580/Hardware/Chassis/NI-XNET/CAN/Server CAN/Incoming/Single-Point/SystemStatus (69785)/SystemStatus') # *** end initialization # *** steps # start sending lateral drive ReAX_GearA_Disable_chan.value = 0 ReAX_GearB_Disable_chan.value = 0 # power on VCU Power_On_chan.value = 1 wait(DoubleValue(3)) if SystemStatus_chan.value != 25: error_status.value = False Autonomous_Drive_chan.value = 1 wait(DoubleValue(1)) Autonomous_Drive_chan.value = 0 if SystemStatus_chan.value != 30: error_status.value = False MODE_TRANS_chan.value = 18 return error_status.value
def self_check(): # *** initialization # variables TestPass = BooleanValue(True) # channel references Power_On_chan = ChannelReference( 'Targets/TruckSim_TTC580/Hardware/Chassis/DAQ/PXI1Slot2/Digital Output/port0/Power on') ReAX_GearA_Disable_chan = ChannelReference( 'Targets/TruckSim_TTC580/User Channels/NI-XNET/VCAN-B/ReAX_GearA (486535187)/ReAX_GearA (486535187) Disable') ReAX_GearB_Disable_chan = ChannelReference( 'Targets/TruckSim_TTC580/User Channels/NI-XNET/VCAN-B/ReAX_GearB (486535443)/ReAX_GearB (486535443) Disable') RemoteAccelPedalPos_chan = ChannelReference( 'Targets/TruckSim_TTC580/Hardware/Chassis/NI-XNET/CAN/Vehicle CAN/Incoming/Single-Point/EEC2_CMD (418382648)/RemoteAccelPedalPos') XBRBrakeDemand_chan = ChannelReference( 'Targets/TruckSim_TTC580/Hardware/Chassis/NI-XNET/CAN/Vehicle CAN/Incoming/Single-Point/XBR (201591804)/XBRBrakeDemand') XPRPReq_chan = ChannelReference( 'Targets/TruckSim_TTC580/Hardware/Chassis/NI-XNET/CAN/VCAN-B/Incoming/Single-Point/XPRCmd (218060344)/XPRPReq') # *** end initialization # *** steps # start sending lateral drive ReAX_GearA_Disable_chan.value = 0 ReAX_GearB_Disable_chan.value = 0 # power on VCU Power_On_chan.value = 1 wait(DoubleValue(3)) # check RemoteAccelPedalPos, XBRBrakeDemand and XPRPReq has been zeroed if RemoteAccelPedalPos_chan.value != 0 or \ -0.02 > XBRBrakeDemand_chan.value or XBRBrakeDemand_chan.value > 0.02 or \ XPRPReq_chan.value != 0: TestPass.value = False # wait for relays to switch on wait(DoubleValue(5)) # *** end steps return TestPass.value
#Set Stop Trigger (Duration) Logging_Specification_Ref.StopTrigger = DefaultTrigger(True) Logging_Specification_Ref.PostTriggerDuration = 4 #Start Data Logging Session Data_Logging_Manager_Ref.StartDataLoggingSession("myLoggingSession",Logging_Specification_Ref) ################################################# ###Changes channel values, wait and reset ### #Prepare values that will be assigned engine_power = BooleanValue(True) desired_rpm = DoubleValue(3000) wait_time = DoubleValue(10) # You can access a channel with a ChannelReference engine_power_chan = ChannelReference('Aliases/EnginePower') desired_rpm_chan = ChannelReference('Aliases/DesiredRPM') engine_power_chan.value = engine_power.value desired_rpm_chan.value = desired_rpm.value wait(wait_time.value) engine_power_chan.value = False desired_rpm_chan.value = 0 ############################################### #Stop Data Logging Session logs_array = ["logs"] Data_Logging_Manager_Ref.StopDataLoggingSession("myLoggingSession",True,Array[str](logs_array))
from NationalInstruments.VeriStand.ClientAPI.Logging import DefaultTrigger from NationalInstruments.VeriStand.ClientAPI.Logging import * from System import Array #Import command line library import os #Import elements to be able to deploy the project and connect to the workspace from NationalInstruments.VeriStand.ClientAPI import DeployOptions #Launch NI VeriStand and open project projectpath = r"C:\Users\chericks\Documents\VeriStand Projects\Engine Demo\Engine Demo.nivsprj" os.startfile(projectpath) wait(30) #Open Workspace Reference. We use localhost because logging takes place in the local computer Workspace_Ref = Factory().GetIWorkspace2("localhost") #New DeployOptions Reference DeployOptions_Ref = DeployOptions() DeployOptions_Ref.DeploySystemDefinition = True DeployOptions_Ref.Timeout = 60000 DeployOptions_Ref.CalibrationFilePath = r"C:\Users\chericks\Documents\VeriStand Projects\Engine Demo\Engine Demo.nivscf" DeployOptions_Ref.FilteredTargets = "" #Connect to System systemDefinitionFilePath = r"C:\Users\chericks\Documents\VeriStand Projects\Engine Demo\Engine Demo.nivssdf" Workspace_Ref.ConnectToSystem(systemDefinitionFilePath, DeployOptions_Ref)