I have a software question based robotics question.
I know very little about Ardunio and the coding for it. I have written some of the code that I require but I am now stuck at the Arduino Sketch. There is two motors, a left and right motor which their speeds are defined as "a" and "b" respectivly. All I know is that I have to use the analogWrite() command to get this to work with values between 0 and 255. I have converted all values to work with this (ie. values between 0 - 255).
This is what I have so far:
[code]
/*
* Robot Motor Controller script with PWM speed control
*/
//---------------------- Motors
int motorL[] = {6, 7}
int motorR[] = {8, 9}
int ledPin = 13;
if y > 0:
digitalWrite(motorL[0], HIGH);
digitalWrite(motorL[1], LOW);
digitalWrite(motorR[0], HIGH);
digitalWrite(motorR[1], LOW);
analogWrite(9, motor_a);
analogWrite(6, motor_b);
if y < 0:
digitalWrite(motorL[0], LOW);
digitalWrite(motorL[1], HIGH);
digitalWrite(motorR[0], LOW);
digitalWrite(motorR[1], HIGH);
analogWrite(9, motor_a);
analogWrite(6, motor_b);
[/code]
Can someone please fix any Syntex errors and other errors that may be present in my code please. I would really like this project to work as it is the most complicated I have tried with the Raspberry Pi.
What I need this to do is:
- decide whether the motor is going forwards or backwards
- (Based on the above) set the pins for that direction
- Interpit the values that are given to it from the TCP server.
- loop back continuly until the program is terminaled.
Any help will be appreciated.
For anyone who wants to know how the motors are controlled read on...
I will be controlling the robot by using a joystick on a remote computer using the pygame module. The code for the below is below:
import pygame
[code]Removed By Request[/code]
So far, I have a TCP server and client working but I have not incorporated it in this script yet.
I only want help on the Arduino Sketch. The Joystick control and TCP are working nicely but the Arduino code is not working (as seen above).
Any help would be appreciated.