Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
Ok so roborealm process vidoe information and send commands to the axon? Will it send the commands to drive and take information from the axon like sensor input. Im planing on useing it to build a pc based robot.
using System;using System.Threading;using System.IO.Ports; //Where you find SerialPortusing System.Collections.Generic;using System.Linq;using System.Text;namespace HandMainProgram{ class Program { static void Main(string[] args) { Console.WriteLine("Hit enter to start"); Console.ReadLine(); //Don't start immediately, as the Axon/Hand may not yet be powered //Prepare the serial port SerialPort serialPort1 = new SerialPort(); //Have to initialize on my own here serialPort1.BaudRate = 115200; serialPort1.DataBits = 8; serialPort1.Parity = Parity.None; serialPort1.StopBits = StopBits.One; serialPort1.PortName = "COM3"; //My COM port is COM3. Others may have different COM ports. //This just makes sure that no other program does something to break mine if (serialPort1.IsOpen) serialPort1.Close(); serialPort1.Open(); //Generate the command array Byte[] ST = new Byte[3]; int d = 0; ST[2] = 125; ST[1] = 0; ST[0] = 0; serialPort1.Write(ST, 0, 3); //send the whole array System.Threading.Thread.Sleep(2000); //Not strictly necessary, but if you want to send multiple //commands you might need to sleep Console.WriteLine("All commands were sent. Hit ENTER to close the program"); Console.ReadLine(); serialPort1.Close(); }[\code]
//These next two lines setthe UART transmit and receive buffer size.#define UART_TX_BUFFER_SIZE 80#define UART_RX_BUFFER_SIZE 80#include "sys/axon.h" //always needed#include "uart.h"#include "rprintf.h"#include "pwm.h"#include "pid.h"#include "a2d.h"#include "iopin.h"#include "Sensors/Encoder/Generic/quadrature.h" //the quadrature encoder //Make the encoderQUADRATURE quad1 = MAKE_GENERIC_QUADRATURE(K1,E3,false,1368,false); //reads from H3 and H4QUADRATURE quad2 = MAKE_GENERIC_QUADRATURE(K0,E2,false,1368,false); //the top motorPID bottomPID = MAKE_PID(2.5,0,1,0,-100,100); //bottom motor PIDPID topPID = MAKE_PID(2.0,0,1,0,-100,100); //top motor PIDPID forcePID = MAKE_PID(2.25,0,1,0,-100,100); //PID for the forces//So what the PID code does: MAKE_PID(KP,KI,KD,MAXINTEGRATE,outMin,outMax)/*Now, webbot works in a slightly odd way. There is no MAIN function,that is included in the library. So you have three functions youhave to have in your code. These are below.*/////This is called only once, and is used to set up any hardwarevoid appInitHardware(void){ //set UART1 to 115200 baud uartInit(UART1,115200); //tell rprintf to output to UART1 rprintfInit(&uart1SendByte); //initialize encoderInit(quad1); encoderInit(quad2); //I guess we initialize PWM here? pwmInitHertz(H6,1000,0,null); //bottom motor pwmInitHertz(H3,1000,0,null); //top motor//}//This is also called once. It is used to set any software variablesTICK_COUNT appInitSoftware(TICK_COUNT loopStart){ return 0; //we're not doing much right now}//This is called repeatedly, and it is the main function.TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){ float enc1 = 0.; //bottom motor float enc2 = 0.; //top motor int forPos = 0; //position is 0, force is 1 int reBy = -10; //the byte we're reading from the UART float instructions[3]; //the array of instructions (needs to be more general, but w/e) int count = 0; pin_make_output(H4,false); //top motor direction pin_make_output(H5,false); //bottom motor direction // //ultimately, if we read nothing from the UART, we do the actual code here if(uartReceiveBufferIsEmpty(UART1)) { //read the encoders encoderRead(quad1); encoderRead(quad2); //set the encoder stuff anyway. enc1 = pidSetActual(&bottomPID,quad1.encoder.value); enc2 = pidSetActual(&topPID,quad2.encoder.value); //for position control pin_low(H5); pin_low(H4); //check the force threshold if(a2dConvert8bit(3) > 75) forPos = 1; if(forPos == 1) { enc1 = pidSetActual(&forcePID,a2dConvert8bit(3)); enc2 = pidSetActual(&forcePID,a2dConvert8bit(3)); } if(enc1 < 0) { if(forPos == 0) { //we're doing position control pin_high(H5); enc1 = -enc1; } else { //For force control, the bottom PID cannot go negative enc1 = 0; } } if(enc2 < 0) { pin_high(H4); enc2 = -enc2; } pwmSetDutyCycle(H6,(int)enc1); //bottom motor pwmSetDutyCycle(H3,(int)enc2); //top motor } else //the UART has something to say { //Now it's time for PID set points reBy = uartGetByte(UART1); while(reBy >= 0) //don't forget that "=", or else you can't send a position of zero...apparently { instructions[count] = (float)reBy; count = count + 1; reBy = uartGetByte(UART1); } { pidSetTarget(&bottomPID,instructions[0]); //set the PID targets according to the message pidSetTarget(&topPID,instructions[1]); pidSetTarget(&forcePID,instructions[2]); } //flush the UART buffer uartFlushReceiveBuffer(UART1); } return 10000; //wait for n uS before calling again. //So the return statement is how you wait before it is called again.}[\code]