How can I continuously detect if someone is in front of Pepper? - javascript

I've been toying with:
PeoplePerception/PeopleDetected()
PeoplePerception/PopulationUpdated()
PeoplePerception/PeopleList()
PeoplePerception/NonVisiblePeopleList()
PeoplePerception/VisiblePeopleList()
Yet I cant seem to figure out how to detect if there is someone in front of Pepper. Those events trigger when the population is updated, but I can't make sense out of the returning values.
What I'm trying to accomplish is to make Pepper remain in a certain state as long as someone is within the detection area number 2 and make it go to a "screensaver" when it doesnt detect someone for 1 minute.
I'm fairly new when it comes to Pepper development, so any help would be apreciated, thank you!

It sounds like you want to combine the ALPeoplePerception API with the ALEngagmentZones API. This is described in some detail here. There's a key in ALMemory (Pepper's memory) that does what you want - stores a list of all people in engagement zone 2 (EngagementZones/PeopleInZone2).
You've tagged the question as javascript, so I'll give a brief example with how to access this.
QiSession(function (session){
session.service("ALMemory").then(function(mem) {
mem.getData("EngagementZones/PeopleInZone2").then(function(data) {
// now you can access data and do something with it...
// it should be a list of IDs of the people in the engagement zone
// so you could check data.length > 0 to see if there's any people
}, console.log);
}, console.log);
}, console.log);
There are also other events that might be useful, like EngagementZones/PersonEnteredZone2. If you haven't found it yet, there's more details about the javascript API here.

Related

I am unable to understand how to code a logic for money splitting among group of people using MEAN

I am working on a project named "Splitter", where I need to create a group and split the money among N number of people in short similar to splitwise app but I am confused at the logic part, where every individual can update the amount and get the overall amount an individual gets or owes others.
Please let me know if you need more clarification on my question. Any leads would be appreciated.
A pseudo-code would be:
amount_every_person_owes = total_spent / number_of_people
for person in group:
amount_this_person_owes = amount_every_person_owes - amount_this_person_spent
Of course, after arriving at the amount each person owes, you'll have to create a mapping as to who owes how much to the other. I'll leave that part to you.

How do I take my output from a math equation and plot it on a graph using JavaScript?

I am looking to do a "stress test", using the mathematical equation stress=force/area (for entertainment purposes). It is simple a simple enough equation, but I am looking to plot/graph the output answer on a chart. For instance,
How many hours do you have in your workload?
user inputs 10
How many days until your workload is due?
user inputs 5
so the output answer is 2. I want to plot that 2 on a chart from "a little stressed" to "very stressed", or something like that. It should be simple but I cannot figure it out. Here is my jsfiddle
https://jsfiddle.net/avanhout13/4ayfxL16/66/
<body>
Stress Test<br><br>
How many hours do you have in your workload?<input type="number" id="workLoad"/><br/>
How many days until your workload is due?<input type="number" id="daysLeft"/><br/>
<button onClick="calc();"> Test your stress! </button><br/>
<p id="output"></p>
</body>
function calc()
{
var workLoad = parseInt(document.getElementById("workLoad").value);
var daysLeft = parseInt(document.getElementById("daysLeft").value);
document.getElementById("output").innerHTML = workLoad / daysLeft;
}
I think you are trying to collect stress over time, particularly in relation to a deadline. If I'm wrong, please update the question. It's probably a bad question because it's not addressing a specific technical issue, but I'm a beginner here too so not sure about that
I recommend that you step back to get a better picture of what you are trying to do. Saving stuff over time means you need to save the values, with a date as well as a value. There are lots of ways to do that, the simplest would be with localStorage. Having collected your data, you then want to display it as a graph. Lots of ways to do that too - you should be able to Google that
If I was doing this just to play with for myself, I would use a spreadsheet rather than building a web page.

Phaser Weapon plugin, set the kill_DISTANCE

I'm using the phaser weapon plugin, and i've set the kill type to kill_distance:
weapon.bulletKillType = Phaser.Weapon.KILL_DISTANCE;
But, it is automatically set to 2, which doesn't really allow it to travel very far. I'm wondering how i can set it to a larger number
thanks in advance
You can just set the bulletKillDistance:
weapon.bulletKillType = Phaser.Weapon.KILL_DISTANCE;
weapon.bulletKillDistance = 50;
This strikes me as an oversight in the documentation.
Update
This has been updated in the documentation source, and should be updated online once there's a release/deployment.
[static] KILL_DISTANCE : integer
A bulletKillType constant that automatically kills the bullets after they
exceed the bulletDistance from their original firing position.
Unfortunately, I tried searching in documents, but I could not find "bulletDistance". For example, if you use KILL_LIFESPAN, you can change bulletLifespan variable, but there are no "bulletDistance" in document. This is either not implemented or they forgot it in the docs. Try this and it may/may not work.

play a single beep (beep.js)

i'm trying to create a "generative score" using beep.js based on some map data i have. i am using new Beep.Voice as placeholder for notes associated to specific types of data (7 voices total). as data is displayed, a voice should be played. i'm doing things pretty "brute force" so far and i'd like it to be cleaner:
// in the data processing function
voice = voices[datavoice]
voice.play()
setTimeout(function(){killVoice(voice)}, 20)
// and the killvoice:
function killVoice(voice) {
voice.pause()
}
i'd like to just "play" the voice, assuming it would have a duration of, say, 20ms (basically just beep on data). i saw the duration property of voices but couldn't make them work.
the code is here (uses grunt/node/coffeescript):
https://github.com/mgiraldo/inspectorviz/blob/master/app/scripts/main.coffee
this is how it looks like so far:
https://vimeo.com/126519613
The reason Beep.Voice.duration is undocumented in the READ ME is because it’s not finished yet! ;) There’s a line in the source code that literally says “Right now these do nothing; just here as a stand-in for the future.” This applies to .duration, .attack, etc. There’s a pull request to implement some of this functionality here but I’ve had to make some significant structural changes since that request was submitted; will need to take a closer look soon once I’ve finished fixing some larger structural issues. (It’s in the pipeline, I promise!)
Your approach in the meantime seems right on the money. I’ve reduced it a bit here and made it 200 milliseconds—rather than 20—so I could here it ring a bit more:
var voice = new Beep.Voice('4D♭')
voice.play()
setTimeout( function(){ voice.pause() }, 200 )
I saw you were using some pretty low notes in your sample code, like '1A♭' for example. If you’re just testing this out on normal laptop speakers—a position I am often myself in—you might find the tone is too low for your speakers; you’ll either hear a tick or dead silence. So don’t worry: it’s not a bug, just a hardware issue :)
Forget everything I said ;)
Inspired by your inquiry—and Sam’s old pull request—I’ve just completed a big ADSR push which includes support for Voice durations. So now with the latest Beep.js getting a quick “chiptune-y” chirp can be done like this:
var voice = new Beep.Voice( '4D♭' )
.setOscillatorType( 'square' )
.setAttackDuration( 0 )
.setDecayDuration( 0 )
.setSustainDuration( 0.002 )
.setReleaseDuration( 0 )
.play()
I’ve even included an ADSR ASCII-art diagram in the new Beep.Voice.js file for easy referencing. I hope this helps!

Timing in Three.js - for interactive shorts

I've recently coming across a lot of great examples of interactive shorts that are made with three.js.
One example is http://www.dilladimension.com/
So I wanted to ask - how does the timing in those actually work? Any known libraries for that?
Music & Visuals are synchronized perfectly and would love to know how.
I think you may be over thinking this.
// psuedo code...
// on start
music.start()
startMs = now()
// animation loop
for event in events {
if (!event.handled && (currentMs - startMs) > timelineEvent.startMs) {
event.doStuff();
event.handled = true;
}
}
Time marches on pretty predictably and measurably. If you know when you started, it's pretty easy to figure out where you are right now. Then simply compare that to a an array of timestamped events and execute their instructions.

Categories