def CalculateAcceleration(self):
currentTheta = math.atan(self.velocity[1]/self.velocity[0])
currentSquaredVelocity = math.pow(self.velocity[0],2)+math.pow(self.velocity[1],2)
accelerationMagnitude = currentSquaredVelocity*self.coeffD
self.acceleration = [math.cos(currentTheta)*accelerationMagnitude, math.sin(currentTheta)*accelerationMagnitude]
self.acceleration = [self.acceleration[0], self.acceleration[1]-self.g]
I believe this is where the problem is and it only happens when the the projectile is going to the right.
not working...
working
I forgot the negative sign in the force calculation
Related
Pdict = {"KobeBryant":0,"JoeJohnson":1,"LeBronJames":2,"CarmeloAnthony":3,"DwightHoward":4,"ChrisBosh":5,"ChrisPaul":6,"KevinDurant":7,"DerrickRose":8,"DwayneWade":9}
Salary = np.array([KobeBryant_Salary, JoeJohnson_Salary, LeBronJames_Salary, CarmeloAnthony_Salary, DwightHoward_Salary, ChrisBosh_Salary, ChrisPaul_Salary, KevinDurant_Salary, DerrickRose_Salary, DwayneWade_Salary])
Games = np.array([KobeBryant_G, JoeJohnson_G, LeBronJames_G, CarmeloAnthony_G, DwightHoward_G, ChrisBosh_G, ChrisPaul_G, KevinDurant_G, DerrickRose_G, DwayneWade_G])
plr =[]
for v in Pdict.values():
for s in Salary:
for g in Games:
if np.isnan(g[v]) == True: continue
z = np.round(np.divide(s[v], Games[v]), 2)
plr.append(z)
print(plr)
print(type(z))
Im trying to make a new matrix called plr, there is a zero in Games[] and Im trying to make it skip it instead of giving me that error. I found the np.isnan() but it seems to do nothing here. If I run the code with or without that line, it still gives me the runtime warning. Im not sure what Im doing wrong with it or is there a better way to do this?
I'm new to pico, only using arduinos before. I'm trying to make a simple rotary encoder program that displays a value from 0-12 on an 0.96 oled display, and lights up that many leds on a strip.
I wanted to try out using multiple cores, as interrupts made the leds not run smooth when I had them just cycling (everything would be paused while the encoder was being turned)
However, when I run this program, aside from the encoder being bouncy, the pico would crash maybe 30 seconds into running the program, making a mess on the display and stopping the code. I feel like there's some rule of using multiple cores that I completely ignored.
Here's the code:
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
import _thread
import utime
import neopixel
#general variables section
numOn = 0
#Encoder section
sw = Pin(12,Pin.IN,Pin.PULL_UP)
dt = Pin(11,Pin.IN)
clk = Pin(10,Pin.IN)
encodeCount = 0
lastClk = clk.value()
lastButton = False
#Encoder thread
def encoder(): #don't mind the indentation here,
#stackoverflow kinda messed up the code block a bit.
while True:
#import stuff that I shouldn't need to according to tutorials but it doesn't work without
global encodeCount
global lastClk
global clk
import utime
if clk.value() != lastClk:
if dt.value() != clk.value():
encodeCount += 1
else:
encodeCount -= 1
if encodeCount > 12:
encodeCount = 0
elif(encodeCount < 0):
encodeCount = 12
lastClk = clk.value()
print(encodeCount)
utime.sleep(0.01)
_thread.start_new_thread(encoder,())
#LED section
numLed = 12
ledPin = 26
led = neopixel.NeoPixel(machine.Pin(ledPin),numLed)
#Screen Section
WIDTH = 128
HEIGHT = 64
i2c = I2C(0,scl=Pin(17),sda=Pin(16),freq=200000)
oled = SSD1306_I2C(WIDTH,HEIGHT,i2c)
#loop
while True:
for i in range(numLed):
led[i] = (0,0,0)
for i in range(encodeCount):
led[i] = (100,0,0)
led.write()
#Display section
oled.fill(0)
oled.text(f'numLed: {numOn}',0,0)
oled.text(f'counter: {encodeCount}',0,40)
oled.show()
I'm probably doing something stupid here, I just don't know what.
Also, any suggestions on simply debouncing the encoder would be very helpful.
Any help would be appreciated! Thanks!
Update: The code above bricked the pico, so clearly I'm doing something very very wrong. _thread start line stopped it from crashing again, so the problem is there.
Same issue with very similar code on a Raspberry Pico W. I specify the 'W' because my code works without crashing on an earlier Pico.
I'm wondering if the low level networking functions might be using the 2nd core and causing a conflict.
I'm adding thread locking to see if passing a baton helps, the link below has an example, eg:
# create a lock
lck= _thread.allocate_lock()
# Function that will block the thread with a while loop
# which will simply display a message every second
def second_thread():
while True:
# We acquire the traffic light lock
lck.acquire()
print("Hello, I'm here in the second thread writting every second")
utime.sleep(1)
# We release the traffic light lock
lck.release()
im making a 2d platformer in godot with a dash mechanic. i have already tried implementing it myself. i have put in a cool down timer for the dash(which works), made it so that cant dash while in air(which works), and animation(which doesn't work).my code has the following problems:
player "teleports" rather than smoothly and quickly dashing
the animation for dashing is barely visible (visible for only a frame)
for some reason if you are idle(not pressing any buttons) and then push the dash button it propels you further than if you are running(holding one of the arrow keys) and push the dash button.
here is my code. it has a lot of code in it that probably isn't causing the problem but i left it in just in case it is. i put #important in front of all the parts of the code that i deemed important
extends KinematicBody2D
var vel = Vector2(0,0)
var fallswitch=0
var can_jump
var can_dash=true
const GRAVITY = 30
const SPEED = 250
const JUMPFORCE = -1000
const DASHSPEED = 1000
func _physics_process(delta):
#important
if Input.is_action_pressed("dash") and is_on_floor() and can_dash==true:
$Sprites.play("dash")
if $Sprites.flip_h==false:
vel.x = DASHSPEED
else:
vel.x = -DASHSPEED
can_dash=false
$dashcooldown.start()
elif Input.is_action_pressed("right"):
vel.x = SPEED
$Sprites.flip_h=false
$Sprites.play("run")
elif Input.is_action_pressed("left"):
vel.x = -SPEED
$Sprites.flip_h=true
$Sprites.play("run")
else:
pass
$Sprites.play("idle")
if not is_on_floor():
if vel.y < 200 and vel.y > 0:
$Sprites.play("fall.t")
elif vel.y > 200:
$Sprites.play("fall")
else:
$Sprites.play("air")
if is_on_floor():
can_jump=true
elif can_jump==true and $CoyoteTimer.is_stopped() :
$CoyoteTimer. start()
if Input.is_action_just_pressed("jump") && can_jump==true:
vel.y = JUMPFORCE
vel.y+=GRAVITY
vel=move_and_slide(vel,Vector2.UP)
vel.x = lerp(vel.x,0,0.1)
func _on_CoyoteTimer_timeout():
can_jump=false
#important
func _on_dashcooldown_timeout():
can_dash=true
thank in advance :)
Your code seems good. The problem might be from your camera2d. In order to implement a proper dash effect the camera needs to have a smoothing effect(it has to slowly stop when it reaches the player whenever the player moves). It acts as a lag, if there is no lag then the camera will sharply follow the player at every moment and will make a dash seem like a teleport. Try out these camera settings. In the camer2d property section enable the current property, under the limit section enable the smooth property, under the smoothing section enable the smoothing and set the speed to 8.8.
More Tips
At _on_dashcooldown_timeout(), be sure to set the player x vector component back to zero
Only use one sprite frame for dash as you do not need multiple images for it, since it is short and quick.
I try to create a Voice Assistant on python3
This is my function Speak (with pyttsx):
def speak(what):
print("Gosha: " + what)
speak_engine.say( what )
speak_engine.runAndWait()
speak_engine.stop()
in the main body it works fine, but in function execute_cmd, after Speak function my code stucks.
One part of execute_cmd:
def execute_cmd(cmd, voice):
global finished
finished = False
#import debug
if cmd == 'ctime':
now = datetime.datetime.now()
hours = str(now.hour)
minutes = str(now.minute)
if (now.minute < 10): minutes = '0' + minutes
speak("Now " + hours + ":" + minutes)
finished = True
finished will never True
This happens anywhere in the function
pls help me
(sorry for my eng, I'm from Russia)
UPD: I debugged my code and noticed, my code get stuck on speak_engine.runAndWait()
I know, many people have same problem, but their solutions didn't help me
I'm not sure I understand you problem. What exactly do you mean by your code getting "Stuck"? Since you said that your finished variable will never be False, I assume that the code runs through and doesn't get stuck. My best guess is that your code simply doesn't produce sound.
If that's the case, I could imagine it's due to the previous loop still being active. So maybe try adding the following to your speak() function:
ef speak(what):
print("Gosha: " + what)
try:
speak_engine.endLoop()
except Exception as e:
pass
speak_engine.say( what )
speak_engine.runAndWait()
speak_engine.stop()
I am building an application using platebutton iin wxpython. The problem is that I am not able to manually SetState of the toogle buton. I used SetState(0) but it does not change the state of toggle button. Any help would be great. Thanks. Sample code:
self.infinity= platebutton.PlateButton(self._ribbon,wx.ID_NEW, bmp = wx.Bitmap('infinity.bmp'), pos = (0,0), size = (38,18), style= platebutton.PB_STYLE_NOBG |platebutton.PB_STYLE_TOGGLE)
def OnInfinityToggled(self,event):
if event.GetEventObject().IsPressed():
self.popupmenu = wx.Menu()
Session = self.popupmenu.Append(-1, "Session")
self.Bind(wx.EVT_MENU, self.SessionMenu, Session)
self.PopupMenu(self.popupmenu,(2,23))
else:
pass
def SessionMenu(self, event):
print 5
self.infinity.SetState(0)
self.infinity.Raise()
PLATE_NORMAL = 0
PLATE_PRESSED = 1
PLATE_HIGHLIGHT = 2
SetState(0) means set to normal.
Here's how I managed to toggle state:
btn._ToggleState()
btn._pressed = True
I had the same problem. Playing around I managed to resolve my problem with
button._SetState(ix)
button.Refresh()
where ix = your choice of state.