Exemplo n.º 1
0
def less_to_channel_ref():
    a = BooleanValue(False)
    b = ChannelReference("Aliases/DesiredRPM")
    b.value = 5.0
    localhost_wait()
    a.value = 1 < b.value
    return a.value
def aug_bitwise_and_to_channel_ref():
    a = DoubleValue(1)
    b = ChannelReference("Aliases/DesiredRPM")
    b.value = 5.0
    localhost_wait()
    a.value &= b.value
    return a.value
Exemplo n.º 3
0
def equal_to_channel_ref():
    a = BooleanValue(True)
    b = ChannelReference("Aliases/DesiredRPM")
    b.value = 5.0
    localhost_wait()
    a.value = 1 == b.value
    return a.value
def sub_to_channel_ref():
    a = DoubleValue(0)
    b = ChannelReference("Aliases/DesiredRPM")
    b.value = 5.0
    localhost_wait()
    a.value = 1 - b.value
    return a.value
Exemplo n.º 5
0
def modulo_with_channel_ref():
    a = DoubleValue(0)
    b = ChannelReference("Aliases/DesiredRPM")
    b.value = 2.0
    localhost_wait()
    a.value = 3 % b.value
    return a.value
Exemplo n.º 6
0
def aug_modulo_to_channel_ref():
    a = DoubleValue(3)
    b = ChannelReference("Aliases/DesiredRPM")
    b.value = 2.0
    localhost_wait()
    a.value %= b.value
    return a.value
def test_realtimesequence_channel_reference_param():
    desired_rpm = ChannelReference('Aliases/DesiredRPM')
    desired_rpm.value = 100.101
    rtseq = RealTimeSequence(func1)
    actual = rtseq.run({"p": desired_rpm})
    actual.wait_for_result()
    assert actual.ret_val == 100.101
Exemplo n.º 8
0
def arithmetic_shift_right_augassign_channel_ref():
    a = DoubleValue(1)
    b = ChannelReference("Aliases/DesiredRPM")
    b.value = 5.0
    localhost_wait()
    a.value >>= b.value
    return a.value
Exemplo n.º 9
0
def abs_channel_ref():
    a = DoubleValue(0)
    b = ChannelReference("Aliases/DesiredRPM")
    b.value = -5.0
    localhost_wait()
    a.value = abs(b.value)
    return a.value
def gt_equal_to_channel_ref():
    a = BooleanValue(False)
    b = ChannelReference("Aliases/DesiredRPM")
    b.value = 1.0
    localhost_wait()
    a.value = 1 >= b.value
    return a.value
Exemplo n.º 11
0
def arithmetic_shift_right_to_channel_ref():
    a = DoubleValue(0)
    b = ChannelReference("Aliases/DesiredRPM")
    b.value = 5.0
    localhost_wait()
    a.value = 1 >> b.value
    return a.value
Exemplo n.º 12
0
def aug_mult_to_channel_ref():
    a = DoubleValue(2)
    b = ChannelReference("Aliases/DesiredRPM")
    b.value = 5.0
    localhost_wait()
    a.value *= b.value
    return a.value
def call_parameter_send_channel_ref_by_value():
    a = ChannelReference('Aliases/DesiredRPM')
    ret = DoubleValue(0)
    a.value = 67
    localhost_wait(0.5)
    _return_parameter_plus1_by_value(a)
    ret.value = a.value
    return ret.value
Exemplo n.º 14
0
def for_loop_range_with_channel_ref():
    a = DoubleValue(0)
    b = ChannelReference('Aliases/DesiredRPM')
    b.value = 10.0
    localhost_wait(0.2)
    for x in range(b.value):
        a.value += x
    return a
def call_clearfault():
    a = ChannelReference("Aliases/DesiredRPM")
    b = DoubleValue(0)
    c = BooleanValue(False)
    # Store initial channel value
    b.value = a.value
    fault(a, 1001)
    clearfault(a)
    # Try to assign back to the channel the initial value
    a.value = b.value
    # If everything went well the initial value and the current value should now be equal
    c.value = b.value == a.value
    return c.value
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 call_fault():
    a = ChannelReference("Aliases/DesiredRPM")
    b = DoubleValue(0)
    fault(a, 1001)
    b.value = a.value
    # cleanup the fault so that other tests are still able to use this channel
    clearfault(a)
    return b.value
Exemplo n.º 18
0
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 measure_set_point_response(setpoint, timeout, tolerance):
    """Sets the desired rpm to the specified setpoint and wait until the signal settles.

    The tolerance is used to create upper and lower boundaries for the signal.
    Returns the amount of time it takes the signal to settle or timeout.
    """
    actual_rpm = ChannelReference('Aliases/ActualRPM')
    desired_rpm = ChannelReference('Aliases/DesiredRPM')
    start_time = DoubleValue(0)
    settle_time = DoubleValue(0)

    desired_rpm.value = setpoint.value
    # Waits .5 seconds, so the gateway has time to update.
    localhost_wait(0.5)

    start_time.value = seqtime()
    wait_until_settled(actual_rpm, desired_rpm.value + tolerance.value,
                       desired_rpm.value - tolerance.value, DoubleValue(2.0),
                       timeout.value)
    settle_time.value = seqtime() - start_time.value
    return settle_time.value
Exemplo n.º 20
0
def run_engine_demo_advanced():
    """Run the engine_demo_advanced example.

    To handle a condition that stops a task (such as, the engine temperature rising above a safe value),
    use a try/finally block.

    Regardless of the result of the execution, the finally block can be used to safely shut down the engine.
    """
    try:
        warmup_succeeded = BooleanValue(False)
        engine_power = ChannelReference('Aliases/EnginePower')
        desired_rpm = ChannelReference('Aliases/DesiredRPM')
        actual_rpm = ChannelReference('Aliases/ActualRPM')
        engine_temp = ChannelReference('Aliases/EngineTemp')
        engine_power.value = True
        warmup_succeeded.value = engine_demo_advanced(desired_rpm, actual_rpm, engine_temp)
    finally:
        engine_power.value = False
        desired_rpm.value = 0
    return warmup_succeeded.value
Exemplo n.º 21
0
def enter_autonomous():
    error_status = BooleanValue(False)
    enter_autonomous_complete = BooleanValue(False)
    enter_autonomous_succeeded = BooleanValue(False)
    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')
    Power_On_chan = ChannelReference(
        'Targets/TruckSim_TTC580/Hardware/Chassis/DAQ/PXI1Slot2/Digital Output/port0/Power on')

    SystemStatus_chan = ChannelReference(
        'Targets/TruckSim_TTC580/Hardware/Chassis/NI-XNET/CAN/Server CAN/Incoming/Single-Point'
        '/SystemStatus(69785)/SystemStatus')
    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')

    with multitask() as mt:
        @task(mt)
        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

        @task(mt)
        def monitor_error_status():
            while enter_autonomous_complete.value is False:
                if error_status.value:
                    stop_task(enter_30)
                    enter_autonomous_complete.value = True
                    enter_autonomous_succeeded.value = False
                nivs_yield()
    return enter_autonomous_succeeded.value
def set_engine_power(on_off):
    """Turns the engine on or off."""
    engine_power = ChannelReference('Aliases/EnginePower')
    engine_power.value = on_off.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))

def test_run_py_as_rtseq_channel_reference_param():
    desired_rpm = ChannelReference('Aliases/DesiredRPM')
    desired_rpm.value = 100.101
    actual = realtimesequencetools.run_py_as_rtseq(func1, {"p": desired_rpm})
    assert actual == 100.101
Exemplo n.º 25
0
from niveristand.clientapi import ChannelReference
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'
)
SystemStatus_chan = ChannelReference(
    'Targets/TruckSim_TTC580/Hardware/Chassis/NI-XNET/CAN/Server CAN/Incoming/Single-Point'
    '/SystemStatus(69785)/SystemStatus')
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'
)

# enginedemo
engine_power_chan = ChannelReference('Aliases/EnginePower')
desired_rpm_chan = ChannelReference('Aliases/DesiredRPM')
Exemplo n.º 26
0
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
Exemplo n.º 27
0
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