Compare commits
No commits in common. "d6a82dafd883b81c5f6760a341bff91e683ac7d7" and "711e86f918a22db8ab08736b6be85f8e0b575eaa" have entirely different histories.
d6a82dafd8
...
711e86f918
4 changed files with 29 additions and 113 deletions
|
@ -121,21 +121,27 @@ bool PixelBot::Connect()
|
|||
void PixelBot::Listen()
|
||||
{
|
||||
while(true) {
|
||||
Serial.println("[PixelBot/Server] Entering main loop.");
|
||||
|
||||
// Make sure that there's something to read
|
||||
if(tcpClient.available() == 0) {
|
||||
delay(10); // sleep for 10ms
|
||||
continue;
|
||||
}
|
||||
|
||||
String nextLine = tcpClient.readStringUntil('\n');
|
||||
Serial.print(" > "); Serial.println(nextLine);
|
||||
|
||||
|
||||
if(!Tick()) {
|
||||
Serial.println("[PixelBot/Server] Exiting main loop.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PixelBot::Tick()
|
||||
{
|
||||
// Make sure that there's something to read
|
||||
if(tcpClient.available() == 0) {
|
||||
delay(10);
|
||||
return true;
|
||||
}
|
||||
|
||||
String nextLine = tcpClient.readStringUntil('\n');
|
||||
Serial.print(" > "); Serial.println(nextLine);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PixelBot::processCommand(String command)
|
||||
{
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#include "PixelBotController.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
PixelBotController::PixelBotController()
|
||||
{
|
||||
|
||||
|
@ -12,54 +10,3 @@ PixelBotController::~PixelBotController()
|
|||
|
||||
}
|
||||
|
||||
unsigned long PixelBotController::GetTicksTravelled()
|
||||
{
|
||||
return ticksTravelled;
|
||||
}
|
||||
|
||||
void PixelBotController::MoveDistance(int direction, int ticks)
|
||||
{
|
||||
for(int i = 0; i < ticks; i++) {
|
||||
MoveTick(direction);
|
||||
delay(tickDelay);
|
||||
}
|
||||
}
|
||||
|
||||
void PixelBotController::MoveTick(int direction)
|
||||
{
|
||||
for(int i = 0; i < 8; i++)
|
||||
{
|
||||
switch(direction) {
|
||||
case STOP:
|
||||
return;
|
||||
case FORWARD:
|
||||
setOutputDir(i,7-i);
|
||||
break;
|
||||
case BACK:
|
||||
setOutputDir(7-i,i);
|
||||
break;
|
||||
case LEFT:
|
||||
setOutputDir(7-i,7-i);
|
||||
break;
|
||||
case RIGHT:
|
||||
setOutputDir(i,i);
|
||||
break;
|
||||
}
|
||||
delayMicroseconds(motorSpeed);
|
||||
}
|
||||
ticksTravelled++;
|
||||
}
|
||||
|
||||
void PixelBotController::sendTickPart(int leftCode, int rightCode)
|
||||
{
|
||||
digitalWrite(lmotorPin1, bitRead(motorLookup[leftCode], 0));
|
||||
digitalWrite(lmotorPin2, bitRead(motorLookup[leftCode], 1));
|
||||
digitalWrite(lmotorPin3, bitRead(motorLookup[leftCode], 2));
|
||||
digitalWrite(lmotorPin4, bitRead(motorLookup[leftCode], 3));
|
||||
|
||||
digitalWrite(rmotorPin1, bitRead(motorLookup[rightCode], 0));
|
||||
digitalWrite(rmotorPin2, bitRead(motorLookup[rightCode], 1));
|
||||
digitalWrite(rmotorPin3, bitRead(motorLookup[rightCode], 2));
|
||||
digitalWrite(rmotorPin4, bitRead(motorLookup[rightCode], 3));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Connects to a PixelHub server, receives commands, and acts upon them.
|
||||
/// </summmary>
|
||||
|
@ -9,34 +10,13 @@ public:
|
|||
PixelBotController();
|
||||
~PixelBotController();
|
||||
|
||||
static const int STOP = 0;
|
||||
static const int FORWARDS = 1;
|
||||
static const int BACKWARDS = 2;
|
||||
static const int LEFT = 3;
|
||||
static const int RIGHT = 4;
|
||||
|
||||
void MoveDistance(int direction, int ticks);
|
||||
void MoveTick(int direction);
|
||||
|
||||
unsigned long GetTicksTravelled();
|
||||
|
||||
private:
|
||||
const int rmotorPin1 = 16;
|
||||
const int rmotorPin2 = 5;
|
||||
const int rmotorPin3 = 4;
|
||||
const int rmotorPin4 = 0;
|
||||
int motorLookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
|
||||
|
||||
const int lmotorPin1 = 2;
|
||||
const int lmotorPin2 = 14;
|
||||
const int lmotorPin3 = 12;
|
||||
const int lmotorPin4 = 13;
|
||||
|
||||
int motorLookup[8] = { 0b01000, 0b01100, 0b00100, 0b00110, 0b00010, 0b00011, 0b00001, 0b01001 };
|
||||
|
||||
int motorSpeed = 1200; // The speed at which the stepper motor accepts bits
|
||||
unsigned long ticksTravelled = 0; // Number of steps travelled (including turns)
|
||||
int ticksPerRevolution = 512; // Number of steps per full revolution of the wheels
|
||||
int tickDelay = 1; // The delay in between ticks
|
||||
|
||||
void sendTickPart(int leftCode, int rightCode);
|
||||
int motorSpeed = 1200; //variable to set stepper speed
|
||||
int count = 0; // count of steps made
|
||||
int countsperrev = 512; // number of steps per full revolution
|
||||
};
|
||||
|
||||
|
|
19
README.md
19
README.md
|
@ -2,26 +2,9 @@
|
|||
|
||||
A combination of a C# server and an arduino program that allows the control of a Hull Pixelbot.
|
||||
|
||||
## PixelHub Cilent protocol
|
||||
The PixelHub client protocol is a (mostly) text-based protocol that the server uses to give the robot instructions. One instruction or message is passed per line (and line endings are '\n'). The message flow works something like this:
|
||||
|
||||
(todo: diagram here :D)
|
||||
|
||||
1. The server sends a command ot the robot
|
||||
2. The robot sends back to say whether it will/can execute the command
|
||||
3. The robot executes the command
|
||||
4. The robot messages back to say it's finished executing a given command.
|
||||
|
||||
|
||||
|
||||
## Split-brain robots
|
||||
If you have a split brain robot, the PixelHub client, while it doesn't support it yet, _can_ be adjusted to add support. Currently, all you need to do is swap out the `PixelHubController` .cpp file with one that can talk to your other microcontroller that actually controls the wheels.
|
||||
|
||||
## Credits
|
||||
- Debugging:
|
||||
- Andrew C, Karen van Eck, Mike C
|
||||
- Soldering:
|
||||
- Brian N
|
||||
|
||||
## Useful Links
|
||||
|
||||
|
@ -31,7 +14,7 @@ If you have a split brain robot, the PixelHub client, while it doesn't support i
|
|||
|
||||
### For Multicast networkinterface blog post
|
||||
- [NetworkInterface class](https://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface(v=vs.110).aspx)
|
||||
- [Stackoverflow answer](http://stackoverflow.com/questions/2192548/specifying-what-network-interface-an-udp-multicast-should-go-to-in-net)
|
||||
- [Sockoverflow answer](http://stackoverflow.com/questions/2192548/specifying-what-network-interface-an-udp-multicast-should-go-to-in-net)
|
||||
- [IPv4InterfaceProperties](https://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipv4interfaceproperties(v=vs.110).aspx)
|
||||
|
||||
### Bits and Bobs
|
||||
|
|
Reference in a new issue