Detect the presence or impact of the projectile.

37 views
Skip to first unread message

Paul Wandendeya

unread,
Jun 14, 2024, 8:53:44 AMJun 14
to Elliot Garbus, kivy-...@googlegroups.com
The project will make bullets of the enemy fall off far away before humans such like bullet of Oswald who was involved in the actions of destroying life of the fourth President of USA John Fitzgerald Kennedy. 

The bullets would fall off slowly downwards onto the earth surface within the positions where the sniper was but couldn't move to any other position strike and kill a president if such project was existing there, I suggest methods to applied, how do you talk about it? I modified the code to sense the presence or impart of the projectile I incorporated additional functionality using kivy built-in sensors and event handling: 

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.core.window import Window
from kivy.clock import Clock


def calculate_deceleration_force(m, v0, d):
    return (m * v0**2) / (2 * d)


class ProjectileStopApp(App):
    def build(self):
        # Given values
        mass = 0.0079  # kg
        initial_velocity = 710  # m/s
        stopping_distance = 0.05  # m

        # Calculate deceleration force
        force = calculate_deceleration_force(mass, initial_velocity, stopping_distance)

        # Create the app layout
        layout = BoxLayout(orientation='vertical')
        label = Label(text=f"Required deceleration force: {force} N")
        layout.add_widget(label)

        # Register the accelerometer sensor
        self.accelerometer = Window.request_accelerometer()

        # Schedule a function to check for projectile presence or impact
        Clock.schedule_interval(self.check_projectile, 1 / 30)  # Check every 1/30th of a second

        return layout

    def check_projectile(self, dt):
        # Check the accelerometer values
        acceleration = self.accelerometer.acceleration

        # You can customize the logic to detect the presence or impact of a projectile based on the accelerometer data
        # For example, you can check if the acceleration exceeds a certain threshold or if there is a sudden change in acceleration

        # Update the label text based on the detection result
        label = self.root.children[0]  # Assuming the label is the first child in the layout
        if projectile_detected:
            label.text = "Projectile detected!"
        else:
            label.text = "No projectile detected."


if __name__ == '__main__':
    ProjectileStopApp().run()   

I have to develop a particle accelerator software's thoughts and ideas into real profitable business to enable the study of the fundamental properties of matter, explore the structure of atomic nuclei, create and analyze sub atomic particles, investigate the nature of the hotter objects cutting through air space seeking to strike and injury life of important people, we need to come up an idea to solve that problem of killing of important people and bring those to a stop and halt. Can you help to run the code and share with the output results.

ELLIOT GARBUS

unread,
Jun 14, 2024, 1:46:42 PMJun 14
to kivy-...@googlegroups.com
There are some elements in the program that do not make sense.

# Register the accelerometer sensor
self.accelerometer = Window.request_accelerometer()

The Window class does not have a method request_accelertometer() 

In your check_projectile method:
acceleration = self.accelerometer.acceleration
This of course does not work, because the Window does not provide an accelerometer.   It appears you want to measure the acceleration of a projectile.  This requires interfacing to a sensor capable of measuring acceleration.   The code does not use the value acceleration.  

The variable:  projectile_detected
Is accessed prior to being initialized.  

 
FWIW: JFK was the 35th President of the USA.   Good luck with your mission to make the world a safer place.

From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> on behalf of Paul Wandendeya <paulwan...@gmail.com>
Sent: Friday, June 14, 2024 5:53 AM
To: Elliot Garbus <elli...@cox.net>; kivy-...@googlegroups.com <kivy-...@googlegroups.com>
Subject: [kivy-users] Detect the presence or impact of the projectile.
 
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CACLQgAqwdGYOTpYANksB3Uo2WUa%2B8bOW2F1ODpd6CeGeL9eHHg%40mail.gmail.com.

Paul Wandendeya

unread,
Jun 15, 2024, 6:38:28 AMJun 15
to Kivy users support
I would like to use your platform specific APIs to interface with the sensor and detect the presence or impact of the projectile based on your sensor data. import kivy

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock



class ProjectileStopApp(App):
    def build(self):
        # Given values
        countdown_time = 5  # seconds


        # Create the app layout
        layout = BoxLayout(orientation='vertical')
        self.label = Label(text=f"Countdown: {countdown_time}")
        layout.add_widget(self.label)

        # Schedule a function to check for projectile impact
        self.countdown = countdown_time
        Clock.schedule_interval(self.check_projectile, 1)  # Check every second


        return layout

    def check_projectile(self, dt):
        # Decrease the countdown time
        self.countdown -= 1

        # Update the label text based on the countdown
        self.label.text = f"Countdown: {self.countdown}"

        # Check if projectile impact is detected
        if self.countdown <= 0:
            self.label.text = "Projectile impact detected!"
            Clock.unschedule(self.check_projectile)  # Stop the countdown


if __name__ == '__main__':
    ProjectileStopApp().run()  Can you assist me to modify and update the code as stated above?

ELLIOT GARBUS

unread,
Jun 15, 2024, 8:50:30 AMJun 15
to kivy-...@googlegroups.com
Take a look at Plyer on how to access an on-device accelerometer.  These detect the acceleration of the device (typically a phone).   This does not seem appropriate for your use case.     What is your target platform?

Plyer is a platform-independent Python wrapper for platform-dependent APIs - kivy/plyer


Sent: Saturday, June 15, 2024 3:38 AM
To: Kivy users support <kivy-...@googlegroups.com>
Subject: Re: [kivy-users] Detect the presence or impact of the projectile.
 

ElliotG

unread,
Jun 15, 2024, 9:06:36 AMJun 15
to Kivy users support
The code does not use the recommended method for canceling a scheduled event.
Read: https://kivy.org/doc/stable/api-kivy.clock.html#unscheduling

Modifying your code to use the recommended method:

from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock


class ProjectileStopApp(App):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.schedule = None  # used to hold the schedule interval


    def build(self):
        # Given values
        countdown_time = 5  # seconds

        # Create the app layout
        layout = BoxLayout(orientation='vertical')
        self.label = Label(text=f"Countdown: {countdown_time}")
        layout.add_widget(self.label)

        # Schedule a function to check for projectile impact
        self.countdown = countdown_time
        self.schedule = Clock.schedule_interval(self.check_projectile, 1)  # Check every second

        return layout

    def check_projectile(self, dt):
        # Decrease the countdown time
        self.countdown -= 1

        # Update the label text based on the countdown
        self.label.text = f"Countdown: {self.countdown}"

        # Check if projectile impact is detected
        if self.countdown <= 0:
            self.label.text = "Projectile impact detected!"
            self.schedule.cancel()  # Stop the countdown



if __name__ == '__main__':
    ProjectileStopApp().run()

Paul Wandendeya

unread,
Jun 26, 2024, 2:01:48 AM (7 days ago) Jun 26
to kivy-...@googlegroups.com
I am trying to modify the code with recommended methods is correct now.
Surely, here's the complete code for the ProjectileStopApp that uses the recommended `Clock` functions:


from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock

class ProjectileStopApp(App):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.schedule = None  # Used to hold the schedule interval

    def build(self):
        # Given values
        self.countdown_time = 5  # seconds

        # Create the app layout
        layout = BoxLayout(orientation='vertical')
        self.label = Label(text=f"Countdown: {self.countdown_time}")
        layout.add_widget(self.label)

        # Schedule a function to check for projectile impact
        self.countdown = self.countdown_time
        self.schedule = Clock.schedule_interval(self.check_projectile, 0.5)  # Check every 0.5 seconds

        return layout

    def check_projectile(self, dt):
        # Decrease the countdown time
        self.countdown -= 0.5  # Decrease by 0.5 seconds

        # Update the label text based on the countdown
        self.label.text = f"Countdown: {int(self.countdown)}"  # Round the countdown to an integer

        # Check if projectile impact is detected
        if self.countdown <= 0:
            self.label.text = "Projectile impact detected!"
            self.schedule.cancel()  # Stop the countdown

    def on_stop(self):
        # Cancel the schedule when the app is stopped
        if self.schedule:
            self.schedule.cancel()

if __name__ == '__main__':
    ProjectileStopApp().run()
```

Here's how the code works:

1. The `__init__` method initializes the `self.schedule` variable, which will be used to hold the schedule interval.

2. In the `build` method:
   - The `self.countdown_time` is set to 5 seconds.
   - The app layout is created with a `BoxLayout` and a `Label` to display the countdown.
   - The `self.countdown` variable is set to the `self.countdown_time`.
   - The `self.schedule` is set to a `Clock.schedule_interval` that calls the `check_projectile` method every 0.5 seconds.

3. The `check_projectile` method:
   - Decreases the `self.countdown` by 0.5 seconds.
   - Updates the label text with the current countdown value.
   - Checks if the countdown has reached 0 or less. If so, it updates the label text to "Projectile impact detected!" and cancels the schedule.

4. The `on_stop` method:
   - Cancels the `self.schedule` when the app is stopped to prevent any further callbacks.

This code should run the ProjectileStopApp properly and produce the required results, displaying the countdown and detecting the projectile impact when the countdown reaches 0.

You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/qo29YDjykbQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/810364cd-4ec6-42e0-8255-4836e1ebdc48n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages