I have a arduino with robot open connected to a relayboard (we only are using one of the 4). It is all wired correctly but we need code so when the “A” button is pressed on our logitech controller, it will activate the relay and send power to our solenoid for a second to activate our t-shirt launcher. The code for this will be put into our existing code for a 4motor tank drive coded modified from the example code from robot open/arduino. I personally have no idea what im doing in programming. The relay is hooked up to port 9
I assume you mean port 8 on the relay shield, as there is no port 9.
you would have to add:
ROSolenoid solenoid(9);
before your enabled() function. The 9 is because Robot-Open 0-indexs ports.
you would also need to add:
if (usb1.btnA())
solenoid.on();
else
solenoid.off();
inside the enabled() function.
This would cause the solenoid to mimic the button presses.
However I cannot test this code as I do not have the hardware myself.
also is it necessary for the burst to be 1 second?
When we try to do if statements it gives us an error that it does not have a type.
have you defined usb1 as such:
ROJoystick usb1(1);
We can’t give good advice based on a paraphrase of your code and a paraphrase of the error message. Show us exactly what you’re trying to compile, and exactly what the error says. Someone here will probably recognize exactly what needs to be corrected.
this is our current code, we are trying to hook it up to one of the digital ports on the side car itself instead on directly to the arduino robot shield
Code:
#include <SPI.h>
#include <Ethernet.h>
#include <EEPROM.h>
#include <RobotOpen.h>
/* I/O Setup */
ROJoystick usb1(1); // Joystick #1
ROPWM leftmotorone(1);
ROPWM rightmotorone(0);
ROPWM leftmotortwo(2);
ROPWM rightmotortwo(3);
void setup()
{
/* Initiate comms */
RobotOpen.begin(&enabled, &disabled, &timedtasks);
pinMode(SIDECAR_DIGITAL7, OUTPUT);
}
/* This is your primary robot loop - all of your code
- should live here that allows the robot to operate
*/
void enabled() {
// Constantly update PWM values with joystick values
// Analog sticks feed back values from 0-255
// 255 - usb1.leftY() to invert a drive
leftmotorone.write(255 - usb1.leftY());
rightmotorone.write(usb1.rightY());
leftmotortwo.write(255 - usb1.leftY());
rightmotortwo.write(usb1.rightY());
if (usb1.btnA(1))
digitalWrite(SIDECAR_DIGITAL7, HIGH);
else
digitalWrite(SIDECAR_DIGITAL7, LOW);
}
/* This is called while the robot is disabled
- PWMs and Solenoids are automatically disabled
*/
void disabled() {
// safety code
}
/* This loop ALWAYS runs - only place code here that can run during a disabled state
- This is also a good spot to put driver station publish code
*/
void timedtasks() {
RODashboard.publish(“Uptime Seconds”, ROStatus.uptimeSeconds());
}
// !!! DO NOT MODIFY !!!
void loop() {
RobotOpen.syncDS();
}
The code below, copied from the “digital” example provided with the library should work fine.
#include <SPI.h>
#include <SD.h>
#include <Ethernet.h>
#include <Servo.h>
#include <EEPROM.h>
#include <RobotOpen.h>
/* I/O Setup */
ROJoystick usb1(1); // Joystick #1
RODigitalIO dig1Out(9, OUTPUT); // DIO channel 9, output mode
void setup()
{
/* Initiate comms */
RobotOpen.begin(&enabled, &disabled, &timedtasks);
}
/* This is your primary robot loop - all of your code
* should live here that allows the robot to operate
*/
void enabled() {
if (usb1.btnA())
dig1Out.on();
else
dig1Out.off();
}
/* This is called while the robot is disabled
* All outputs are automatically disabled (PWM, Solenoid, Digital Outs)
*/
void disabled() {
// safety code
}
/* This loop ALWAYS runs - only place code here that can run during a disabled state
* This is also a good spot to put driver station publish code
*/
void timedtasks() {
RODashboard.publish("Uptime Seconds", ROStatus.uptimeSeconds());
}
// !!! DO NOT MODIFY !!!
void loop() {
RobotOpen.syncDS();
}
What are the correct arguments for the btnA method? Examples show it with empty parentheses usb1.btnA() but you have tried to pass it a number.
You didn’t show us the error message, but I’m guessing it says something clear about the mismatch between the expected and supplied parameter types.
This issue was solved for the OP offline.
They didn’t have their Arduino libraries setup properly…on top of the improper code.