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

core: frontend: do not update motors when blueos is not in focus #2243

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 34 additions & 4 deletions core/frontend/src/components/vehiclesetup/PwmSetup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<vehicle-viewer :highlight="highlight" :transparent="true" :autorotate="false" />
</v-card>
<v-card class="mt-3">
<v-overlay :value="!has_focus">
<div class="text-h4 py-12 px-12">
Motor test is disabled when the page is out of focus
</div>
</v-overlay>
<v-simple-table
dense
>
Expand All @@ -20,7 +25,7 @@
</th>
<th>
<v-switch
v-model="is_armed"
v-model="desired_armed_state"
:loading="desired_armed_state !== (is_armed) ? 'warning' : null"
:disabled="!is_manual"
class="mx-1 flex-grow-0"
Expand Down Expand Up @@ -188,6 +193,8 @@ export default Vue.extend({
motor_writer_interval: undefined as undefined | number,
desired_armed_state: false,
arming_timeout: undefined as number | undefined,
has_focus: true,
motors_zeroed: false,
}
},
computed: {
Expand Down Expand Up @@ -326,13 +333,29 @@ export default Vue.extend({
this.motor_writer_interval = setInterval(this.write_motors, 100)
mavlink.setMessageRefreshRate({ messageName: 'SERVO_OUTPUT_RAW', refreshRate: 10 })
this.desired_armed_state = this.is_armed
this.installListeners()
},
beforeDestroy() {
clearInterval(this.motor_zeroer_interval)
clearInterval(this.motor_writer_interval)
mavlink.setMessageRefreshRate({ messageName: 'SERVO_OUTPUT_RAW', refreshRate: 1 })
this.uninstallListeners()
},
methods: {
focusListener() {
this.has_focus = true
},
blurListener() {
this.has_focus = false
},
installListeners() {
window.addEventListener('focus', this.focusListener)
window.addEventListener('blur', this.blurListener)
},
uninstallListeners() {
window.removeEventListener('focus', this.focusListener)
window.removeEventListener('blur', this.blurListener)
},
styleForMotorBar(value: number): string {
const percent = (value - 1500) / 10
const left = percent < 0 ? 50 + percent : 50
Expand All @@ -350,16 +373,24 @@ export default Vue.extend({
},
printParam,
zero_motors() {
if (!this.has_focus && this.motors_zeroed) {
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a case where we should be safe to run if out of focus no ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to stop completely in case the user is trying to do something else.
We need to check if rover has a decent motor test timeout, actually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is zero_motors.. isn't this supposed to be the safest way than letting a undefined state ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't want to interfere if the user is using another software. we should probably send one zero_motors and then stop completely

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a comment explaining that ? This is not clear from the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a comment explaining that ? This is not clear from the code.

the code wasn't doing it before. I added a boolean to keep track of it.

}
for (const motor of this.available_motors) {
this.motor_targets[motor.target] = 1500
}
this.motors_zeroed = true
},
async write_motors() {
if (!this.has_focus) {
return
}
if (this.is_armed && this.desired_armed_state) {
for (const [motor, value] of Object.entries(this.motor_targets)) {
this.doMotorTest(parseInt(motor, 10), value)
}
}
this.motors_zeroed = false
},
restart_motor_zeroer() {
clearInterval(this.motor_zeroer_interval)
Expand All @@ -384,10 +415,9 @@ export default Vue.extend({
console.warn('Disarming failed!')
}, 5000)
},
arm_disarm_switch_change(): void {
this.desired_armed_state = !this.is_armed
arm_disarm_switch_change(should_arm: boolean): void {
// eslint-disable-next-line no-unused-expressions
this.is_armed ? this.disarm() : this.arm()
should_arm ? this.arm() : this.disarm()
},
armDisarm(arm: boolean, force: boolean): void {
mavlink2rest.sendMessage(
Expand Down