Pepper: return to the start of the program if there is not interaction - pepper

I'm making a Pepper app with Choregraphe and I have a doubt:
Pepper has to maintain a conversation with a human user and the problem is that if the user "disappears", the app is in middle of an state, and if it doesn't get any interaction, it should got to the first state (return to the start of the program). The idea was to use a timeout of no response (like the timeout between machines). Is there a way to do this with Choregraphe?
PD: The project is big and there are a lot of boxes, so add a timeout box and link it to all boxes can be messy.
PD: I have been looking to make a trigger condition, but in the condition it should detect tablet interactions like touch or that user talk to the robot.

A good way is to put all the "lot of boxes" into a parent-box (new box/diagram box).
Thus when you time out, you just stop the parent box, and all the inner box will be stopped automatically.

Related

How to script an interactive NPC having dialogue and menus in LUA with C++?

I'm working on a 2D game engine in C++ and have thought about moving the NPC scripts such as dialogues and menu selection items into LUA. I'm having a hard time figuring out how to wait for a response from the user/client. My scenario is as follows -
User clicks on NPC.
NPC initiates a dialogue window, player cannot move. LUA script is read and started to run. Example:
mes("Hello! " .. PlayerName)
next()
reply = select("Would you like to do this?", "Or that?")
if reply == 1 then
mes("You chose: Or that!")
close()
end
Now, I want the script to send one message mes at a time, and the next() function would send a next button to the client. After which the script pauses and waits for the user's input.
Once the next button is clicked, the script continues, sending a menu to the client. Upon selection it further continues into the conditional clause or not, depending on the selection.
All this is server sided and the dialogues are sent to the client. What I want to achieve is a pause functionality while waiting for the client's response.
What would be a good way to achieve this in Lua? If you have suggestions for best practices I would appreciate that as well.
I'll agree with #Blaze and go with coroutines as my answer. The question would then be, when and how to wrap Lua scripts into coroutines.
Just wrapping every script into its own coroutine might* lose you some performance, but if most of your scripts are longer than just a few lines, this should not be very noticeable. Aside from speed concerns you'd have to keep in mind that in 5.1 coroutine.running() would then not return nil even in the top level of the script, because that's also just a coroutine. In 5.3 this is less of a problem, as it always returns a thread plus a boolean.
* You'll need to benchmark if this is at all relevant
The next big question would be whether to do the wrapping in Lua or in C(++). Lua is obviously more flexible and easier to change, but C might gain you some performance, which is rarely as relevant as when developing games. The obvious downside being that the C API is just more inconvenient to use.
The most important issue though, is that you couldn't (or shouldn't) just implement, for example, next() as just a wrapper around coroutine.yield('next') or something like that, because you may have nested coroutines; so you'd need some more logic around that to pass through your API calls to the top level and then to C++.
I hope this gives you a good overview of the most important considerations when deciding whether or not to go with coroutines for this problem.

Pepper: disable events temporally

I'm programming a Pepper app with Choregraphe to make a conversation. This conversations have some different sorted states:
Hello (start of conversation)
ask for information
Specify the information
Goodbye (end of the conversation)
To start a conversation, people have to get close to the robot and the robot has to detect a face.
The problem is that if I am in middle of the conversation and the robot detect another face, it starts the conversation at the beginning. So I need to disable the event temporally, while the robot is in a conversation. Is there a way to do it?
These are the events output of Choregraphe:
At your place, I would program it as a finite state machine: you decide your detection and the way to switch from one state to another, in a simple way. Each processing of one state is stopped when you change state.
You can download a simple state machine here: http://protolab.aldebaran.com/public/the_3_templates.zip
you cannot disable them on that format, but if you use the "subscribe to event" box, there are start/stop inputs that you can use to enable/disable the box, i.e. subscribe/unsubscribe to the events.
At the end I visit this part of documentation and looked at Engagement Modes.
To allow a wider range of behaviors, ALBasicAwareness provides 3 engagement modes that specify how “focused” the robot is on the engaged person.
“Unengaged”: (Default mode) when the robot is engaged with a user, it can be distracted by any stimulus, and engage with another person.
“FullyEngaged”: as soon as the robot is engaged with a person, it stops listening to stimuli and stays engaged with the same person. If it loses the engaged person, it will listen to stimuli again and may engage with a different person.
“SemiEngaged”: when the robot is engaged with a person, it keeps listening to the stimuli, and if it gets a stimulus, it will look in its direction, but it will always go back to the person it is engaged with. If it loses the person, it will listen to stimuli again and may engage with a different person.
I have used FullyEngaged and the robot only focuses on the first person that enter the robot Zone 1.
This is done like this:
basic_awareness = ALProxy("ALBasicAwareness", ip_robot, port_robot)
basic_awareness.setEngagementMode("FullyEngaged")
basic_awareness.startAwareness()

How to detect if computer is shutting down to save session

I am making an RPG game with C++/x86 asm. My question is related to the C++ component. In C++/win32 how would I detect if the computer is shutting down or turning off, or whatever else - so that I can save the game session. My game has a 'save' option, but if the user or another program decides to shut off the computer how can I detect this with some kind of API hook so that I can instantly save the game session to the text file.
Now please don't suggest an option by creating a thread to run passively as I want to keep the file size to a minimum, so if you can suggest some sort of WM_ hook that would be great. I'd refer to MSDN but I don't want to be searching for hours through their WM directory.
You can handle session saving in response to the WM_ENDSESSION message. Note that after your message handler returns from handling this, your process may be terminated at any time, so you need to save it directly during the message handler, and not just set a flag to let some later code handle the saving, because that later code might not get to execute.
A comment suggests the WM_QUERYENDSESSION message. This has a slightly different meaning: it gives applications the chance to complain about the session ending, and gives the user a chance to not log off / shut down the system. Based on your question, you have no intention of preventing any such thing, so WM_ENDSESSION seems like a better match to me.

How to make a c++ program which is waiting for some event, appear responsive?

I am using visual studio 2010 to develop a windows form application using c++.
This program waits for an event like connection request and displays a message
But this program is shown as "not responding" in windows task manager.
Is there any way to make the program appear responsive ??
The standard practice for this situation is to use multi-threading. Create a background thread to wait for the connection request or whatever event you need that might cause the primary thread to block.
This allows the user interface of your application to remain responsive. If you don't use a thread, the primary UI thread will be blocked waiting for the request and can't handle other events such as drawing the form, responding to window events, etc.
In Windows programming, any activity that is going to take a significant amount of time should be threaded. This isn't a hard rule, but a pragmatic amount of threading will make a world of different in giving your application a smooth, responsive feel. The primary thread should be reserved for drawing and handling user interaction.
A Google search will give you plenty of examples, but here is a decent one to get you started.

C++ : Running a background task all the time on machine

I want to make an MFC app which leave a thread/process running in the background all the time that keeps track of something like hard disk size.
Whenever the hard disk size goes beyond lets say 90% it shows a warning dialog (also MFC dialog of same app).
I am not sure how to do it.
I tried the windows service option, but it doesn't seem much reliable to me , as most of the times, the service is not successfully installed, or if installed it doesn't get started successfully.
What other options do I have to achieve it?
Any help is appreciated.
Create a worker thread which keep on monitoring the disk space.
Create a user defined message in the main thread and provide a handler for it
When disk space goes more than 90%, Post a message (Post the user defined message that you created)
From the main thread handler for the user defined message "Display the warning message"
Note: Services are not suitable for this task as they don't like user interactions.