Creators: Robot Arm

cpccg_screening_robot

This week we looked at a representation of a robot arm. The body of our robot is allowed to slide horizontally and the arm can pivot at the shoulder (where the upper arm attaches to the body) and at the elbow (where the lower arm attaches to the upper arm).

Transformations

An important point about this project was to show how transformations add up together. Transformations include translations (moving in straight line), rotations (turning about a pivot point) and scaling (changing size). We’ve used translations and rotations for our robot.

In P5, the origin, or place where the x and y coordinates are both zero is at the upper left-hand corner of the screen. The x coordinate gets bigger as we move right and the y coordinate gets bigger as we move down.

When we translate, we move the origin to somewhere else. This is handy for a few reasons but if we are performing rotations. All rotations happen around the origin, wherever that happens to be at the time.

This diagram shows all the transformations we use for our robot:

Robot DOFs (1)

  1. Translate to move the origin to the centre of the robot body
  2. Translate to move the origin to the shoulder
  3. Upper arm rotation at the shoulder
  4. Translate to move the origin to the elbow
  5. Lower arm rotation at the elbow

Because these transformations stack up on top of each other, this is what each part experiences:

  1. Body – Transformations: 1
  2. Upper Arm – Transformations: 1, 2, 3
  3. Lower Arm – Transformations: 1, 2, 3, 4, 5

The body is only affected by one, but the lower arm is affected by all five.

Movement

To move the robot, we set up three variables:

  1. bodyPos to store the body position (our first transformation)
  2. upperArmAngle to store the rotation at the shoulder (our third transformation)
  3. lowerArmAngle to store the rotation at the elbow (our fifth transformation)

We created a function called handleInput() called from the draw() function (which is called every frame). In that we used the keyIsDown() function from P5 to check for keys being held down. We made the left/right arrow keys move the body horizontally, the up/down arrow keys rotate at the shoulder and the Z/X keys to rotate at the elbow.

Source Code

As always, the code can be downloaded from our GitHub repository.

Scratch Advanced – Week 15 – Radio Waves

What are we going to learn this week:

  • A tiny little bit about Waves and how clever they are.
  • A pratical demonstration.
  • Thinking – Yes, it’s tough, you will have to do that part 🙂
  • Coding – Sine Waves

I will hopefully demonstrate how differnt types of waves behave.

I will admit, that I am not an expert here and will probably be unable to answer any of your questions, but you see that’s where you come in and start thinking about these things yourself.

A Pratical Demonstration.

What’s in the Box?

I will bring the Box and we can take a look inside, I might even have two boxes, you never know.

Thinking.

Hmmmmm….

Coding.

Remember the Gravity simulation we did, well we can do the same with Waves.

We will build a few Transmitters and a Receiver which can be “tuned” in to the different transmissions. In fact this would be an ideal Application to do using the Networking in Scratch. Does anyone remember that from last year?

Lets see how we get on, we might set this up with one person as the Transmitter and one person as the Receiver.

I have some of the coding done to Transmit a Wave, but will need help in building a transmitter and obviously something to broadcast as well 🙂

Ok, I know Iam supposed to put up the code before the day, but better late than never.

Here is the code for the Transmitter of the radio Waves. Careful with the SIN code has there are a few nested calculations there.

Transmitter

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

And here is the code for the Reciever.

Reciever

Intermediate Scratch – Challenge 14 – Build a Network Pong Game!

CDA-S2-Challenge14-NetworkPongThis week’s challenge is to build a 2-player networked Pong game.

This challenge made use of the networking ideas that we covered when writing a network Chat program and previously when we learned about networking.

The big ideas behind this challenge were:

  1. Design of a networked program
  2. Division of labour: there are two programs running on two computers, and we have to decide which is which
  3. Using variables  for exchange of data

Here are the presentation slides from the day, in PDF format: CDA-S2-Challenge14-NetworkPong.pdf

If you would like me to send you these slides in PowerPoint format, feel free to get in touch on Twitter or via the comments!