Game Design Hw1

Variables:

1.

very simple, just create variable and Debug.Log them out:

2.

The tricky part is to insert the variables as string in the story text elegantly, without using too much + operator:

therefore I use the operator in the code:

IF statement:

I combined the 3 car speed control tasks together in one program

when pressing w the car accelarates, when pressing s it decelarates

when the speed is positive the state is moving

when the speed is negative the state is reverse

when the -0.001 < speed < 0.001 speed will become 0 and state = stop

speed limited to -100 ~ 100, reaching the boundary will cause the state to become overspeed

To enable keyboard input, I used the special function in unity GetAxis()

To have a reasonable update rate of data, I used Time.deltatime

Switch

  1. color

Very simple, not much to say.

2.  change weapon

I feel like it is easier to implemnt it usinf IF, because I googled that it is not quite easy to detect arbitary keyboard input and tell what is the key in unity.

Array

  1. change color

2. change color by tag

For loop

1.

I feel the most difficlut part is to put the camera at the right position so that it can see all the cubes

2.

function

I put the three tasks together:

press w to move

press space tgo change color

press s to measure distance

Colla-Draw – Kris – Rudi – Interaction Lab Final

CONCEPTION AND DESIGN:

It is a collaborative drawing machine aims at promoting and inspiring collaborative work, cooperation and communication. In real case it could be used as an ice-breaking game; as the cooperative task provided is designed to be both simple (in terms of abstraction: i.e. it does not require players to manage a company together, but simply drawing a picture), but also difficult (in terms of collaboration: without collaboration it is almost impossible to finish the task ) it may also be used by researchers to study how human beings interact with each other in a collaborative work. The device requires 4 players to play with. In front of the m is a large screen with a special pen on it:


Notice the 4 colorful circles in the screen and the lines connecting them. These together are the pen. Three players will have a handy device in their hands, which contains a “spin-able” part. Players spin it to control the rotation of each circle on the pen. The last player has 2 buttons in hand, the red one is to draw (from the tip of the pen which is the red circle) and the black button it to undo the previous stroke:

three most important designs in this project are: the rotation control unit. The handle and the style of the pen. With the development of our project the design of these three kept changing.

For the spin control unit, the ideal choice is to use a rotatory encoder. We tried it for several days, but then we realized we were facing a fatal problem. (The only time I stayed overnight since college is to solve the problem) with the help of Tristan I almost hacked the microcontroller of Arduino Uno but finally failed (It will be detailed recorded in the next part). The second alternative is quark: to use motor inversely, as we learned at class if we spin a motor it will generate electric signals. But then I realized it needs complex circuits to make the motor able to send out signals in two rotation direction. As the due time is approaching, we have to go back to potential meter. A drawback is that I can only rotate it 360 degrees then got stuck. In observing the players in ima show we find occasionally it slightly affects the performance of the device.

We paid attention to very details of user experience, and the handle is designed very smartly using human engineering. The shape of it fits very well with human hands (see the pic above) and people are happy holding it. We laser cut the boards and put them together. I suggested of using 3D printer before but steve reminded me that there are some small and delicate parts in it and 3D printer is not accurate enough.

As for the style of the pen. We pursue a simplicity in the design of the shape, yet we, again, paid attention to very details of user experience. The color of each circle corresponds to a color tape in the players device. We adjusts the radius of the circle, the size of the circle, the size of the pen stroke many times and ask people to test different versions to hasve best visual effect. The function of the pen is actually inspired by a visualization of Fourier transformation, but I’ll stop talking about math here.

FABRICATION AND PRODUCTION

#A Full Record on Rotatory Encoder#

To me it is the most exciting part. Indeed as Rudi said we should have changed our direction the minute we realized the problem, but my problem is that I could not resist new knowledge (A conflict on pin interrupt?? what’s that?? & I need to control registers in microcontroller to solve it? cool!). Although I failed, that night offers me knowledge and experience that I could hardly get in class, and I’m not regret of that.

This part is also a review for myself about what I learned in that breezeless night.

1.
The problem starts with the library that use the rotatory encoder: it asks as to make an object:

Encoder myencoder

Then call the counting function like:

encoder.counting()

yet weirdly we don’t specify pins here! After Steve tried every pins he finds only when we connect the encoder to pin2 and 3 it works. But we need to connect 3 encoders on the Arduino. Anyway this default use of pins is weird so i checked the source file in cpp.
In the source I found many unfamiliar things: some hexadecimal value assignment to a constant called PCINT, and another called some MASK, a function call “sei()” appears in the middle of nowhere, a function define “ISR()” without any return type… But I do recognize one lines: digitalRead(2) (and 3).

2.

Tristan gives a simple solution. He suggests me to copy paste the file, reset the pins in the digitalRead, then I can have to different objects in my code using different pins. But the IDE raised errors of “redefine variables”, then Tristan reminds me to change all the variables to avoid that. In doing it most of the problem got solved, with only one left: “Error: redefinition of __vector_5()__”.

3.
I scroll the codes up and down without finding and words in the text that looks like a “__vector 5__”. Finally I realized it is a situation I had no experience before, and it might has something to do with all the “sei”s and PCINTs above. Then I google.

after about 1 hour I had some basic ideas about it

#vecter 5 is a variable of Pin Interrupt that governs a range of pins including pin2 and 3.
#A PIN interrupt can be considered as a event listener, when the value on a pin changed, it will trigger the interrupt, which will stop the current calculation in processor and run a new function
# the function is ISR()
#There are three pin interrupts: vector 3 4 5: they are not defined explicitly: the variable PCINT refers to a register with 2 bits that controls the open and close of a pin interrupt; as each interrupt governs a range of pins, MASK is another register that specify a certain pins to listen to.
#sei(); means to start monitoring interrupts

4.

That’s why it specifies pin 2 and 3. Therefore if I could set the code to use a new pin interrupt, say vector 4, I could set new pins and solve the problem. Understanding all the theories in the next several hours, the last thing to do is to study the documentation of the microcontroller on Uno: basically to find which interrupt corresponds to which PCINT and MASK register digit and correspond to which pins.
In fact it worked. I changed the pins and connect it to the encoder, it gives correct output. But when I tried to put two together, there is always one of them not working. I did various experiment and found one thing: as mentioned I copy pasted the codes so I have two of them compiling together, only the encoder connected to the code that is firstly compiled works. It means there are still some hardware resource that are shared by the codes.

Then I found the code refers to another library, a look at it shows it is a timer library uses processor clock pulse, other types of interrupts (there are other types besides pin interrupts) …. Fine.

——————————————————————-

We missed user test because on it, yet we conduct our own user test later. many useful suggestions were offered and I have recorded some of them in the first section. The idea of different color circles is a feedback from the users, also based on feedback I improved the rotation algorithms to make the drawing process more smooth….

CONCLUSIONS:

It is a great success in IMA show. There are always people in front of our table. Strangers came together, had a great time in this collaborative game, and some of them even become friends and exchanged wechats. Among them, one representative from the manufacturer of Arduino is very interested in our project. Hearing our problem in the encoder, he assed steve’s wechat and told us he could help with the problem and provide us with better equipment to remake it. In general the final project does not fail us.

*Interestingly, as a work focusing on collaboration, it is also done collaboratively. Steve and me have been partners since midterm and we worked together extremely well. Here I would like to show my gratitude to Steve.

*At thus end of the semester, I would also like to say thanks to Rudi, for… well for everything in these two semester.

Last Recitation Interlab Kris

The last recitation reviews the use of map function, and I went to Prof. Moon’s workshop to review Serial Communication. Prof. Moon didn’t leave us a homework, instead, he asks us to review what he taught in class and finish the implementation.

We reviewed the use of serial communication code in class:

Arduino to processing is what we will use in final, so we focus more on it in this blog:


void setup() {
Serial.begin(9600);
}

void loop() {
int sensor1 = analogRead(A0);
int sensor2 = analogRead(A1);
int sensor3 = analogRead(A2);

// keep this format
Serial.print(sensor1);
Serial.print(","); // put comma between sensor values
Serial.print(sensor2);
Serial.print(",");
Serial.print(sensor3);
Serial.println(); // add linefeed after sending the last sensor value

// too fast communication might cause some latency in Processing
// this delay resolves the issue.
delay(100);
}


import processing.serial.*;

String myString = null;
Serial myPort;

int NUM_OF_VALUES = 3; /** YOU MUST CHANGE THIS ACCORDING TO YOUR PROJECT **/
int[] sensorValues; /** this array stores values from Arduino **/

void setup() {
size(500, 500);
background(0);
setupSerial();
}

void draw() {
updateSerial();
printArray(sensorValues);

// use the values like this!
// sensorValues[0]

// add your code

//
}

void setupSerial() {
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[ PORT_INDEX ], 9600);
// WARNING!
// You will definitely get an error here.
// Change the PORT_INDEX to 0 and try running it again.
// And then, check the list of the ports,
// find the port "/dev/cu.usbmodem----" or "/dev/tty.usbmodem----"
// and replace PORT_INDEX above with the index number of the port.

myPort.clear();
// Throw out the first reading,
// in case we started reading in the middle of a string from the sender.
myString = myPort.readStringUntil( 10 ); // 10 = '\n' Linefeed in ASCII
myString = null;

sensorValues = new int[NUM_OF_VALUES];
}

void updateSerial() {
while (myPort.available() > 0) {
myString = myPort.readStringUntil( 10 ); // 10 = '\n' Linefeed in ASCII
if (myString != null) {
String[] serialInArray = split(trim(myString), ",");
if (serialInArray.length == NUM_OF_VALUES) {
for (int i=0; i<serialInArray.length; i++) {
sensorValues[i] = int(serialInArray[i]);
}
}
}
}
}

We understand several important use of it:

1. the change of port numbers
2. the use of comma and println / print
3. different between write and print that is: output bytes / string
4. number of sensor values

map function is to map a value based on a certain range: map(value, r00, r01, r10, r11)
which is handy and the theory behind is also very simple:

it is a linear transformation f(x) = kx + b , where k, b can be calculated by the 4 r’s

Project Essay

Project title: collaborative Fourier drawing machine

It is collaborative drawing machine. The project is to stress on, promote and study the human behavior the collaborative work in art design. Many research has been done, including the paper discussing network, Rudi’s video, and a visualization video on Fourier transformation. which, at first gives us a different idea, but after consideration, it lead us finally to this project.

The project consists of a system of nodes that are connected together, each node’s rotation will cause others to rotate as well, the end of the system will has a pen. The users will control the rotation of each node and draw a picture together.
In the following days we will finish three parts:
Arduino: we will make several control machines to the nodes as well as the pen using rotatery encoder, as well as serial communication. We will try two types of the encoder and test their performance. The the device will sent information of the rotation controlled by users to processing, as well as the control flag of the pen, i.e. whether to draw, to erase or nothing.
Processing: we will using oop with sub system idea to design the drawing display. It implies possible advance use of oop including inheritance so that each movement of a node can pass information to its subnodes. it will also involves in complex algorithms to calculate rotation using complex numbers / matrix / inverse trigonometry etc.
Digital fabrication: we will make a cover for the Arduino hardware with each contains a handle for rotation control, a box to but the hardware in and a button shield for drawing control.

As the name suggests, the project is inspired by several research. What makes us want to focus on collaboration are: the paper we found (posted in the proposal) focuses that in a networked system, the individual node is the core essence, and their collaborative work defines the behavior of the whole network. Therefore it gives us the first inspiration. In class Rudi showed us the video that many people ride bicycles to draw display an animation. This inspired us to design a collaborative drawing machine, but the user can design their own drawing. Lastly, the visualization of Fourier transformation inspired us to design the current form. We want to promote the collaboration among people in the design field, and we are also interested in how people will form a collaboration in doing a complex task. Therefore a record will be made by us after observing the collaboration in our project.

Recitation 9

I made a windmill that will rotate with the control of Arduino:

It is relatively simple: I use a picture of the windnill using media controller:

img = loadImage(“img.jpg”)

Then use serial communication to let Arduino send rotation instruction to processing using a potential meter. When I rotate the potential meter the windmill will rotate correspondingly.