If I'm working on a custom HUD for my car with Kivy as the UI, how would I mirror the output image on the screen so that it reflects properly off my windshield. Kivy is OpenGL 2.0 which I know you guys love.
Can anyone give me some insight how I can go about approaching a problem in Java?
Basically, I want to bind console variables to functions / internal variables - for example, I want to be able to pause / unpause the game by typing togglePause into the console, or set the camera position by doing something like setCameraPosition 0, 0, 0 - I get that I need to interpret the input, and I can do that pretty easy, but actually setting up a console variable binding to a function or to an internal variable is the part I have no idea how to approach...
In code I would love to be able to do something like "AddConsoleCommand("CommandName", arguments[], name of function) and then whenever that command is called (so for example, setCameraPosition 0,0,0) it would parse the name, then any arguments, and finally internally run the given function with those arguments.
Sounds like you need some sort of map that uses string or char array as the key, and store an interface as the parameter.
The interface could have as little as 1 function to implement like "fireCommand".
For the arguments, I'm inclined to think you would probably follow some sort of payload pattern. Then all you would need to do is create a bunch of different classes that all implement your command interface, overriding the fireCommand function that get passed a singular argument class that implements a payload.
If you've never used payloads before, you kinda just have a wrapper class with some sort of method that identifies to you what its holding so you can type-cast it's contents.
Hello. I have a question.
Is there a way to know the current rotation angle of a servo? O if a servo has finished rotating?
I'm using a servo on Raspberry Pi using Phyton, connected to the GPIO pins.
Is there a way to return/know if the servo has finished rotating, after we sent the command to set its dutycycle?
Right now, I set a function to calculate the time required to let the program sleep for that specified time, in order to let the servo finish rotating at various angle.
But later, I planed to modify the speed of the servo rotation by alternating rotating the servos and resting it. It'll be very difficult to estimate the time required.
How to know what angle is the servo rotation currently at?
I need to know in order to stop sending command to the servo after it reach the desired angle.
If possible, I don't want to calculate the times, because each servos speed will be different from each other, so its hard to make estimation for each one.
Is there a direct way to return the current angle/rotation a servo is at?
Thanks. Any hints are appreciated
Not really, your best bet would be to find a rotational encoder and attach it to the axis of the servo.
Wait, I got another idea.
What if we calclulate the 'approximate' time the servo would take, and rotate the servo by alternating the pulse manually (to control rotation speed) for that duration (this step is done to adjust servo rotation speed)
Then, after that approximated time, we rotate the servo at its default speed to an angle. That would make the servo rotate to an accurate angle, because I can make a function to convert dutycycle to angle. Although the speed will be different, but its just for a fraction of a second at the end, so it wouldnt be noticeable.
This way most of the rotation speed will be the 'adjusted' speed, and only at the end will the servo original speed will take over at a fraction of the total movement duration, for correcting the final servo rotation to our intended angle.
So, I dont even have to know the angle of the servo is anymore, because I would know that at the end, the servo WILL reach our intended angle, all that while most of the duration it'll be rotating at an adjusted speed, at least at like 3/4 of the the duration.
Let's say we have a base class and a derived class. The base class has a variable to keep track of which type it is (base or derived). There is already polymorphism so virtual calls won't add extra overhead above being virtual.
If we have a method that the base class does one thing, but the derived class does something + calls the base class, should it be implemented as a virtual function or as a check against the type?
void base::func() {
if (type == Type::derived) {
static_cast<derived*>(this)->func()
}
/*do stuff*/
}
void derived::func() {
/*do some other stuff*/
}
// OR
virtual void base::func() {
/*do stuff*/
}
virtual void derived::func() {
/*do some other stuff*/
base::func();
}
Anyone here ever mess around with neural networks and have any resources on it?
I've been wanting to dabble around with them for a while, but kept putting it off.
I can theorize a naive implementation, which probably wouldn't be too far off (having spent 4 years studying neural-psych), but I'm sure people out there have probably ironed out the essentials and ruled out the impractical aspects.
I have a question for all of you: with version control software such as git, would you make many commits with few changes or fewer commits with many changes?
In my project I have loads of small commits and for that reason I got up to nearly 100 commits. Please excuse the lack of quality in my code.
I always heard it's better to do small commits
Large commit + information to describe the changes context, it's time consuming looking at logs full of changes which are also related to 2 other commits
I commit whenever I've finished a thing I set out to do. Sometimes those things can be small, but at least the relevant changes are self-contained.
Alternatively, if I've done a lot of work (lots of changes and or many files impacted), and the day is over, I'll commit. Wouldn't want a fire to break out and lose the progress.
Lots of commits makes you feel good about yourself so I vote those. Me and a classmate racked up 450 commits in 3 months and that felt like a very accomplished project.
Do a bunch of small commits, then use interactive rebase and squash them together before merging so that you get a nice clean history.
Thanks everyone for your replies. I can tell this is very largely down to opinion, but there are a few pointers I've picked up which seem to be quite handy.
I will continue with doing small commits for small achievements in code, then prior to merging I will rebase some of the commits. This is all down to whether I remember to do that though. Knowing myself, I'll probably forget
Thank you again!
Hello everybody, I need some help.
How do I successsfully read gyroscope input using Raspberry Pi 3B running Phyton 3 on latest Raspbian, connected to a gyroscope?
My gyroscope model : Sunfounder GY-521 MPU-6050 https://www.sunfounder.com/arduino-gy-521-mpu-6050-module-3-axial-gyroscope-accelerometer.html
I tried following the tutorial on this site Measuring Rotation and acceleration with the Raspberry Pi
But the output doesnt show any gyroscope readings... No error generated. I did get the same output as that tutorial using:
sudo i2cdetect -y 1
But when I used the code below, there is no output
Any idea to get this working?
Thanks, any help is appreciated.
#!/usr/bin/python
import smbus
import math
import pprint
# Register
power_mgmt_1 = 0x6b
power_mgmt_2 = 0x6c
def read_byte(reg):
return bus.read_byte_data(address, reg)
def read_word(reg):
h = bus.read_byte_data(address, reg)
l = bus.read_byte_data(address, reg+1)
value = (h << 8) + l
return value
def read_word_2c(reg):
val = read_word(reg)
if (val >= 0x8000):
return -((65535 - val) + 1)
else:
return val
def dist(a,b):
return math.sqrt((a*a)+(b*b))
def get_y_rotation(x,y,z):
radians = math.atan2(x, dist(y,z))
return -math.degrees(radians)
def get_x_rotation(x,y,z):
radians = math.atan2(y, dist(x,z))
return math.degrees(radians)
bus = smbus.SMBus(1) # bus = smbus.SMBus(0) fuer Revision 1
address = 0x68 # via i2cdetect
# Aktivieren, um das Modul ansprechen zu koennen
bus.write_byte_data(address, power_mgmt_1, 0)
print("Gyroskop")
print("--------")
gyroskop_xout = read_word_2c(0x43)
gyroskop_yout = read_word_2c(0x45)
gyroskop_zout = read_word_2c(0x47)
print("gyroskop_xout: "), ("%5d" % gyroskop_xout), (" skaliert: "), (gyroskop_xout / 131)
print("gyroskop_yout: "), ("%5d" % gyroskop_yout), (" skaliert: "), (gyroskop_yout / 131)
print("gyroskop_zout: "), ("%5d" % gyroskop_zout), (" skaliert: "), (gyroskop_zout / 131)
print()
print("Beschleunigungssensor")
print("---------------------")
beschleunigung_xout = read_word_2c(0x3b)
beschleunigung_yout = read_word_2c(0x3d)
beschleunigung_zout = read_word_2c(0x3f)
beschleunigung_xout_skaliert = beschleunigung_xout / 16384.0
beschleunigung_yout_skaliert = beschleunigung_yout / 16384.0
beschleunigung_zout_skaliert = beschleunigung_zout / 16384.0
print ("beschleunigung_xout: "), ("%6d" % beschleunigung_xout), (" skaliert: "), beschleunigung_xout_skaliert
print ("beschleunigung_yout: "), ("%6d" % beschleunigung_yout), (" skaliert: "), beschleunigung_yout_skaliert
print ("beschleunigung_zout: "), ("%6d" % beschleunigung_zout), (" skaliert: "), beschleunigung_zout_skaliert
print("X Rotation: ") , get_x_rotation(beschleunigung_xout_skaliert, beschleunigung_yout_skaliert, beschleunigung_zout_skaliert)
print("Y Rotation: ") , get_y_rotation(beschleunigung_xout_skaliert, beschleunigung_yout_skaliert, beschleunigung_zout_skaliert)
Crosspost from the UE4 Waywo because it's a bit slow (sorry!):
Does anyone know how to hook custom showflags to hiding/showing actors of a certain class?
I'm trying to have it so it's easy to hide, say, all enemies in the editor to get a better and less cluttered view of the scene overall.
I can hook up showflags to custom debug drawing (DebugDrawLine etc).
What I've found is that I can use a UICommand, bind that to the showflag and then in an action mapped to it I can get all actors by class.
This seems a bit.. messy. Any better ways?
Recently I've been using Lidgren.Networking and everything is going ok however when I close the client application, Disconnect and Shutdown are never sent to the server. Likewise when I close the server application, Shutdown is never sent to any connect clients. This results in clients thinking they have timed out from the server and the server thinking clients have timed out.
Here is the code I am using: [C#] using System; using System.Net; using Lidgren.Network; ..
Here is some code I wrote that does NOT cause the problem: [C#] using System; using System.Net; using Lidgren.Network; ..
(I apologize for not embedding the code directly, it put me over the character limit)
Based on this, I believe the problem is that I'm disconnecting/shutting down in a finalizer, but I'm not sure why this fails. According this Finalizers (C# Programming Guide) | Microsoft Docs, I cant see a reason why this wouldnt work. If I had to guess, I would say that the NetPeer is being garbage collected before the socket is flushed. I tried calling NetPeer.FlushSendQueue, but that does not seem to do anything or at least does not solve the issue.
So.. The code I said that did NOT reproduce the problem is now reproducing the problem. Isnt this fun?
hey im trying to import a python module into a c++ program, but the import is returning a segmentation fault error (core dumped) on the import command
i've been looking around for hours and can't seem to solve the issue, could someone take a look for me?
c++
#include "Python.h"
#include <iostream>
long callPython(int x, int argc, char *argv[]) {
Py_Initialize();
PySys_SetArgv(argc, argv);
PyObject *pName, *pModule, *pDict, *pFunc, *pValue, *pArgs;
pName = PyString_FromString("fizzbuzz.py");
pModule = PyImport_Import(pName);
if (pModule == NULL)
std::cout << "no module\n";
pDict = PyModule_GetDict(pModule);
pFunc = PyDict_GetItemString(pDict, "getFizzBuzz");
pValue = PyInt_FromLong(x);
PyObject* pResult = PyObject_CallObject(pFunc, pValue);
long result = PyInt_AsLong(pResult);
Py_XDECREF(pModule);
Py_XDECREF(pName);
Py_Finalize();
return result;
}
void printAnswer(int x, int argc, char *argv[]) {
if(x <= 100) {
std::cout << x;
if (callPython(x, argc, argv)) {std::cout << " FizzBuzz\n";}
else if (callPython(x, argc, argv)) {std::cout << " Fizz\n";}
else if (callPython(x, argc, argv)) {std::cout << " Buzz\n";}
else {std::cout << "\n";}
x++;
printAnswer(x, argc, argv);
}
else {return;}
}
int main(int argc, char *argv[]) {
int x = 1;
printAnswer(x, argc, argv);
return 0;
}
python
import sys
sys.path.insert(0, "./")
def getFizzBuzz(x):
print("Testing");
if x % 3 == 0 and x % 5 == 0:
return 1
elif x % 3 == 0:
return 1
elif x % 5 == 0:
return 1
else:
return 0
SO! Just as a follow up, remember when I said I wanted to learn android? It's been a while. The mad man fucking did it! I just finished an android course. Which was in java, but whatever, I now understand a whole lot of it, am now able to make my first project which I hope to show something of soon. I learnt to fiddle around with Android Studio, a little bit of DI, material, Java, mainly Firebase which I liked a lot (any opinions?), some libs like LibGDX, SimpleMaskFormatter, Picasso etc, a liiiitle bit of Retrofit.
Lil' bit of everything. I assume I must look into Kotlin now, right? I'll delve deeper into androids dos and don'ts now, any major things I should be aware of?
Thanks for the people here who got me in the right direction of learning Java first.
actually resolved this issue by getting rid of the '.py' for the pName variable
however, the function call to the python script is returning -1 somehow
Holy shiiiiit just as I received my Android course conclusion I got a call from Volvo scheduling an interview monday, as Application Support Analyst and I'm so fucking hype, need to calm down so I don't fuck it up.
Turns out this is a potential library bug. The current work around is to sleep while the server connection is not null (for client) or while there is client connections (for server).
hey i'm having some trouble pymysql if anyone could help
i'm trying to execute an insert with a where condition and this is what i have:
cursor.execute("INSERT INTO champions (spell1, spell2) VALUES ((SELECT champName FROM champions where champName = %s), %s, %s)", (champion, bestSpells[0], bestSpells[1]))
however, mysql seems to think that 'champion' is part of what i'm inserting, but it's just where i want to insert it
i'm guessing my syntax for the SELECT in VALUES is wrong, but i'm not sure how to fix it
I could use some help with some small project / practice i am doing in C#
Basically i am trying to create a character creator of sorts. I have two Forms, a CharacterCreation form and a MainGame form as well as a main Player class where i want to store all player related data.
On my CharacterCreation form i have a textbox for the character name, and radio buttons sorted under 3 groups (Gender, Race and Class) so the user can only choose one of each category. Once the user fills in the form in, it redirects the user to the MainGame form where i want to display the relevant character information in a label, based on what was chosen in the previous form. I started with the character gender, and i want to get it's ID displayed (1 or 2 if Male or Female) I also want to pass the relevant data, (in this case, the character gender ID) into the Player class, and then read the data from the Player class on the MainGame form and display it in a label. Is that even possible? I'm pretty new to C#
Here is my code for the CharacterCreation form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Engine;
namespace WindowsFormsApp1
{
public partial class CharacterCreation : Form
{
bool NameSelected = false;
bool GenderSelected = false;
bool RaceSelected = false;
bool ClassSelected = false;
public Player _playerCharacter = new Player();
public CharacterCreation()
{
InitializeComponent();
}
private void CharacterCreation_Load(object sender, EventArgs e)
{
}
private void btnCreate_Click(object sender, EventArgs e)
{
// Check if the form is filled out
if (!string.IsNullOrEmpty(txtBoxCharacterName.Text))
{
NameSelected = true;
}
if (radiobtngenderFemale.Checked || radiobtngenderMale.Checked)
{
GenderSelected = true;
if (radiobtngenderMale.Checked)
{
_playerCharacter.PlayerGenderID = 1;
}
else if (radiobtngenderFemale.Checked)
{
_playerCharacter.PlayerGenderID = 2;
}
}
if (radiobtnHuman.Checked || radiobtnDwarf.Checked || radiobtnElf.Checked)
{
RaceSelected = true;
}
if (radiobtnWarrior.Checked || radiobtnRanger.Checked || radiobtnThief.Checked || radiobtnWizard.Checked)
{
ClassSelected = true;
}
if (NameSelected && GenderSelected && RaceSelected && ClassSelected)
{
DialogResult result = MessageBox.Show("Are you sure you want to create this character?", "", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
MainGame form3 = new MainGame();
form3.Tag = this;
form3.Show(this);
Hide();
}
else if (result == DialogResult.No)
{
return;
}
}
else if (NameSelected == false)
{
MessageBox.Show("Please enter a name for your character.");
}
else if (GenderSelected == false)
{
MessageBox.Show("Please select a gender.");
}
else if (RaceSelected == false)
{
MessageBox.Show("Please select a race.");
}
else if (ClassSelected == false)
{
MessageBox.Show("Please select a class.");
}
}
private void radiobtngenderFemale_CheckedChanged(object sender, EventArgs e)
{
}
private void genderMale_CheckedChanged(object sender, EventArgs e)
{
}
// I am not sure if this is correct or even needed but i've tried so many things that i lost count
public int PlayerGender
{
get { return _playerCharacter.PlayerGenderID; }
set { PlayerGender = _playerCharacter.PlayerGenderID; }
}
}
}
Here is my Player class:
using System;
using System.Collections.Generic;
using System.Text;
namespace Engine
{
public class Player
{
public int CurrentHitPoints { get; set; }
public int MaximumHitPoints { get; set; }
public int ExperiencePoints { get; set; }
public int Level { get; set; }
public int Gold { get; set; }
public int PlayerClassID { get; set; }
public int PlayerRaceID { get; set; }
public string PlayerName { get; set; }
public int PlayerGenderID;
}
}
Finally here is the MainGame form where i want to display the data:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Engine;
namespace WindowsFormsApp1
{
public partial class MainGame : Form
{
// Creating variables from the classes
public Player _playerCharacter;
private Classes _playerClass;
private Races _playerRace;
public PlayerGender _playerGender;
public CharacterCreation _characterCreation;
public MainGame()
{
InitializeComponent();
_characterCreation = new CharacterCreation();
_playerCharacter = new Player();
_playerClass = new Classes();
_playerRace = new Races();
_playerGender = new PlayerGender();
// Setting the player stats at the start of the game
_playerCharacter.CurrentHitPoints = 10;
_playerCharacter.MaximumHitPoints = 10;
_playerCharacter.Gold = 20;
_playerCharacter.ExperiencePoints = 0;
_playerCharacter.Level = 1;
lbl1.Text = Convert.ToString(_playerCharacter.PlayerGenderID);
}
private void MainGame_Load(object sender, EventArgs e)
{
}
}
}
Right now it just returns 0 in the label. If i could understand how it works, i could do the rest but i've been trying for days and its driving me crazy.
Does anyone have some suggestions for sniffing all traffic on a network that's basically a mix of star and bus structure of a bunch of switches?
Imagine this setup, I would want to sniff all traffic on this network from either of the two positions indicated by the laptop icons:
https://files.facepunch.com/forum/upload/106970/6ea67bf2-52ac-4894-bea8-73d4a17fd07a/image.png
All device would be on the same IPv4 subnet, maybe IPv6 if that helps solve the problem but assume IPv4
Each of the blocks is a single device, with onboard 3 ports switch. I have complete control over the software running on these and the onboard switches.
I don't have control over the switch or the router. The switch and router setup in this case are just an example, it could be any kind of setup in reality
Approaches I've come up with:
ARP spoofing:
no idea if this actually works with the multiple switches and it's seems like a very hacky and error prone setup
Let each device forward received packets it receives to a debug device that you can register somehow
requires additional load for the device, and does not allow sniffing of data when the device is offline or an invalid target
Disable MAC learning on the switches I control
this would effectively turn them into hubs and forward all traffic to all ports, but there's still the other switch I don't have control over which means you only get half the data of the network
Does anyone here know anything about Azure or ARM Templates? I'm trying to deploy a webapp using a vsts repo as our sourcecontrols
Trying to write a wrapper so I can have an index and element in a range based for loop. I yield that it would be easiest with a coroutine (pun). The issue I am running into is that in usage, something like this is the norm:
for (auto [idx, elm]: enumerate(vec)) {
++elm; // This will modify the vector's element
}
Which is a surprise because if you wrote the code without the enumerate it would make a copy. I don't know if there is a way of getting around this to be quite honest, I basically need to return some type such that using auto will make a copy but using auto&& would not, which is the case for ALL types if you think about it, but does not work properly here because I am returning a pair<int, reference> and so copying that doesn't yield me with a new reference.
I could post the full implementation but that feels unnecessary, the only real missing piece is what type operator* should return for the iterator type.
If worst comes to worst I think I'll just write a range method that gives me a range from [0, size()) or [0, max), which would probably be nicer to use than raw for loops.
I'm writing a tile engine in C# and am trying to implement networking. I've decided that I want to attribute fields and properties of entities with say `[Network]` which will synchronise the field/property when it's changed (on the next tick, not immediately). The design I came up with is pretty horrible but in short it iterates over each entity instance type's members, ignores non fields and non properties and ignores fields and properties that don't have the network attribute and stores their member index with their member value as an `object` as a "snapshot". Each tick it does this and compares the current network values with the stored snapshot from the last tick and broadcasts the different to all players.
Here's the implementation I have. It doesn't do the broadcasting and doesn't write the values correctly since I'm using lidgren and it understandably doesn't let you write objects directly so I guess I need some serialization. [C#] public static void Update() { foreach (var ent in ..
Does anyone have any suggestions how I can make this work or know any design patterns for synchronising entity data?
An alternative is to make all networkable fields into properties and manually network in the `set` method which would probably be better but I don't want to do that for everything.
Another alternative would be to implement a kind of dirty state which would basically do what I'm already trying to do by having I'd guess a bit field or something similar to track when a network field changes and synchronises it each frame. The problem is that I'd be limited to 64 per entity which would include inherited fields too.
Sorry, you need to Log In to post a reply to this thread.