*
This commit is contained in:
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c8ad34b1803a3594a86d256cd3c7ae57
|
||||
timeCreated: 1451913636
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12b57bd5d4d44cd4f9f47c70380925f0
|
||||
timeCreated: 1446988057
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,212 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 358edfed70794324c8b6d35fef3ed9fe
|
||||
timeCreated: 1451914723
|
||||
licenseType: Free
|
||||
ModelImporter:
|
||||
serializedVersion: 19
|
||||
fileIDToRecycleName:
|
||||
100000: 1
|
||||
100002: 10
|
||||
100004: 11
|
||||
100006: 12
|
||||
100008: 13
|
||||
100010: 14
|
||||
100012: 15
|
||||
100014: 16
|
||||
100016: 16518
|
||||
100018: 16518 1
|
||||
100020: 16518 1_MeshPart0
|
||||
100022: 16518 1_MeshPart1
|
||||
100024: 16518 1_MeshPart2
|
||||
100026: 16518 1_MeshPart3
|
||||
100028: 16518_MeshPart0
|
||||
100030: 16518_MeshPart1
|
||||
100032: 16518_MeshPart2
|
||||
100034: 16518_MeshPart3
|
||||
100036: 17
|
||||
100038: 18
|
||||
100040: 19
|
||||
100042: 2
|
||||
100044: 26922
|
||||
100046: 26922 1
|
||||
100048: 26922 2
|
||||
100050: 26922 3
|
||||
100052: 2780
|
||||
100054: 28984
|
||||
100056: 28984 1
|
||||
100058: 28984 1_MeshPart0
|
||||
100060: 28984 1_MeshPart1
|
||||
100062: 28984_MeshPart0
|
||||
100064: 28984_MeshPart1
|
||||
100066: 3
|
||||
100068: 4
|
||||
100070: 5
|
||||
100072: 6
|
||||
100074: 62
|
||||
100076: 7
|
||||
100078: 8
|
||||
100080: 9
|
||||
100082: //RootNode
|
||||
100084: PCB
|
||||
400000: 1
|
||||
400002: 10
|
||||
400004: 11
|
||||
400006: 12
|
||||
400008: 13
|
||||
400010: 14
|
||||
400012: 15
|
||||
400014: 16
|
||||
400016: 16518
|
||||
400018: 16518 1
|
||||
400020: 16518 1_MeshPart0
|
||||
400022: 16518 1_MeshPart1
|
||||
400024: 16518 1_MeshPart2
|
||||
400026: 16518 1_MeshPart3
|
||||
400028: 16518_MeshPart0
|
||||
400030: 16518_MeshPart1
|
||||
400032: 16518_MeshPart2
|
||||
400034: 16518_MeshPart3
|
||||
400036: 17
|
||||
400038: 18
|
||||
400040: 19
|
||||
400042: 2
|
||||
400044: 26922
|
||||
400046: 26922 1
|
||||
400048: 26922 2
|
||||
400050: 26922 3
|
||||
400052: 2780
|
||||
400054: 28984
|
||||
400056: 28984 1
|
||||
400058: 28984 1_MeshPart0
|
||||
400060: 28984 1_MeshPart1
|
||||
400062: 28984_MeshPart0
|
||||
400064: 28984_MeshPart1
|
||||
400066: 3
|
||||
400068: 4
|
||||
400070: 5
|
||||
400072: 6
|
||||
400074: 62
|
||||
400076: 7
|
||||
400078: 8
|
||||
400080: 9
|
||||
400082: //RootNode
|
||||
400084: PCB
|
||||
2300000: 16518 1_MeshPart0
|
||||
2300002: 16518 1_MeshPart1
|
||||
2300004: 16518 1_MeshPart2
|
||||
2300006: 16518 1_MeshPart3
|
||||
2300008: 16518_MeshPart0
|
||||
2300010: 16518_MeshPart1
|
||||
2300012: 16518_MeshPart2
|
||||
2300014: 16518_MeshPart3
|
||||
2300016: 26922
|
||||
2300018: 26922 1
|
||||
2300020: 26922 2
|
||||
2300022: 26922 3
|
||||
2300024: 2780
|
||||
2300026: 28984 1_MeshPart0
|
||||
2300028: 28984 1_MeshPart1
|
||||
2300030: 28984_MeshPart0
|
||||
2300032: 28984_MeshPart1
|
||||
2300034: 62
|
||||
3300000: 16518 1_MeshPart0
|
||||
3300002: 16518 1_MeshPart1
|
||||
3300004: 16518 1_MeshPart2
|
||||
3300006: 16518 1_MeshPart3
|
||||
3300008: 16518_MeshPart0
|
||||
3300010: 16518_MeshPart1
|
||||
3300012: 16518_MeshPart2
|
||||
3300014: 16518_MeshPart3
|
||||
3300016: 26922
|
||||
3300018: 26922 1
|
||||
3300020: 26922 2
|
||||
3300022: 26922 3
|
||||
3300024: 2780
|
||||
3300026: 28984 1_MeshPart0
|
||||
3300028: 28984 1_MeshPart1
|
||||
3300030: 28984_MeshPart0
|
||||
3300032: 28984_MeshPart1
|
||||
3300034: 62
|
||||
4300000: 62
|
||||
4300002: 2780
|
||||
4300004: 16518_MeshPart0
|
||||
4300006: 16518_MeshPart1
|
||||
4300008: 16518_MeshPart2
|
||||
4300010: 16518_MeshPart3
|
||||
4300012: 16518_MeshPart0
|
||||
4300014: 16518_MeshPart1
|
||||
4300016: 16518_MeshPart2
|
||||
4300018: 16518_MeshPart3
|
||||
4300020: 26922
|
||||
4300022: 26922
|
||||
4300024: 26922
|
||||
4300026: 26922
|
||||
4300028: 28984_MeshPart0
|
||||
4300030: 28984_MeshPart1
|
||||
4300032: 28984_MeshPart0
|
||||
4300034: 28984_MeshPart1
|
||||
9500000: //RootNode
|
||||
materials:
|
||||
importMaterials: 1
|
||||
materialName: 0
|
||||
materialSearch: 1
|
||||
animations:
|
||||
legacyGenerateAnimations: 4
|
||||
bakeSimulation: 0
|
||||
resampleRotations: 1
|
||||
optimizeGameObjects: 0
|
||||
motionNodeName:
|
||||
animationImportErrors:
|
||||
animationImportWarnings:
|
||||
animationRetargetingWarnings:
|
||||
animationDoRetargetingWarnings: 0
|
||||
animationCompression: 1
|
||||
animationRotationError: 0.5
|
||||
animationPositionError: 0.5
|
||||
animationScaleError: 0.5
|
||||
animationWrapMode: 0
|
||||
extraExposedTransformPaths: []
|
||||
clipAnimations: []
|
||||
isReadable: 1
|
||||
meshes:
|
||||
lODScreenPercentages: []
|
||||
globalScale: 1
|
||||
meshCompression: 0
|
||||
addColliders: 0
|
||||
importBlendShapes: 1
|
||||
swapUVChannels: 0
|
||||
generateSecondaryUV: 0
|
||||
useFileUnits: 1
|
||||
optimizeMeshForGPU: 1
|
||||
keepQuads: 0
|
||||
weldVertices: 1
|
||||
secondaryUVAngleDistortion: 8
|
||||
secondaryUVAreaDistortion: 15.000001
|
||||
secondaryUVHardAngle: 88
|
||||
secondaryUVPackMargin: 4
|
||||
useFileScale: 1
|
||||
tangentSpace:
|
||||
normalSmoothAngle: 60
|
||||
normalImportMode: 0
|
||||
tangentImportMode: 3
|
||||
importAnimation: 1
|
||||
copyAvatar: 0
|
||||
humanDescription:
|
||||
human: []
|
||||
skeleton: []
|
||||
armTwist: 0.5
|
||||
foreArmTwist: 0.5
|
||||
upperLegTwist: 0.5
|
||||
legTwist: 0.5
|
||||
armStretch: 0.05
|
||||
legStretch: 0.05
|
||||
feetSpacing: 0
|
||||
rootMotionBoneName:
|
||||
hasTranslationDoF: 0
|
||||
lastHumanDescriptionAvatarSource: {instanceID: 0}
|
||||
animationType: 2
|
||||
humanoidOversampling: 1
|
||||
additionalBone: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2aaee285323f2ba448550885035f6519
|
||||
timeCreated: 1446987472
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66cbc8a8f999670488c7d4d074b5f378
|
||||
folderAsset: yes
|
||||
timeCreated: 1451914681
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dfe2d57612b00fc479ce8d6bf1e8077f
|
||||
timeCreated: 1451914681
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcddec219066ebd4992dbb0ae1100f7c
|
||||
timeCreated: 1451914681
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ae596ca993a71f4c93470d01128cc96
|
||||
timeCreated: 1451914681
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cd653f2f65305a44a9092dfcca1cbb0
|
||||
timeCreated: 1451914696
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c772ffff0c820443883d3cab9d31c0f
|
||||
timeCreated: 1451914696
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8b6febdce1e6b247b6984943905022f
|
||||
timeCreated: 1451914717
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a9a0e60a422666941b96b2495d1ca220
|
||||
timeCreated: 1451914717
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,106 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.IO.Ports;
|
||||
using System;
|
||||
|
||||
public class QuadcoperClient : MonoBehaviour {
|
||||
private SerialPort port;
|
||||
public string portName = "COM5";
|
||||
private bool _stream = false;
|
||||
|
||||
private int[] motor_speeds = new int[4];
|
||||
|
||||
// Use this for initialization
|
||||
void Start() {
|
||||
Connect();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
if (port != null && port.IsOpen)
|
||||
{
|
||||
// UpdateOrientation();
|
||||
}
|
||||
}
|
||||
|
||||
void Connect() {
|
||||
port = new SerialPort(portName);
|
||||
port.BaudRate = 1500000;
|
||||
port.Open();
|
||||
port.ReadTimeout = SerialPort.InfiniteTimeout;
|
||||
}
|
||||
|
||||
void Disconnect() {
|
||||
port.Close();
|
||||
}
|
||||
|
||||
static Quaternion AccelerationToOrientation(Vector3 acceleration)
|
||||
{
|
||||
acceleration.x = -acceleration.x;
|
||||
acceleration.z = -acceleration.z;
|
||||
if (Vector3.Dot(acceleration.normalized, Vector3.up) > 0.9999f){
|
||||
return Quaternion.identity;
|
||||
}
|
||||
return Quaternion.FromToRotation(Vector3.up, acceleration);
|
||||
}
|
||||
|
||||
public void SetMotorSpeed(byte motor, byte speed) {
|
||||
port.ExecuteCommand(UartCommand.Create(uart_commands.motor_write).Write<byte>(motor).Write<byte>(speed));
|
||||
}
|
||||
|
||||
public Vector3 ReadAccelerometer() {
|
||||
var response = port.ExecuteCommand(UartCommand.Create(uart_commands.acc_read));
|
||||
var result = response.CreateReader().Read<Vector3>();
|
||||
return new Vector3(result.x, result.z, result.y);
|
||||
}
|
||||
|
||||
void SyncTransform()
|
||||
{
|
||||
transform.localRotation = AccelerationToOrientation(ReadAccelerometer());
|
||||
}
|
||||
|
||||
void OnGUI() {
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
var new_speed = (int)GUI.HorizontalSlider(new Rect(10, 10 + 30 * i, 300, 30), motor_speeds[i], 0, 100);
|
||||
if (new_speed != motor_speeds[i]) {
|
||||
motor_speeds[i] = new_speed;
|
||||
SetMotorSpeed((byte)i, (byte)new_speed);
|
||||
}
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Play sound"))
|
||||
{
|
||||
port.ExecuteCommand(UartCommand.Create(uart_commands.play_sound));
|
||||
}
|
||||
|
||||
if (GUI.Button(new Rect(400, 10, 150, 30), "Read accelerometer"))
|
||||
{
|
||||
Debug.Log(ReadAccelerometer());
|
||||
SyncTransform();
|
||||
}
|
||||
|
||||
if (_stream)
|
||||
{
|
||||
if (GUI.Button(new Rect(10, 130, 150, 30), "Stop stream"))
|
||||
{
|
||||
_stream = false;
|
||||
}
|
||||
} else {
|
||||
if (GUI.Button(new Rect(10, 130, 150, 30), "Start stream")) {
|
||||
_stream = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (_stream)
|
||||
{
|
||||
SyncTransform();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnDestroy() {
|
||||
Disconnect();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b1502c8102409e4a9549559e8db7eb7
|
||||
timeCreated: 1446981335
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da8aba65204e1d9408a8dd107e205f2d
|
||||
timeCreated: 1446988062
|
||||
licenseType: Free
|
||||
NativeFormatImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f11d2a31b724a6449ba3c2d362bcde5
|
||||
timeCreated: 1446981321
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,139 @@
|
||||
|
||||
using System.Collections;
|
||||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
using System.IO.Ports;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct UartCommandHeader {
|
||||
public uint id;
|
||||
public byte payloadSize;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||
public struct UartCommand {
|
||||
public UartCommandHeader header;
|
||||
public const int MaxPayloadSize = 32;
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MaxPayloadSize)]
|
||||
public byte[] payload;
|
||||
|
||||
public UartCommand(uint _id, byte[] payloadBytes = null) {
|
||||
byte _payloadSize = 0;
|
||||
if (payloadBytes != null) {
|
||||
if (payloadBytes.Length > MaxPayloadSize) {
|
||||
throw new Exception("Too big payload!");
|
||||
}
|
||||
_payloadSize = (byte)payloadBytes.Length;
|
||||
}
|
||||
header = new UartCommandHeader() { id = _id, payloadSize = _payloadSize };
|
||||
payload = new byte[MaxPayloadSize];
|
||||
|
||||
if (_payloadSize > 0) {
|
||||
Array.Copy(payloadBytes, payload, payloadBytes.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public UartCommand Write<T>(T val) where T : struct {
|
||||
var bytes = Utils.StructToBytes(val);
|
||||
for (int i = 0; i < bytes.Length; ++i) {
|
||||
payload[header.payloadSize++] = bytes[i];
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public static UartCommand Create() {
|
||||
var result = new UartCommand();
|
||||
result.payload = new byte[MaxPayloadSize];
|
||||
return result;
|
||||
}
|
||||
|
||||
public static UartCommand Create(uint id) {
|
||||
var result = Create();
|
||||
result.header.id = id;
|
||||
return result;
|
||||
}
|
||||
|
||||
public UartCommand SetID(uint _id) {
|
||||
header.id = _id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static int Size {
|
||||
get { return Marshal.SizeOf(typeof(UartCommandHeader)) + MaxPayloadSize; }
|
||||
}
|
||||
|
||||
public UartCommandReader CreateReader() {
|
||||
return new UartCommandReader(ref this);
|
||||
}
|
||||
}
|
||||
|
||||
public class UartCommandReader {
|
||||
private int offset = 0;
|
||||
private byte[] buffer;
|
||||
public UartCommandReader(ref UartCommand cmd) {
|
||||
buffer = cmd.payload;
|
||||
}
|
||||
|
||||
public T Read<T>() where T : struct {
|
||||
var result = Utils.StructFromBytes<T>(buffer, offset);
|
||||
offset += Marshal.SizeOf(typeof(T));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Utils {
|
||||
public static T StructFromBytes<T>(byte[] buffer, int offset = 0) where T : struct {
|
||||
var handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
|
||||
var result = (T)Marshal.PtrToStructure(new IntPtr(handle.AddrOfPinnedObject().ToInt64() + offset), typeof(T));
|
||||
handle.Free();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static byte[] StructToBytes<T>(T val) where T : struct {
|
||||
var result = new byte[Marshal.SizeOf(typeof(T))];
|
||||
var handle = GCHandle.Alloc(result, GCHandleType.Pinned);
|
||||
Marshal.StructureToPtr(val, handle.AddrOfPinnedObject(), false);
|
||||
handle.Free();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SerialPortEx {
|
||||
public static UartCommand ExecuteCommand(this SerialPort _this, UartCommand cmd) {
|
||||
SendCommand(_this, cmd);
|
||||
return ReceiveCommand(_this);
|
||||
}
|
||||
|
||||
private static void SendCommand(SerialPort _this, UartCommand cmd) {
|
||||
var bytes = Utils.StructToBytes(cmd);
|
||||
_this.Write(bytes, 0, bytes.Length);
|
||||
_this.BaseStream.Flush();
|
||||
}
|
||||
|
||||
private static UartCommand ReceiveCommand(SerialPort _this) {
|
||||
var buffer = new byte[UartCommand.Size];
|
||||
int done = 0;
|
||||
while (done != buffer.Length) {
|
||||
var len = _this.Read(buffer, done, buffer.Length - done);
|
||||
if (len <= 0) {
|
||||
throw new Exception("Failed to read command");
|
||||
}
|
||||
done += len;
|
||||
}
|
||||
_this.BaseStream.Flush();
|
||||
return Utils.StructFromBytes<UartCommand>(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public struct uart_commands {
|
||||
public static uint FOURCC(char a, char b, char c, char d) {
|
||||
return ((uint)((((uint)d) << 24) | (((uint)c) << 16) | (((uint)b) << 8) | ((uint)a)));
|
||||
}
|
||||
public static uint led_write = FOURCC('L', 'e', 'd', 'W');
|
||||
public static uint led_read = FOURCC('L', 'e', 'd', 'R');
|
||||
public static uint motor_write = FOURCC('M', 't', 'r', 'W');
|
||||
public static uint play_sound = FOURCC('P', 'S', 'n', 'd');
|
||||
public static uint acc_read = FOURCC('A', 'c', 'c', 'R');
|
||||
public static uint gyro_read = FOURCC('G', 'r', 'o', 'R');
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25178827e9ce9bf498d903d4fba6f3af
|
||||
timeCreated: 1451812741
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user