Saturday, 14 June 2014

TriRot first motor test

posted 13 May 2011 15:43 by David Taylor

Okay, so after absolutely no help from the manufacturers, I finally had to write a short app to step through all possible I2C addresses to find the address for the BL_CTRL_v1.2 (I would not recommend this part because of the total lack of customer support or descent documentation).
So I shot the first video of TriRot today as promised to those that follow me on twitter (@gineer). In this video I run to motors in a program that slowly ramps up the speed, but I only use the first byte of the 11 bit resolution for the speed. This equates to 0-255 of 2048. These little motors are amazing.

YouTube Video

Now on to the source code: Not finished, but if you fill in the minor blanks, it will work. The ESC has none of the address jumpers soldered so it is effectively configured for "address 0" which apparently equates to 0x29.
Microsoft C#.Net
0:  using System;
1:  using Microsoft.SPOT;
2:  using Microsoft.SPOT.Hardware;
3:  using System.Threading;
4:  
5:  namespace Tri_Rot_Version_1
6:  {
7:      public class BL_CTRLv12I2C : IDisposable
8:      {
9:          #region Private Variables
10:         private I2CDevice BL_CTRLv12;
11:         private I2CDevice.I2CTransaction[] xActions;
12:         #endregion
13: 
14:         #region [Con|De]structor
15:         public BL_CTRLv12I2C() { }
16:         #endregion
17: 
18:         #region Public Properties
19:         #endregion
20: 
21:         #region Public Methods
22:         public void StartUp(Motor motor)
23:         {
24:             ushort I2CAddress;
25:             switch(motor)
26:             {
27:                 case Motor.Left:
28:                      I2CAddress = 0x29;
29:                      break;
30:                 case Motor.Right:
31:                     I2CAddress = ???;
32:                     break;
33:                 default:
34:                     I2CAddress = ???;
35:                     break;
36:             }
37: 
38:             InitialiseBL_CTRLv12(I2CAddress);
39:         }
40: 
41:         public int SetSpeed(int Speed)
42:         {
43:             if (Speed > 2048) Speed = 2048;
44:             else if (Speed < 0) Speed = 0;
45: 
46:             //break speed into 2 bytes and send;
47:         }
48: 
49:         public void Dispose()
50:         {
51:             BL_CTRLv12.Dispose();
52:         }
53:         #endregion
54: 
55:         #region Private Methods
56:         private void InitialiseBL_CTRLv12(ushort I2CAddress)
57:         {
58:             I2CDevice.Configuration BL_CTRLv12Config = new I2CDevice.Configuration(I2CAddress, 400);
59:             BL_CTRLv12 = new I2CDevice(BL_CTRLv12Config);
60:         }
61: 
62:         private int WriteBL_CTRLv12Speed(Byte MostSignificantByte, Byte LeastSignificantByte)
63:         {
64:             int bytesTransfered = 0;
65:             Byte[] SendBytes;
66:             xActions = new I2CDevice.I2CTransaction[1];
67:             SendBytes = new byte[2] { MostSignificantByte, LeastSignificantByte };
68:             xActions[0] = I2CDevice.CreateWriteTransaction(SendBytes);
69:             bytesTransfered = BL_CTRLv12.Execute(xActions, 1000);
70:             return bytesTransfered;
71:         }
72:         #endregion
73: 
74:         public enum Motor
75:         {
76:             Left,
77:             Right,
78:             Rear
79:         }
80:     }
81: }
Let me know what you think!  

No comments:

Post a Comment