The following code helps to operate a MAXV controller with an encoder axis. The widget is displayed below.
$Spc::res_h{ blsc} = "mot65encoder";
#
#
#
$Spc::res_h{ mot65encoder_title} = { text => "Mot65-Encoder"};
$Spc::res_h{ mot65encoder_help} = sub
{
Util::display_text( "Help MOt65Encoder",
'
State
0 ON
6 MOVING
Home
Starts the homing sequence
Toggle auto-refresh
If enabled, the menu items are updated every 2 seconds.
See current state of this flag is displayed in the
log widget of the toplevel menu, if it is changed.
'
)};
$Spc::res_h{ "mot65encoder_io1"} = {
label => { name => "Position",
get => sub { Spectra::tng_attrDoubleRd( "mot65", "Position");}},
entry => { set => sub { Spectra::tng_inoutDoubleLong( "mot65", "Move", $_[0])}}};
$Spc::res_h{ "mot65encoder_io2"} = {
label => { name => "Encoder Position",
get => sub { if( Spectra::tng_attrLongRd( "mot65", "FlagEncoderHomed"))
{
Spectra::tng_attrDoubleRd( "mot65", "PositionEncoder");
}
else { "not homed";}}}};
$Spc::res_h{ "mot65encoder_io3"} = {
label => { name => "Encoder Home Position",
get => sub { if( Spectra::tng_attrLongRd( "mot65", "FlagEncoderHomeDefined"))
{
Spectra::tng_attrDoubleRd( "mot65", "HomePosition");
}
else { "home not defined";}}},
entry => { set => sub { Spectra::tng_attrDoubleWrt( "mot65", "HomePosition", $_[0])}}};
$Spc::res_h{ "mot65encoder_io4"} = {
label => { name => "Encoder Conversion",
get => sub { if( Spectra::tng_attrLongRd( "mot65", "FlagEncoderConversionDefined"))
{
Spectra::tng_attrDoubleRd( "mot65", "ConversionEncoder");
}
else { "conversion not defined";}}},
entry => { set => sub { Spectra::tng_attrDoubleWrt( "mot65", "ConversionEncoder", $_[0])}}};
$Spc::res_h{ "mot65encoder_io5"} = {
label => { name => "FlagHomed",
get => sub { Spectra::tng_attrLongRd( "mot65",
"FlagEncoderHomed");}}};
$Spc::res_h{ "mot65encoder_io6"} = {
label => { name => "FlagUseEncoderPosition",
get => sub { Spectra::tng_attrLongRd( "mot65",
"FlagUseEncoderPosition");}},
entry => { set => sub { Spectra::tng_attrLongWrt( "mot65", "FlagUseEncoderPosition", $_[0])}}};
$Spc::res_h{ "mot65encoder_io7"} = {
label => { name => "State",
get => sub { Spectra::tng_state( "mot65");}}};
$Spc::res_h{ mot65encoder_b1} = {
name => "Home",
command => sub { Spectra::tng_inout( "mot65",
"MoveHome");}};
$Spc::res_h{ mot65encoder_b2} = {
name => "ResetMotor",
command => sub { Spectra::tng_inout( "mot65",
"ResetMotor");}};
$Spc::res_h{ mot65encoder_option1} = {
name => "Toggle auto-refresh",
command => sub { if( defined( $BLSC::h{ w_timer}))
{
$BLSC::h{ w_timer}->cancel();
delete $BLSC::h{ w_timer};
Util::log( "BLSC: timer cancelled");
}
else
{
$BLSC::h{ w_timer} =
$BLSC::h{ w_top}->after( 2000, \&BLSC::refresh);
Util::log( "BLSC: timer started");
}}};
The following figure displays the widget just after the axis has been homed: the motor position, the encoder position and the home position are identical.