Attempting to make the Elegoo Smart Car 4.0 parametrically navigate, but I don't quite know how to go about it, so I was hoping for some ideas
what is it?
It's a little RC car that uses Arduino code, but I can't quite figure it out
which one?
Arduino Uno
cool. I have very many codes for UNO, do you want some?
Is it all built and tested with supplied code??
I built one last week, was a FreeNove 4WD based on ESP32..
Really just wanted some to test with..
I tied it into my nard server and controlled it using a tablet, was quite surprised that it actually worked quite well..
Need to add a separate cam to the bot though as pulling a live stream and trying to drive at the same time has issues..
fun though, want to build to another, see how many i can control at once..
If you stuck on something, post up some code using codeblocks.
have fun.. ~q
Yeah, the code that was supplied was good, it works well, I just need to figure out how to make it navigate to a point on it's own
I think this would be the code that makes it move
if (controlED == control_enable) //Enable motot control?
{
digitalWrite(PIN_Motor_STBY, HIGH);
{ //A...Right
switch (direction_A) //movement direction control
{
case direction_just:
digitalWrite(PIN_Motor_AIN_1, HIGH);
analogWrite(PIN_Motor_PWMA, speed_A);
break;
case direction_back:
digitalWrite(PIN_Motor_AIN_1, LOW);
analogWrite(PIN_Motor_PWMA, speed_A);
break;
case direction_void:
analogWrite(PIN_Motor_PWMA, 0);
digitalWrite(PIN_Motor_STBY, LOW);
break;
default:
analogWrite(PIN_Motor_PWMA, 0);
digitalWrite(PIN_Motor_STBY, LOW);
break;
}
}
{ //B...Left
switch (direction_B)
{
case direction_just:
digitalWrite(PIN_Motor_BIN_1, HIGH);
analogWrite(PIN_Motor_PWMB, speed_B);
break;
case direction_back:
digitalWrite(PIN_Motor_BIN_1, LOW);
analogWrite(PIN_Motor_PWMB, speed_B);
break;
case direction_void:
analogWrite(PIN_Motor_PWMB, 0);
digitalWrite(PIN_Motor_STBY, LOW);
break;
default:
analogWrite(PIN_Motor_PWMB, 0);
digitalWrite(PIN_Motor_STBY, LOW);
break;
}
}
}
else
{
digitalWrite(PIN_Motor_STBY, LOW);
return;
}
Looks like it, put the whole sketch up..
looks like direction_void is stop and default is stop..
strange case names direction_just, means just what??
mine was easier to understand..
case CMD_MOTOR:{ //Serial.println("SetParams: Motor");
Car_SetMode(0);
if (p1 == 0 && p3 == 0)
Motor_Move(0, 0, 0, 0);//Stop the car
else //If the parameters are not equal to 0
Motor_Move(p1, p1, p3, p3);
result = true;
break;
}
just Motor_Move 4 params is the speed and direction..
how many motors does your bot have??
i got 4, hence the 4 params..
~q
Mine has 4 as well, and I don't quite know what some of the names mean, it's just what came with the default. Which line did you find that code under?
Line 142 in NardBot.ino
Like I said mine was a bit easier to understand..
Put the whole sketch up and I'll take a look at it..
~q
Here's the whole sketch, found under device driver set
#include "DeviceDriverSet_xxx0.h"
//#include "PinChangeInt.h"
#include <avr/wdt.h>
static void
delay_xxx(uint16_t _ms)
{
wdt_reset();
for (unsigned long i = 0; i < _ms; i++)
{
delay(1);
}
}
/*RBG LED*/
static uint32_t Color(uint8_t r, uint8_t g, uint8_t b)
{
return (((uint32_t)r << 16) | ((uint32_t)g << 8) | b);
}
void DeviceDriverSet_RBGLED::DeviceDriverSet_RBGLED_xxx(uint16_t Duration, uint8_t Traversal_Number, CRGB colour)
{
if (NUM_LEDS < Traversal_Number)
{
Traversal_Number = NUM_LEDS;
}
for (int Number = 0; Number < Traversal_Number; Number++)
{
leds[Number] = colour;
FastLED.show();
delay_xxx(Duration);
}
}
void DeviceDriverSet_RBGLED::DeviceDriverSet_RBGLED_Init(uint8_t set_Brightness)
{
FastLED.addLeds<NEOPIXEL, PIN_RBGLED>(leds, NUM_LEDS);
FastLED.setBrightness(set_Brightness);
}
#if _Test_DeviceDriverSet
void DeviceDriverSet_RBGLED::DeviceDriverSet_RBGLED_Test(void)
{
leds[0] = CRGB::White;
FastLED.show();
delay_xxx(50);
leds[1] = CRGB::Red;
FastLED.show();
delay_xxx(50);
DeviceDriverSet_RBGLED_xxx(50 /*Duration*/, 5 /*Traversal_Number*/, CRGB::Black);
}
#endif
void DeviceDriverSet_RBGLED::DeviceDriverSet_RBGLED_Color(uint8_t LED_s, uint8_t r, uint8_t g, uint8_t b)
{
if (LED_s > NUM_LEDS)
return;
if (LED_s == NUM_LEDS)
{
FastLED.showColor(Color(r, g, b));
}
else
{
leds[LED_s] = Color(r, g, b);
}
FastLED.show();
}
/*Key*/
uint8_t DeviceDriverSet_Key::keyValue = 0;
static void attachPinChangeInterrupt_GetKeyValue(void)
{
DeviceDriverSet_Key Key;
static uint32_t keyValue_time = 0;
static uint8_t keyValue_temp = 0;
if ((millis() - keyValue_time) > 500)
{
keyValue_temp++;
keyValue_time = millis();
if (keyValue_temp > keyValue_Max)
{
keyValue_temp = 0;
}
Key.keyValue = keyValue_temp;
}
}
void DeviceDriverSet_Key::DeviceDriverSet_Key_Init(void)
{
pinMode(PIN_Key, INPUT_PULLUP);
//attachPinChangeInterrupt(PIN_Key, attachPinChangeInterrupt_GetKeyValue, FALLING);
attachInterrupt(0, attachPinChangeInterrupt_GetKeyValue, FALLING);
}
#if _Test_DeviceDriverSet
void DeviceDriverSet_Key::DeviceDriverSet_Key_Test(void)
{
Serial.println(DeviceDriverSet_Key::keyValue);
}
#endif
void DeviceDriverSet_Key::DeviceDriverSet_key_Get(uint8_t *get_keyValue)
{
*get_keyValue = keyValue;
}
/*ITR20001 Detection*/
bool DeviceDriverSet_ITR20001::DeviceDriverSet_ITR20001_Init(void)
{
pinMode(PIN_ITR20001xxxL, INPUT);
pinMode(PIN_ITR20001xxxM, INPUT);
pinMode(PIN_ITR20001xxxR, INPUT);
return false;
}
int DeviceDriverSet_ITR20001::DeviceDriverSet_ITR20001_getAnaloguexxx_L(void)
{
return analogRead(PIN_ITR20001xxxL);
}
int DeviceDriverSet_ITR20001::DeviceDriverSet_ITR20001_getAnaloguexxx_M(void)
{
return analogRead(PIN_ITR20001xxxM);
}
int DeviceDriverSet_ITR20001::DeviceDriverSet_ITR20001_getAnaloguexxx_R(void)
{
return analogRead(PIN_ITR20001xxxR);
}
#if _Test_DeviceDriverSet
void DeviceDriverSet_ITR20001::DeviceDriverSet_ITR20001_Test(void)
{
Serial.print("\tL=");
Serial.print(analogRead(PIN_ITR20001xxxL));
Serial.print("\tM=");
Serial.print(analogRead(PIN_ITR20001xxxM));
Serial.print("\tR=");
Serial.println(analogRead(PIN_ITR20001xxxR));
}
#endif
/*Voltage Detection*/
void DeviceDriverSet_Voltage::DeviceDriverSet_Voltage_Init(void)
{
pinMode(PIN_Voltage, INPUT);
//analogReference(INTERNAL);
}
float DeviceDriverSet_Voltage::DeviceDriverSet_Voltage_getAnalogue(void)
{
//float Voltage = ((analogRead(PIN_Voltage) * 5.00 / 1024) * 7.67); //7.66666=((10 + 1.50) / 1.50)
float Voltage = (analogRead(PIN_Voltage) * 0.0375);
Voltage = Voltage + (Voltage * 0.08); //Compensation 8%
//return (analogRead(PIN_Voltage) * 5.00 / 1024) * ((10 + 1.50) / 1.50); //Read voltage value
return Voltage;
}
#if _Test_DeviceDriverSet
void DeviceDriverSet_Voltage::DeviceDriverSet_Voltage_Test(void)
{
//float Voltage = ((analogRead(PIN_Voltage) * 5.00 / 1024) * 7.67); //7.66666=((10 + 1.50) / 1.50)
float Voltage = (analogRead(PIN_Voltage) * 0.0375); //7.66666=((10 + 1.50) / 1.50)
Voltage = Voltage + (Voltage * 0.08); //Compensation 8%
//Serial.println(analogRead(PIN_Voltage) * 4.97 / 1024);
Serial.println(Voltage);
}
#endif
/*Motor control*/
void DeviceDriverSet_Motor::DeviceDriverSet_Motor_Init(void)
{
pinMode(PIN_Motor_PWMA, OUTPUT);
pinMode(PIN_Motor_PWMB, OUTPUT);
pinMode(PIN_Motor_AIN_1, OUTPUT);
pinMode(PIN_Motor_BIN_1, OUTPUT);
pinMode(PIN_Motor_STBY, OUTPUT);
}
#if _Test_DeviceDriverSet
void DeviceDriverSet_Motor::DeviceDriverSet_Motor_Test(void)
{
//A...Right
//B...Left
digitalWrite(PIN_Motor_STBY, HIGH);
digitalWrite(PIN_Motor_AIN_1, HIGH);
analogWrite(PIN_Motor_PWMA, 100);
digitalWrite(PIN_Motor_BIN_1, HIGH);
analogWrite(PIN_Motor_PWMB, 100);
delay_xxx(1000);
digitalWrite(PIN_Motor_STBY, LOW);
delay_xxx(1000);
digitalWrite(PIN_Motor_STBY, HIGH);
digitalWrite(PIN_Motor_AIN_1, LOW);
analogWrite(PIN_Motor_PWMA, 100);
digitalWrite(PIN_Motor_BIN_1, LOW);
analogWrite(PIN_Motor_PWMB, 100);
delay_xxx(1000);
}
#endif
/*
Motor_control:AB / movement direction and speed
*/
void DeviceDriverSet_Motor::DeviceDriverSet_Motor_control(boolean direction_A, uint8_t speed_A, //Group A motor parameters
boolean direction_B, uint8_t speed_B, //Group B motor parameters
boolean controlED //AB enable setting (true)
) //Motor control
{
if (controlED == control_enable) //Enable motot control?
{
digitalWrite(PIN_Motor_STBY, HIGH);
{ //A...Right
switch (direction_A) //movement direction control
{
case direction_just:
digitalWrite(PIN_Motor_AIN_1, HIGH);
analogWrite(PIN_Motor_PWMA, speed_A);
break;
case direction_back:
digitalWrite(PIN_Motor_AIN_1, LOW);
analogWrite(PIN_Motor_PWMA, speed_A);
break;
case direction_void:
analogWrite(PIN_Motor_PWMA, 0);
digitalWrite(PIN_Motor_STBY, LOW);
break;
default:
analogWrite(PIN_Motor_PWMA, 0);
digitalWrite(PIN_Motor_STBY, LOW);
break;
}
}
{ //B...Left
switch (direction_B)
{
case direction_just:
digitalWrite(PIN_Motor_BIN_1, HIGH);
analogWrite(PIN_Motor_PWMB, speed_B);
break;
case direction_back:
digitalWrite(PIN_Motor_BIN_1, LOW);
analogWrite(PIN_Motor_PWMB, speed_B);
break;
case direction_void:
analogWrite(PIN_Motor_PWMB, 0);
digitalWrite(PIN_Motor_STBY, LOW);
break;
default:
analogWrite(PIN_Motor_PWMB, 0);
digitalWrite(PIN_Motor_STBY, LOW);
break;
}
}
}
else
{
digitalWrite(PIN_Motor_STBY, LOW);
return;
}
}
/*ULTRASONIC*/
//#include <NewPing.h>
// NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void DeviceDriverSet_ULTRASONIC::DeviceDriverSet_ULTRASONIC_Init(void)
{
pinMode(ECHO_PIN, INPUT); //Ultrasonic module initialization
pinMode(TRIG_PIN, OUTPUT);
}
void DeviceDriverSet_ULTRASONIC::DeviceDriverSet_ULTRASONIC_Get(uint16_t *ULTRASONIC_Get /*out*/)
{
unsigned int tempda_x = 0;
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
tempda_x = ((unsigned int)pulseIn(ECHO_PIN, HIGH) / 58);
// *ULTRASONIC_Get = tempda_x;
if (tempda_x > 150)
{
*ULTRASONIC_Get = 150;
}
else
{
*ULTRASONIC_Get = tempda_x;
}
// sonar.ping() / US_ROUNDTRIP_CM; // Send ping, get ping time in microseconds (uS).
}
#if _Test_DeviceDriverSet
void DeviceDriverSet_ULTRASONIC::DeviceDriverSet_ULTRASONIC_Test(void)
{
unsigned int tempda = 0;
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
tempda = ((unsigned int)pulseIn(ECHO_PIN, HIGH) / 58);
// if (tempda_x > 50)
// {
// tempda_x = 50;
// }
// // return tempda;
// return tempda_x;
Serial.print("ULTRASONIC=");
Serial.print(tempda); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
Serial.println("cm");
}
#endif
/*Servo*/
Servo myservo; // create servo object to control a servo
void DeviceDriverSet_Servo::DeviceDriverSet_Servo_Init(unsigned int Position_angle)
{
myservo.attach(PIN_Servo_z, 500, 2400); //500: 0 degree 2400: 180 degree
myservo.attach(PIN_Servo_z);
myservo.write(Position_angle); //sets the servo position according to the 90(middle)
delay_xxx(500);
myservo.attach(PIN_Servo_y, 500, 2400); //500: 0 degree 2400: 180 degree
myservo.attach(PIN_Servo_y);
myservo.write(Position_angle); //sets the servo position according to the 90(middle)
delay_xxx(500);
myservo.detach();
}
#if _Test_DeviceDriverSet
void DeviceDriverSet_Servo::DeviceDriverSet_Servo_Test(void)
{
for (;;)
{
myservo.attach(PIN_Servo_z);
myservo.write(180);
delay_xxx(500);
myservo.write(0);
delay_xxx(500);
}
// for (uint8_t i = 0; i < 6; i++)
// {
// myservo.write(30 * i);
// delay(500);
// }
// for (uint8_t i = 6; i > 0; i--)
// {
// myservo.write(30 * i);
// delay(500);
// }
// myservo.attach(PIN_Servo_y);
// for (uint8_t i = 0; i < 6; i++)
// {
// myservo.write(30 * i);
// delay(500);
// }
// for (uint8_t i = 6; i > 0; i--)
// {
// myservo.write(30 * i);
// delay(500);
// }
}
#endif
/*0.17sec/60degree(4.8v)*/
void DeviceDriverSet_Servo::DeviceDriverSet_Servo_control(unsigned int Position_angle)
{
myservo.attach(PIN_Servo_z);
myservo.write(Position_angle);
delay_xxx(450);
myservo.detach();
}
//Servo motor control:Servo motor number and position angle
void DeviceDriverSet_Servo::DeviceDriverSet_Servo_controls(uint8_t Servo, unsigned int Position_angle)
{
if (Servo == 1 || Servo == 3) //Servo_z
{
if (Position_angle <= 1) //minimum angle control
{
Position_angle = 1;
}
if (Position_angle >= 17) //maximum angle control
{
Position_angle = 17;
}
myservo.attach(PIN_Servo_z);
myservo.write(10 * Position_angle);
delay_xxx(500);
}
if (Servo == 2 || Servo == 3) //Servo_y
{
if (Position_angle <= 3) //minimum angle control
{
Position_angle = 3;
}
if (Position_angle >= 11) //maximum angle control
{
Position_angle = 11;
}
myservo.attach(PIN_Servo_y);
myservo.write(10 * Position_angle);
delay_xxx(500);
}
myservo.detach();
}
/*IRrecv*/
IRrecv irrecv(RECV_PIN); // Create an infrared receive drive object
decode_results results; // Create decoding object
void DeviceDriverSet_IRrecv::DeviceDriverSet_IRrecv_Init(void)
{
irrecv.enableIRIn(); //Enable infrared communication NEC
}
bool DeviceDriverSet_IRrecv::DeviceDriverSet_IRrecv_Get(uint8_t *IRrecv_Get /*out*/)
{
if (irrecv.decode(&results))
{
IR_PreMillis = millis();
switch (results.value)
{
case /* constant-expression */ aRECV_upper:
case /* constant-expression */ bRECV_upper:
/* code */ *IRrecv_Get = 1;
break;
case /* constant-expression */ aRECV_lower:
case /* constant-expression */ bRECV_lower:
/* code */ *IRrecv_Get = 2;
break;
case /* constant-expression */ aRECV_Left:
case /* constant-expression */ bRECV_Left:
/* code */ *IRrecv_Get = 3;
break;
case /* constant-expression */ aRECV_right:
case /* constant-expression */ bRECV_right:
/* code */ *IRrecv_Get = 4;
break;
case /* constant-expression */ aRECV_ok:
case /* constant-expression */ bRECV_ok:
/* code */ *IRrecv_Get = 5;
break;
case /* constant-expression */ aRECV_1:
case /* constant-expression */ bRECV_1:
/* code */ *IRrecv_Get = 6;
break;
case /* constant-expression */ aRECV_2:
case /* constant-expression */ bRECV_2:
/* code */ *IRrecv_Get = 7;
break;
case /* constant-expression */ aRECV_3:
case /* constant-expression */ bRECV_3:
/* code */ *IRrecv_Get = 8;
break;
case /* constant-expression */ aRECV_4:
case /* constant-expression */ bRECV_4:
/* code */ *IRrecv_Get = 9;
break;
case /* constant-expression */ aRECV_5:
case /* constant-expression */ bRECV_5:
/* code */ *IRrecv_Get = 10;
break;
case /* constant-expression */ aRECV_6:
case /* constant-expression */ bRECV_6:
/* code */ *IRrecv_Get = 11;
break;
case /* constant-expression */ aRECV_7:
case /* constant-expression */ bRECV_7:
/* code */ *IRrecv_Get = 12;
break;
case /* constant-expression */ aRECV_8:
case /* constant-expression */ bRECV_8:
/* code */ *IRrecv_Get = 13;
break;
case /* constant-expression */ aRECV_9:
case /* constant-expression */ bRECV_9:
/* code */ *IRrecv_Get = 14;
break;
default:
// *IRrecv_Get = 5;
irrecv.resume();
return false;
break;
}
irrecv.resume();
return true;
}
else
{
return false;
}
}
#if _Test_DeviceDriverSet
void DeviceDriverSet_IRrecv::DeviceDriverSet_IRrecv_Test(void)
{
if (irrecv.decode(&results))
{
Serial.print("IRrecv_Test:");
Serial.println(results.value);
irrecv.resume();
}
}
#endif
where's the colors, will they come back after i drink me coffee??
the above function is the one you're after..
these are #define 's look in the .h file see if they're in there, being bools just 2 possible values 0 and 1, bit of experimenting and you should discover direction..
you don't have separate motor control, looks like they grouped each side, which is actually fine..
lol, funny, triple x delay??
maybe I don't want to know what it's doing..
maybe start by making a function that calls Motor_control and discover how it works..
then expand it..
have fun.. ~q
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.