Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1/3 Scale Car - write firmware for motors #11

Open
jruths opened this issue Aug 26, 2024 · 9 comments
Open

1/3 Scale Car - write firmware for motors #11

jruths opened this issue Aug 26, 2024 · 9 comments
Assignees

Comments

@jruths
Copy link
Contributor

jruths commented Aug 26, 2024

Two identical motors are used to steer and apply the brake on the 1/3 scale car. There is an arduino that needs to be programmed with the logic to turn the motors to achieve these goals. Basic motor control has been tested, but now we need code that turns the motor to apply the brake to a set "value" (0-1) and code that turns the motor to steer the vehicle to a desired turn angle (-X degrees to X degrees).

@jruths jruths converted this from a draft issue Aug 26, 2024
@5408Andy 5408Andy self-assigned this Aug 27, 2024
@Shelleynguy
Copy link

Status: In progress-Researching on the docyke servo motor and how to program it to an arduino
Next Steps: begin the code to turn the servo motor and make a prototype to test the angle of the steering.
Projected Completion: September 21st
Update: First I wanted what a servo motor does and uses, so I began looking at the documentations of the docyke servo motor such as the max torque, PWM, and angles. I created a google doc to help me follow along the features of the servo motor. And then I looked up how to connect and program a servo motor to an arduino such as how to set an angle of a servo motor and changing it by possibly using for-loops. I wanted to test a mini one just in case to help me visually see the steering.

@SHSL-TemiOjumu SHSL-TemiOjumu moved this from ✏️ Todo to 🛠️ In-Progress in 🚗 Hail Bopp Sep 10, 2024
@SHSL-TemiOjumu SHSL-TemiOjumu moved this from 🛠️ In-Progress to ✏️ Todo in 🚗 Hail Bopp Sep 10, 2024
@SHSL-TemiOjumu
Copy link

09/09/2024 Update:

  • Status: Researching servo motors with Arduino and prior data
  • Next Steps: Implement a way to configure the Arduino for the brakes
  • Projected Completion: 09/21
  • Update: We've been looking at what past team members have done for the 1/3 scale car and are trying to catch up on that. We received a link to an Arduino doc to help us understand how to configure the servo motor needed for control
    of the brake and steering. I also researched documentation of the docyke motor to better understand what it does and how it is used.

@github-project-automation github-project-automation bot moved this from ✏️ Todo to ✅ Done in 🚗 Hail Bopp Sep 10, 2024
@SHSL-TemiOjumu SHSL-TemiOjumu moved this from ✅ Done to 🛠️ In-Progress in 🚗 Hail Bopp Sep 10, 2024
@SHSL-TemiOjumu
Copy link

09/16/2024 Update:

  • Status: Working on code for braking and steering
  • Next Steps: Modify code for actual docyke servo motors
  • Projected Completion: 09/21
  • Update: We programmed a working code for a mini servo motor to move at certain angles we specify it to (simulated on Wokwi). We need to modify the code a bit to fit with the actual servo motor on the 1/3 scale car, as it has different angle limitations.

@Shelleynguy
Copy link

  • Status: Coding in Arduino and testing them out in online simulators
  • Next Steps: get help on how to test it and connect on actual servo motor and into IDE
  • Projected Completion: Extended to maybe towards very end of September
  • Update: We worked on the separate codes in Arduino for both steering and braking and ran it a couple of times on online simulators. A problem we ran into is that the servo motors only went up to 180 degrees instead of the 360 degrees that the docyke motor goes up too.

@jruths
Copy link
Contributor Author

jruths commented Sep 20, 2024

Just some thoughts to answer your questions here:

  • Most likely this will be two separate files for steering and brake, but I think it would make sense to make a common program/function that will receive a command angle and turn the motor to achieve that angle. The the separate files would have some slightly more specialized code can call that function after preprocessing the reference signal sent as either a brake or steering command.
  • The ROS Navigator stack (what is running on the main computer) will generate brake and steering commands. There will be a ROS node (a different task to make this) to receive those messages and send them to the arduino controller over USB. The simplest way to communicate the desired brake amount is to provide a number between 0 (no braking) and 1 (full braking). So Navigator will send this value between 0 and 1, and then the new node will pass that "reference" value to your program. Your program will then execute this value into the motor. For the brake, 0 means no rotation, so the brake line is slack, and 1 means to rotate the motor to the farthest angle it can (the same amount as depressing the brake pedal completely). So say reference=0 corresponds to a rotation of 0 degrees and reference=1 corresponds to a rotation of 60 degrees. Then when you receive reference=1, you rotate the motor to 60 degrees to apply the brake completely. If the reference=0.5, then you would rotate the motor to 30 degrees.
  • Similarly the reference values for the steering will likely also be between -1 to 1, with -1 meaning full left turn and +1 meaning full right turn. A full turn on our full size car is about 24 degrees, I think, so in that case if the reference=-1, then you would rotate the motor to 24 degrees to turn the wheels all the way to the left. The reference=1 would mean that you rotate the motor to 24 degrees in the other direction.

@5408Andy 5408Andy removed their assignment Sep 23, 2024
@Shelleynguy
Copy link

Status: Got the servo motor to work in Arduino IDE by using the map function to map different reference values for both brake and steering
Next Steps: need someone to double check code and implement into actual servo motor
Projected Completion: hopefully soon
Update: This week I was able to get access to a prototype servo motor from the lap and was able to work with it. I have two separate codes for the steering and brake. I have the steering set to the default position as 90 degrees and maps the reference values of -1 and 1 to a full right and left turn.
I have a code for the brake where i test multiple of reference inputs (0.25, 0.5, 1) and they brake at different percentages.

@Shelleynguy
Copy link

Shelleynguy commented Oct 1, 2024

#include <Servo.h>

//CODE FOR STEERING
Servo myServo;
//int angle =0;

const int leftTurn = -24; //left angle
const int rightTurn = 24; //right angle
const int defaultPos = 90; //default pos, adjust if needed

void setup() {
// put your setup code here, to run once:
myServo.attach(9); // servo pin
myServo.write(defaultPos); //start at 90
delay(1000); // wait for the servo to reach the default position
}

void loop() {

float referenceVal = -1;

// map the reference value (-1) to the angle range (-24 to 24 degrees)
int angle = map(referenceVal * 100, -100, 100, leftTurn, rightTurn);

//Syntax of map function:
//map(value, fromLow, fromHigh, toLow, toHigh)
//value: the number to map.
//fromLow: the lower bound of the value’s current range.
//fromHigh: the upper bound of the value’s current range.
//toLow: the lower bound of the value’s target range.
//toHigh: the upper bound of the value’s target range.

// shift the servo to the calculated angle
myServo.write(defaultPos + angle);
delay(1000); // wait for a second or so before the next movement

myServo.write(defaultPos);
delay(1000); // wait for a second or so before the next movement

//map new input of 1
referenceVal = 1;
angle = map(referenceVal * 100, -100, 100, leftTurn, rightTurn);

// Move to the mapped angle (shifted by the default position)
myServo.write(defaultPos + angle); // move servo to the mapped angle
delay(1200); // wait for a second

// Return to the default position (90 degrees)
myServo.write(defaultPos); // go back to 90 degrees
delay(1200); // wait for a second

}

@Shelleynguy
Copy link

#include <Servo.h>

Servo brakeServo;
int servoPin = 9; // pin 9 where the servo is connected
int noBrake = 0;
int fullBrake = 60;

void setup() {

//Serial.begin(9600); //serial communicaiton from ROS

brakeServo.attach(servoPin);
brakeServo.write(noBrake); //initially ther is no braking which is 0 degrees
delay(1000);
}

void loop()
{

float referenceVal = 0.25;
int angle = map(referenceVal * 100, 0, 180, noBrake, fullBrake);

// shift the servo to the calculated angle
brakeServo.write(noBrake + angle);
delay(1000); // wait for a second or so before the next movement

brakeServo.write(noBrake); //go back to initial
delay(1000);

//try new input
referenceVal = 0.5;
angle = map(referenceVal * 100, 0, 180, noBrake, fullBrake);

// shift the servo to the calculated angle
brakeServo.write(noBrake + angle);
delay(1000); // wait for a second or so before the next movement

brakeServo.write(noBrake); //go back to initial
delay(1000);

//try new input
referenceVal = 1;
angle = map(referenceVal * 100, 0, 180, noBrake, fullBrake);

// shift the servo to the calculated angle
brakeServo.write(noBrake + angle);
delay(1000); // wait for a second or so before the next movement

brakeServo.write(noBrake); //go back to initial
delay(1000);

}

@Shelleynguy
Copy link

Status: in progress
Next Steps: recheck code to see if motor properly moves with the signal inputs with the serial monitor
Update: Temi and I worked on the code so that it can receive different sent inputs to the code so that the motor moves accordingly.

@5408Andy 5408Andy self-assigned this Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🛠️ In-Progress
Development

No branches or pull requests

6 participants
@jruths @SHSL-TemiOjumu @5408Andy @Shelleynguy and others