Some thoughts of the CrazyCoding Union

Union activities:

  1. “Reading Books”: Reading something fun… such as The World Is Flat. This made a difference to my opinion…
  2. “Hi, New Teacher”: In our union, almost every member has a “teacher”. In fact, this “teacher” is another union member who learns better than the “student”: By this way, we will be better, together.
  3. “Producing New Problems”:  Any of us can “produce” problems for “weekly tests”. On weekly tests, we can get something fun from the problems.
  4. “Weekly Tests”: Almost every week, we have to take some “small” tests. If we don’t pass the tests, we have to take them again… Until we AK them.
  5. “Solution Sharing”: After the tests, there are always somebody sharing their solutions. By doing this action, we can learn about the different solutions to each problem.
  6. So fun…

Above all, I think… the union will get better… (w)

Arduino Tutorials – [1] Hello World

Getting prepared for these things:

  • Arduino
  • USB Cable
  • PC
  • Internet

 

First things first, let’s install Arduino IDE so that we can upload the code to the Arduino board.

  1. Download the software from http://arduino.cc/download or http://download.mby.pw/software/arduino.exe
  2. Install it. The drivers are included. Please choose “Install” when the driver installing box appears.  AT1-Screenshot-1
  3. Well done~

 

Secondly, let’s upload a test code.

  1. Connect your Arduino to your PC with an USB Cable.
  2. Launch Arduino IDE, then select Board Model (Arduino UNO) and Port in “Tools” (depending on your PC settings)AT1-Screenshot-2
  3. Click “File” -> “Example” -> “01. Basics” -> “Blink”, then click the second button on the top bar “Upload”.AT1-Screenshot-3
  4. Wait a moment until the code is uploaded.
  5. If all things don’t get wrong, you can see a light on the board blinking.
  6. Congratulations~ You succeed.

 

At last, you should understand the code.

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
点亮一秒一个LED灯,然后熄灭一秒,循环。
This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
// 在大多数Arduino板上,引脚13连接着一个板载的LED灯。
// 然后定义一个变量叫做 led,并赋值为13。
int led = 13;

// the setup routine runs once when you press reset:
// 一个被命名为setup的子程序在你按下RESET按钮(或刚上电)后只运行花括号里的代码一次。它通常用于初始化的工作。

void setup() {
// initialize the digital pin as an output.
// 一个被命名为setup的子程序在你按下RESET按钮(或刚上电)后只运行花括号里的代码一次。它通常用于初始化的工作。

//初始化LED(13)引脚为输出引脚。然后该引脚可用于输出高电平(一般为5V)或低电平(0V)
//数字引脚可以被设定为输入(将在下节讲)或输出模式。

//设置引脚模式函数用法:

//pinMode(pin, OUTPUT 或 INPUT);
//	     |               |
//要设置引脚模式的引脚   引脚模式(输出或输入)
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
// 又一个被命名为loop的子程序在执行完setup后一遍又一遍地执行花括号里的代码。
void loop() {
digitalWrite(led, HIGH);
// turn the LED on (HIGH is the voltage level)
// 设置led(13)引脚输出高电平。点亮LED。

// 设置引脚输出函数用法:
//digitalWrite(pin, HIGH 或 LOW);
//              |        |
// 要设置输出的引脚  输出电平(高电平或低电平)

delay(1000);
// wait for a second
// 延时1000毫秒(1秒)。

// 延时函数用法:
//delay(time);
//       |
//要延时的时间(毫秒)

digitalWrite(led, LOW);
// turn the LED off by making the voltage LOW
// 设置led(13)引脚输出低电平。熄灭LED。

delay(1000);
// wait for a second
// 延时1000毫秒(1秒)。
}

So fun. Try to change the time to delay. Then upload the code. What can you see?

Aside

Something about me [1]

 

[Photo by @萱子]

 

Today, I went to an after-school class. I saw a student wear the uniform of Hangzhou Foreign Language School. And I saw some photos of Spring Trip in the HZFLS. It reminded me of an exam, an important exam.

When I was a school pupil, the primary school asked some of the students to join the exam in order to choose the one who has a chance to enter Hangzhou Foreign Language School. Yes, there was only one “lucky” person.

My dad knew that and said in order to encourage me, “If you get the chance, you will get a Microsoft(R) Surface Pro.” I was full of power. But the “hardware” limited me. My grades weren’t good at that time except math.

While I was solving problems in the exam, as I expected, I found they were too difficult for me, I could answer only half of them… One of the math problems were strange, at first I answered it correctly, but soon I didn’t think that was right, so I cut it out. As soon as I finished doing that problem, the teacher asked us to hand the papers. I handed them with my trembling hands.

I left the exam room with disappointment, I tried not to think about it.

I remembered the problem clearly, it was

 

 

Day after day, the results came out. The “luck person” (The 1st student in this exam) told me, “You are the 2nd. And if you could answer one of these problems more. You would get my chance, the chance to HZFLS. ”

Oops, if I didn’t cut the answer to that math problem, I would….

Surface flied away.

The chance flied away.

The Dream flied away.

 

So, I entered Jianlan Middle School instead of HZFLS.

——

Nowadays, I didn’t get good grades in my middle school, but I was addicted to making UAVs[1], so my parents got angry. As soon as I finished my daily homework, they wanted me to do extra “homework”. My dad said, “If you entered HZFLS, you would be always allowed to making them… But… You will join the high-school-enterence exam… You have to learn hard…”

So… WTF… Why did I cut that answer out. It changed my life. How silly I was!

——

However, in some ways, I was the lucky one.

I am able to have some close friends in my current school.

I am able to see that lucky student enjoy the life in HZFLS.

I am able to enjoy something special in JL.

I am able to…

I should treasure what I have.

The Plane Project [1] – 使用串口位运算传输飞行数据 / 控制请求

怎么传输飞行数据和控制请求是一个值得探究的问题。一开始我想用JSON,用Arduino的aJSON库和C#的写出了一些乱七八糟的代码,最后发现数据量、延时直接上天【500ms】,程序还经常跑飞,再加上无线模块的串口速率【19200】就更慢了ww,于是脑洞大开想到了位运算处理,将延时降到了【300ms】。

这是我最初使用JSON的Arduino核心代码:

void process_json() {
aJsonObject *temp_ex;

temp = aJson.getObjectItem(control_request, "Flaps");
if (temp) {
temp_ex = aJson.getObjectItem(temp, "l");
if (temp_ex)
if (temp_ex -> type == aJson_Int)
flaps.l = temp_ex -> valueint;

temp_ex = aJson.getObjectItem(temp, "r");
if (temp_ex)
if (temp_ex -> type == aJson_Int)
flaps.r = temp_ex -> valueint;
}

temp = aJson.getObjectItem(control_request, "Slaps");
if (temp) {
temp_ex = aJson.getObjectItem(temp, "l");
if (temp_ex)
if (temp_ex -> type == aJson_Int)
slaps.l = temp_ex -> valueint;

temp_ex = aJson.getObjectItem(temp, "r");
if (temp_ex)
if (temp_ex -> type == aJson_Int)
slaps.r = temp_ex -> valueint;
}

temp = aJson.getObjectItem(control_request, "Thro");
if (temp)
if (temp -> type == aJson_Int) throttle = temp -> valueint;

temp = aJson.getObjectItem(control_request, "SBak");
if (temp)
if (temp -> type == aJson_Int)
speed_brakes = temp -> valueint;

temp = aJson.getObjectItem(control_request, "Rud");
if (temp)
if (temp -> type == aJson_Int)
rudder = temp -> valueint;

temp = aJson.getObjectItem(control_request, "Ele");
if (temp)
if (temp -> type == aJson_Int)
elevator = temp -> valueint;

temp = aJson.getObjectItem(control_request, "Trim");
if (temp)
if (temp -> type == aJson_Int)
trim = temp -> valueint;

temp = aJson.getObjectItem(control_request, "Lig");
if (temp) {
temp_ex = aJson.getObjectItem(temp, "l1");
if (temp_ex)
if (temp_ex -> type == aJson_Int)
lights[1] = temp_ex -> valuebool;

temp_ex = aJson.getObjectItem(temp, "l2");
if (temp_ex)
if (temp_ex -> type == aJson_Int)
lights[2] = temp_ex -> valuebool;

temp_ex = aJson.getObjectItem(temp, "l3");
if (temp_ex)
if (temp_ex -> type == aJson_Int)
lights[3] = temp_ex -> valuebool;
}
}

void create_json() {

aJson.deleteItem(flight_data);
flight_data = aJson.createObject();

aJson.addNumberToObject(flight_data, "MSpd", motor_speed);
aJson.addNumberToObject(flight_data, "ASpd", air_speed);
aJson.addNumberToObject(flight_data, "GSpd", ground_speed);
aJson.addNumberToObject(flight_data, "Alt", altitude);
aJson.addNumberToObject(flight_data, "Hea", heading);

temp = aJson.createObject();
aJson.addNumberToObject(temp, "Lat", loc.lon);
aJson.addNumberToObject(temp, "Lou", loc.lat);
aJson.addItemToObject(flight_data, "Loc", temp);

temp = aJson.createObject();
aJson.addNumberToObject(temp, "x", acc.x);
aJson.addNumberToObject(temp, "y", acc.y);
aJson.addNumberToObject(temp, "z", acc.z);
aJson.addItemToObject(flight_data, "Acc", temp);

temp = aJson.createObject();
aJson.addNumberToObject(temp, "x", gyro.x);
aJson.addNumberToObject(temp, "y", gyro.y);
aJson.addNumberToObject(temp, "z", gyro.z);
aJson.addItemToObject(flight_data, "Gyro", temp);

temp = aJson.createObject();
aJson.addNumberToObject(temp, "x", angle.x);
aJson.addNumberToObject(temp, "y", angle.y);
aJson.addNumberToObject(temp, "z", angle.z);
aJson.addItemToObject(flight_data, "Angle", temp);

aJson.addNumberToObject(flight_data, "BtVolt", battery_voltage);

}

 

 

The Plane Project [Index]

就是因为这个坑!=_=

image

 

于是就开始填233

目前使用C#作为地面端语言,使用Saitak的F.L.Y. 5控制无人机,Arduino和Raspberry Pi作为机上主要控制系统,搭载各种作死的传感器,如空速计,倾角传感器,地磁传感器等,和各种舵机,使用串口通信模块和DTU进行地面与空中的通信。如果可能,我将会加入自动驾驶仪功能。

别忘了,以后还有更新哟~