Use product of the signs for cnts_per_x and steps_per_x to set the fwd and rev limit values.
Also use floating point in the calculations.
This commit is contained in:
@ -75,6 +75,31 @@ set fhe [open ${scriptname}_errors.log "w"]
|
||||
# @param att attribute name
|
||||
# @return value for attribute or NOATT if no attribute should be generated.
|
||||
proc gen_attval {mot att} {
|
||||
|
||||
if {[set ::${mot}_attarr(steps_per_x)] < 0} {
|
||||
set sign -1.0
|
||||
} else {
|
||||
set sign 1.0
|
||||
}
|
||||
if { [info exists ::${mot}_encatts(cnts_per_x)] } {
|
||||
set cnts_per_x_val [expr double([set ::${mot}_encatts(cnts_per_x)])]
|
||||
}
|
||||
if { [info exists ::${mot}_encatts(rev_enc_lim)]} {
|
||||
set rev_enc_lim_val [expr double([set ::${mot}_encatts(rev_enc_lim)])]
|
||||
}
|
||||
if { [info exists ::${mot}_encatts(fwd_enc_lim)]} {
|
||||
set fwd_enc_lim_val [expr double([set ::${mot}_encatts(fwd_enc_lim)])]
|
||||
}
|
||||
if [info exists ::${mot}_attarr(absenchome)] {
|
||||
set enc_home_val [expr double([set ::${mot}_attarr(absenchome)])]
|
||||
} else {
|
||||
set enc_home_val [expr double([set ::${mot}_encatts(rev_enc_lim)])]
|
||||
}
|
||||
if [info exists ::${mot}_attarr(home)] {
|
||||
set home_val [expr double([set ::${mot}_attarr(home)])]
|
||||
} else {
|
||||
set home_val 0
|
||||
}
|
||||
switch $att {
|
||||
"absenchome" {
|
||||
if [info exists ::${mot}_encatts(rev_enc_lim)] {
|
||||
@ -86,24 +111,17 @@ proc gen_attval {mot att} {
|
||||
"maxspeed" {return 1}
|
||||
"maxaccel" {return 1}
|
||||
"maxdecel" {return 1}
|
||||
"rev_lim" {return 0}
|
||||
"rev_lim" {
|
||||
if { [info exists ::${mot}_encatts(rev_enc_lim)] && [info exists ::${mot}_encatts(cnts_per_x)] } {
|
||||
return [expr {$sign * ($rev_enc_lim_val - $enc_home_val) / $cnts_per_x_val + $home_val}]
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
"home" {return 0}
|
||||
"fwd_lim" {
|
||||
if { [info exists ::${mot}_encatts(fwd_enc_lim)] && [info exists ::${mot}_encatts(cnts_per_x)] } {
|
||||
set fwd_enc_lim_val [set ::${mot}_encatts(fwd_enc_lim)]
|
||||
set cnts_per_x_val [set ::${mot}_encatts(cnts_per_x)]
|
||||
|
||||
if [info exists ::${mot}_encatts(rev_enc_lim)] {
|
||||
set rev_enc_lim_val [set ::${mot}_encatts(rev_enc_lim)]
|
||||
} else {
|
||||
set rev_enc_lim_val 0
|
||||
}
|
||||
if [info exists ::${mot}_encatts(home)] {
|
||||
set home_val [set ::${mot}_encatts(home)]
|
||||
} else {
|
||||
set home_val 0
|
||||
}
|
||||
return [expr {($fwd_enc_lim_val - $rev_enc_lim_val) / $cnts_per_x_val + $home_val}]
|
||||
return [expr {$sign * ($fwd_enc_lim_val - $enc_home_val) / $cnts_per_x_val + $home_val}]
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
|
Reference in New Issue
Block a user