Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AI Bridge Default Argument Values #509

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions generated/nidaqmx/_task_modules/ai_channel_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,10 @@ def add_ai_force_bridge_polynomial_chan(
Indicates the newly created channel object.
"""
if forward_coeffs is None:
forward_coeffs = []
forward_coeffs = [0.0, 50]

if reverse_coeffs is None:
reverse_coeffs = []
reverse_coeffs = [0.0, 0.02]

forward_coeffs = numpy.float64(forward_coeffs)
reverse_coeffs = numpy.float64(reverse_coeffs)
Expand Down Expand Up @@ -624,10 +624,10 @@ def add_ai_force_bridge_table_chan(
Indicates the newly created channel object.
"""
if electrical_vals is None:
electrical_vals = []
electrical_vals = [-2.0, 0.0, 2.0]

if physical_vals is None:
physical_vals = []
physical_vals = [-100.0, 0.0, 100.0]

electrical_vals = numpy.float64(electrical_vals)
physical_vals = numpy.float64(physical_vals)
Expand Down Expand Up @@ -1197,10 +1197,10 @@ def add_ai_pressure_bridge_polynomial_chan(
Indicates the newly created channel object.
"""
if forward_coeffs is None:
forward_coeffs = []
forward_coeffs = [0.0, 50]

if reverse_coeffs is None:
reverse_coeffs = []
reverse_coeffs = [0.0, 0.02]

forward_coeffs = numpy.float64(forward_coeffs)
reverse_coeffs = numpy.float64(reverse_coeffs)
Expand Down Expand Up @@ -1289,10 +1289,10 @@ def add_ai_pressure_bridge_table_chan(
Indicates the newly created channel object.
"""
if electrical_vals is None:
electrical_vals = []
electrical_vals = [-2.0, 0.0, 2.0]

if physical_vals is None:
physical_vals = []
physical_vals = [-100.0, 0.0, 100.0]

electrical_vals = numpy.float64(electrical_vals)
physical_vals = numpy.float64(physical_vals)
Expand Down Expand Up @@ -1921,10 +1921,10 @@ def add_ai_torque_bridge_polynomial_chan(
Indicates the newly created channel object.
"""
if forward_coeffs is None:
forward_coeffs = []
forward_coeffs = [0.0, 50]

if reverse_coeffs is None:
reverse_coeffs = []
reverse_coeffs = [0.0, 0.02]

forward_coeffs = numpy.float64(forward_coeffs)
reverse_coeffs = numpy.float64(reverse_coeffs)
Expand Down Expand Up @@ -2012,10 +2012,10 @@ def add_ai_torque_bridge_table_chan(
Indicates the newly created channel object.
"""
if electrical_vals is None:
electrical_vals = []
electrical_vals = [-2.0, 0.0, 2.0]

if physical_vals is None:
physical_vals = []
physical_vals = [-100.0, 0.0, 100.0]

electrical_vals = numpy.float64(electrical_vals)
physical_vals = numpy.float64(physical_vals)
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/templates/function_template.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%
from codegen.utilities.interpreter_helpers import INTERPRETER_CAMEL_TO_SNAKE_CASE_REGEXES
from codegen.utilities.helpers import camel_to_snake_case
from codegen.utilities.function_helpers import order_function_parameters_by_optional,get_parameters_docstring_lines_length,get_parameter_signature,get_instantiation_lines,generate_function_call_args
from codegen.utilities.function_helpers import order_function_parameters_by_optional,get_parameters_docstring_lines_length,get_parameter_signature,get_instantiation_lines,generate_function_call_args, get_list_default_value
from codegen.utilities.text_wrappers import wrap, docstring_wrap
%>\
################################################################################
Expand Down Expand Up @@ -56,7 +56,7 @@
%for input_param in func.parameters:
%if input_param.is_list:
if ${input_param.parameter_name} is None:
${input_param.parameter_name} = []
${input_param.parameter_name} = ${get_list_default_value(func, input_param)}

%endif
%endfor
Expand Down
28 changes: 28 additions & 0 deletions src/codegen/utilities/function_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
"SetDigitalPullUpPullDownStates",
]

FUNCTIONS_WITH_LIST_DEFAULT = [
"add_ai_force_bridge_polynomial_chan",
"add_ai_force_bridge_table_chan",
"add_ai_pressure_bridge_polynomial_chan",
"add_ai_pressure_bridge_table_chan",
"add_ai_torque_bridge_polynomial_chan",
"add_ai_torque_bridge_table_chan",
]


def get_functions(metadata, class_name=""):
"""Converts the scrapigen metadata into a list of functions."""
Expand Down Expand Up @@ -269,3 +278,22 @@ def instantiate_explicit_output_param(param):
)
elif param.ctypes_data_type == "ctypes.c_char_p":
return f"{param.parameter_name} = ctypes.create_string_buffer(temp_size)"


def get_list_default_value(func, param):
"""Gets the default value for list parameters."""
if func.function_name in FUNCTIONS_WITH_LIST_DEFAULT:
if param.parameter_name == "forward_coeffs":
return "[0.0, 50]"
elif param.parameter_name == "reverse_coeffs":
return "[0.0, 0.02]"
elif param.parameter_name == "electrical_vals":
return "[-2.0, 0.0, 2.0]"
elif param.parameter_name == "physical_vals":
return "[-100.0, 0.0, 100.0]"
else:
raise RuntimeError(
f'Unable to find parameter name while getting list default value for "{func.function_name}"'
)
else:
return "[]"
20 changes: 8 additions & 12 deletions tests/component/_task_modules/channels/test_ai_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,29 +739,27 @@ def test___task___add_ai_pressure_bridge_polynomial_chan___sets_channel_attribut
task: Task,
sim_bridge_device: Device,
) -> None:
# #482: Default argument values for bridge create channel functions are unusable
chan: AIChannel = task.ai_channels.add_ai_pressure_bridge_polynomial_chan(
sim_bridge_device.ai_physical_chans[0].name,
forward_coeffs=[0.0, 1.0],
reverse_coeffs=[0.0, 1.0],
)

assert chan.ai_meas_type == UsageTypeAI.PRESSURE_BRIDGE
assert chan.ai_bridge_poly_forward_coeff == [0.0, 50]
assert chan.ai_bridge_poly_reverse_coeff == [0.0, 0.02]


# Nothing novel here vs. other bridge-based channels.
def test___task___add_ai_pressure_bridge_table_chan___sets_channel_attributes(
task: Task,
sim_bridge_device: Device,
) -> None:
# #482: Default argument values for bridge create channel functions are unusable
chan: AIChannel = task.ai_channels.add_ai_pressure_bridge_table_chan(
sim_bridge_device.ai_physical_chans[0].name,
electrical_vals=[-1.0, 0.0, 1.0],
physical_vals=[-100.0, 0.0, 100.0],
)

assert chan.ai_meas_type == UsageTypeAI.PRESSURE_BRIDGE
assert chan.ai_bridge_table_electrical_vals == [-2.0, 0.0, 2.0]
assert chan.ai_bridge_table_physical_vals == [-100.0, 0.0, 100.0]


# Nothing novel here vs. other bridge-based channels.
Expand Down Expand Up @@ -1144,29 +1142,27 @@ def test___task___add_ai_torque_bridge_polynomial_chan___sets_channel_attributes
task: Task,
sim_bridge_device: Device,
) -> None:
# #482: Default argument values for bridge create channel functions are unusable
chan: AIChannel = task.ai_channels.add_ai_torque_bridge_polynomial_chan(
sim_bridge_device.ai_physical_chans[0].name,
forward_coeffs=[0.0, 1.0],
reverse_coeffs=[0.0, 1.0],
)

assert chan.ai_meas_type == UsageTypeAI.TORQUE_BRIDGE
assert chan.ai_bridge_poly_forward_coeff == [0.0, 50]
assert chan.ai_bridge_poly_reverse_coeff == [0.0, 0.02]


# Nothing novel here vs. other bridge-based channels.
def test___task___add_ai_torque_bridge_table_chan___sets_channel_attributes(
task: Task,
sim_bridge_device: Device,
) -> None:
# #482: Default argument values for bridge create channel functions are unusable
chan: AIChannel = task.ai_channels.add_ai_torque_bridge_table_chan(
sim_bridge_device.ai_physical_chans[0].name,
electrical_vals=[-1.0, 0.0, 1.0],
physical_vals=[-100.0, 0.0, 100.0],
)

assert chan.ai_meas_type == UsageTypeAI.TORQUE_BRIDGE
assert chan.ai_bridge_table_electrical_vals == [-2.0, 0.0, 2.0]
assert chan.ai_bridge_table_physical_vals == [-100.0, 0.0, 100.0]


# Nothing novel here vs. other bridge-based channels.
Expand Down
Loading