public static void PinConfig() { BBBPinManager.AddBusCAN(0); //BBBPinManager.AddMappingUART(Pins.MTK3339_RX); //BBBPinManager.AddMappingUART(Pins.MTK3339_TX); //BBBPinManager.AddMappingsI2C(Pins.BNO055_SCL, Pins.BNO055_SDA); //BBBPinManager.AddMappingGPIO(Pins.SteeringLimitSwitch, false, Scarlet.IO.ResistorState.PULL_UP, true); //BBBPinManager.AddMappingPWM(Pins.SteeringMotor); //BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.NO_CHANGES); BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_IF_NONE); }
public static void Main(string[] args) { Telemetry = new Dictionary <Device, JointTelemetry> { { Device.BASE, new JointTelemetry() }, { Device.SHOULDER, new JointTelemetry() }, { Device.ELBOW, new JointTelemetry() }, { Device.WRIST, new JointTelemetry() }, { Device.DIFFERENTIAL_1, new JointTelemetry() }, { Device.DIFFERENTIAL_2, new JointTelemetry() }, { Device.HAND, new JointTelemetry() } }; Log.Begin(); Log.Output(Log.Severity.INFO, Log.Source.ALL, "Initializing CAN Bus..."); BeagleBone.Initialize(SystemMode.NO_HDMI, true); BBBPinManager.AddBusCAN(0, false); BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_IF_NONE); Log.Output(Log.Severity.INFO, Log.Source.ALL, "CAN Initialized."); Client.Start(ServerIP, TCPPort, UDPPort, "ArmTestClient"); Arm arm = new Arm(CANBBB.CANBus0); Parsing.Start(arm); while (ENABLED) { ArmPacket?next = arm.ReadNext(); if (next != null) { UpdateTelemetry((ArmPacket)next); } SendTelemetry(); Thread.Sleep(Constants.DEFAULT_MIN_THREAD_SLEEP); } }
static void Main(string[] args) { StateStore.Start("CanTester"); BeagleBone.Initialize(SystemMode.NO_HDMI, true); BBBPinManager.AddBusCAN(0, false); BBBPinManager.ApplyPinSettings(BBBPinManager.ApplicationMode.APPLY_IF_NONE); bool Priority = false; byte Sender = 0; byte Receiver = 0; byte DataID = 0; bool continuez = true; UInt16 Val1 = 0; UInt16 Val2 = 0; byte Speed = 0; byte Direction = 0; byte Mode = 0; Console.WriteLine("CAN TESTER TOOL"); while (continuez) { Console.Write("Write Mode(true) or Read Mode(false)? (true/false): "); bool Write = oldNew(Console.ReadLine(), true); if (Write) // Write Mode { Console.Write("Enter Priority (true/false) [Previous " + Priority + " ]: "); Priority = oldNew(Console.ReadLine(), Priority); Console.Write("Enter Sender (byte) [Previous " + Sender + "]: "); Sender = oldNewHex(Console.ReadLine(), Sender); Console.Write("Enter Reciever (byte) [Previous " + Receiver + "]: "); Receiver = oldNewHex(Console.ReadLine(), Receiver); Console.Write("Enter DataID (byte) [Previous " + DataID + "]: "); DataID = oldNew(Console.ReadLine(), DataID); switch (DataID) { case 0x0: Console.Write("Enter in mode [Previous " + Mode + "]: "); Mode = oldNew(Console.ReadLine(), Mode); break; case 0x2: Console.Write("Enter in speed [Previous " + Speed + "]: "); Speed = oldNew(Console.ReadLine(), Speed); Console.Write("Enter in direction (1 or 0) [Previous " + Direction + "]: "); Direction = oldNew(Console.ReadLine(), Direction); break; case 0x4: case 0xA: case 0xC: case 0xE: case 0x14: case 0x18: Console.Write("Enter in first value [Previous " + Val1 + "]: "); Val1 = oldNew(Console.ReadLine(), Val1); Console.Write("Enter in second value [Previous " + Val2 + "]: "); Val2 = oldNew(Console.ReadLine(), Val2); break; case 0x16: break; default: Console.WriteLine("Unknown or unsupported data value"); break; } bool keepSending = true; while (keepSending) { switch (DataID) { case 0x0: ModeSelect(CANBBB.CANBus0, Priority, Sender, Receiver, Mode); break; case 0x2: SpeedDir(CANBBB.CANBus0, Priority, Sender, Receiver, Speed, Direction); break; case 0x4: case 0xA: case 0xC: case 0xE: case 0x14: case 0x18: TwoData(CANBBB.CANBus0, Priority, Sender, Receiver, DataID, Val1, Val2); break; case 0x10: ModelReq(CANBBB.CANBus0, Priority, Sender, Receiver); break; default: Console.WriteLine("Unknown or unsupported data value"); break; } Console.Write("Data Sent. Hold enter to continue sending (true/false): "); try { keepSending = oldNew(Console.ReadLine(), true); } catch { if (DataID == 2) { Console.WriteLine("Speed set to zero"); SpeedDir(CANBBB.CANBus0, Priority, Sender, Receiver, 0, Direction); keepSending = false; } } } } else // Read Mode { bool reading = true; while (reading) { int count = 0; Task <Tuple <uint, byte[]> > CanRead = CANBBB.CANBus0.ReadAsync(); while (!CanRead.IsCompleted || (count > 10)) { CanRead.Wait(1000); count++; } if (CanRead.IsCompleted) { Tuple <uint, byte[]> temp = CanRead.Result; byte priority = Convert.ToByte(((temp.Item1) >> 0b1111111111) & 0x1F); byte sender = Convert.ToByte(((temp.Item1) >> 0x1F) & 0x1F); byte receiver = Convert.ToByte((temp.Item1) & 0x1F); Console.WriteLine("ID: " + Convert.ToString(temp.Item1, 2)); //Console.WriteLine("ID: " + priority + " " + sender + " " + receiver); Console.WriteLine("Data: {0}", string.Join(", ", temp.Item2.Select(v => v.ToString())) ); } else { Console.WriteLine("TIMEOUT, No CANID found"); } Console.Write("Continue read?"); reading = oldNew(Console.ReadLine(), true); } } Console.Write("Continue Program (true) or exit (false): "); continuez = oldNew(Console.ReadLine(), true); } }